Objective-C indentation in emacs

I use Emacs to edit my Objective-C code. The default indent is as follows:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                 target:self
                 selector:@selector(callback:)
                 userInfo:nil 
                 repeats:YES];

I would like Emacs to backtrack from code such as Xcode, i.e. to align with colons:

    NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                                target:self
                              selector:@selector(callback:)
                              userInfo:nil 
                               repeats:YES];

Is there any hope of achieving this?

+3
source share
3 answers

I hacked it a bit and came closer, but not yet fully operational. The solution I have is to add an entry to align-rules-list, so a simple one M-x alignwill do the trick. The problem is that you need to run twice alignto make it work.

(obj-c-colons
 (regexp . "^\\(\\s-*[^:]+\\):")
 (justify . t)
 (repeat . t)
 (modes obj-c-mode)) ;; <= Replace with actual name of major mode

, objective-c, obj-c-mode , . align-rules-list :

(add-to-list 'align-rules-list
             '(obj-c-colons
               (regexp . "^\\(\\s-*[^:]+\\):")
               (justify . t)
               (repeat . t)
               (modes obj-c-mode)))

align ; :

 NSTimer *timer =
        [NSTimer timerWithTimeInterval:1.0
                              target:self
                            selector:@selector(callback:)
                            userInfo:nil
                             repeats:YES];

, . align . , .

align , . , - . , EmacsWiki .

+6

- c-lineup-ObjC-method-call-colons objc-method-call-cont c-offsets-alist?

+6

Objective C,

0

Source: https://habr.com/ru/post/1714528/


All Articles