help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Block as method parameter indentation in objc-mode


From: Pascal J. Bourguignon
Subject: Re: Block as method parameter indentation in objc-mode
Date: Mon, 25 May 2015 20:30:21 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

juha.nieminen@gmail.com writes:

> Is there an easy way in objc-mode to make a starting { symbol that appears in 
> a method parameter to be indented only one space more than the starting [ of 
> the method call? In other words, I want it to indent like this:
>
>     [someObj someMethodTakingABlock: ^()
>      {
>          // some code here
>      }];
>
> Likewise, if possible, the ^(...) part also ought to be indented like that if 
> it's on its own like. So like:
>
>     [someObj someMethodTakingABlock:
>      ^(int someValue, NSString* someString)
>      {
>          // some code here
>      }];
>
> Currently objc-mode indents such blocks waaaay to the right, which is rather 
> impractical.

It's the objc-method-call-cont c-offsets-alist key.

My current setting, giving the same results you have is:

       (objc-method-call-cont . (c-lineup-ObjC-method-call-colons
                                 c-lineup-ObjC-method-call
                                 +))

to obtain what you want, you would have to modify it, but as you can
see, it uses those two functions to compute the position in a
sophisticated way.



By using:

/*
    (push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
                                     ;; c-lineup-ObjC-method-call
                                     2)) 
            c-offsets-alist)
*/

we obtain this:

    [someObj someMethodTakingABlock: ^()
      {
          // some code here
      }];

    [someObj someMethodTakingABlock:
      ^(int someValue, NSString* someString)
      {
          // some code here
      }];

but also:

    [someObj someMethodTakingABlock: 
      a 
                          someOther:b];

which may not be what you want.   In that case, you might have to write
a function to replace c-lineup-ObjC-method-call providing the same
indent as c-lineup-ObjC-method-call for non-^ and non-{, and providing
the 2-indent for ^ and {.

> If there happened to be more parameters after that, they ought to be
> indented as normal. In other words, overall, like this:

and indeed, indenting correctly:

    [someObj someParameter: aValue
                    aBlock: ^()
      {
          // some code
      }
    aThirdParameter: anotherValue];

is harder.  As it is, aThirdParameter: is taken as a label, instead of
an objc-method-call-cont.


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

[Prev in Thread] Current Thread [Next in Thread]