* Block as method parameter indentation in objc-mode
@ 2015-05-25 18:02 juha.nieminen
2015-05-25 18:30 ` Pascal J. Bourguignon
0 siblings, 1 reply; 7+ messages in thread
From: juha.nieminen @ 2015-05-25 18:02 UTC (permalink / raw)
To: help-gnu-emacs
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.
If there happened to be more parameters after that, they ought to be indented as normal. In other words, overall, like this:
[someObj someParameter: aValue
aBlock: ^()
{
// some code
}
aThirdParameter: anotherValue];
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Block as method parameter indentation in objc-mode
2015-05-25 18:02 Block as method parameter indentation in objc-mode juha.nieminen
@ 2015-05-25 18:30 ` Pascal J. Bourguignon
2015-05-26 8:25 ` juha.nieminen
0 siblings, 1 reply; 7+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-25 18:30 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Block as method parameter indentation in objc-mode
2015-05-25 18:30 ` Pascal J. Bourguignon
@ 2015-05-26 8:25 ` juha.nieminen
2015-05-26 12:43 ` Pascal J. Bourguignon
0 siblings, 1 reply; 7+ messages in thread
From: juha.nieminen @ 2015-05-26 8:25 UTC (permalink / raw)
To: help-gnu-emacs
On Monday, May 25, 2015 at 9:30:23 PM UTC+3, Pascal J. Bourguignon wrote:
> By using:
>
> /*
> (push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
> ;; c-lineup-ObjC-method-call
> 2))
> c-offsets-alist)
> */
I'm not sure where this should be put. If I add it to my .emacs, it issues the error "Symbol's value as variable is void: c-offsets-alist".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Block as method parameter indentation in objc-mode
2015-05-26 8:25 ` juha.nieminen
@ 2015-05-26 12:43 ` Pascal J. Bourguignon
2015-05-28 7:44 ` Juha Nieminen
0 siblings, 1 reply; 7+ messages in thread
From: Pascal J. Bourguignon @ 2015-05-26 12:43 UTC (permalink / raw)
To: help-gnu-emacs
juha.nieminen@gmail.com writes:
> On Monday, May 25, 2015 at 9:30:23 PM UTC+3, Pascal J. Bourguignon wrote:
>> By using:
>>
>> /*
>> (push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
>> ;; c-lineup-ObjC-method-call
>> 2))
>> c-offsets-alist)
>> */
>
> I'm not sure where this should be put. If I add it to my .emacs, it
> issues the error "Symbol's value as variable is void:
> c-offsets-alist".
There's various ways to configure c styles.
(info "(emacs) Custom C Indent")
--
__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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Block as method parameter indentation in objc-mode
2015-05-26 12:43 ` Pascal J. Bourguignon
@ 2015-05-28 7:44 ` Juha Nieminen
2015-05-28 18:26 ` John Mastro
[not found] ` <mailman.3855.1432837606.904.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 7+ messages in thread
From: Juha Nieminen @ 2015-05-28 7:44 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon <pjb@informatimago.com> wrote:
> juha.nieminen@gmail.com writes:
>
>> On Monday, May 25, 2015 at 9:30:23 PM UTC+3, Pascal J. Bourguignon wrote:
>>> By using:
>>>
>>> /*
>>> (push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
>>> ;; c-lineup-ObjC-method-call
>>> 2))
>>> c-offsets-alist)
>>> */
>>
>> I'm not sure where this should be put. If I add it to my .emacs, it
>> issues the error "Symbol's value as variable is void:
>> c-offsets-alist".
>
> There's various ways to configure c styles.
> (info "(emacs) Custom C Indent")
I have no idea what to do with that information. I still haven't the
slightest clue where I should put that command.
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Block as method parameter indentation in objc-mode
2015-05-28 7:44 ` Juha Nieminen
@ 2015-05-28 18:26 ` John Mastro
[not found] ` <mailman.3855.1432837606.904.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 7+ messages in thread
From: John Mastro @ 2015-05-28 18:26 UTC (permalink / raw)
To: help-gnu-emacs@gnu.org
Juha Nieminen <nospam@thanks.invalid> wrote:
>>>> /*
>>>> (push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
>>>> ;; c-lineup-ObjC-method-call
>>>> 2))
>>>> c-offsets-alist)
>>>> */
> I have no idea what to do with that information. I still haven't the
> slightest clue where I should put that command.
Try this:
(eval-after-load 'cc-mode
'(push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
;; c-lineup-ObjC-method-call
2))
c-offsets-alist))
That wraps Pascal's suggestion in `eval-after-load' such that it's not
evaluated until after `cc-mode' is loaded.
--
john
^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <mailman.3855.1432837606.904.help-gnu-emacs@gnu.org>]
* Re: Block as method parameter indentation in objc-mode
[not found] ` <mailman.3855.1432837606.904.help-gnu-emacs@gnu.org>
@ 2015-05-29 8:18 ` Juha Nieminen
0 siblings, 0 replies; 7+ messages in thread
From: Juha Nieminen @ 2015-05-29 8:18 UTC (permalink / raw)
To: help-gnu-emacs
John Mastro <john.b.mastro@gmail.com> wrote:
> Try this:
>
> (eval-after-load 'cc-mode
> '(push '(objc-method-call-cont . (c-lineup-ObjC-method-call-colons
> ;; c-lineup-ObjC-method-call
> 2))
> c-offsets-alist))
>
> That wraps Pascal's suggestion in `eval-after-load' such that it's not
> evaluated until after `cc-mode' is loaded.
That seems to work. Thanks.
As he said, if there's any additional parameter after the {} block,
emacs will consider it a label rather than a paraneter, and mis-indent
(and mis-color) it. Fortunately it's very are for methods to be designed
like this. I suppose I'll cope (unless someone can suggest a fix to that.)
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-29 8:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-25 18:02 Block as method parameter indentation in objc-mode juha.nieminen
2015-05-25 18:30 ` Pascal J. Bourguignon
2015-05-26 8:25 ` juha.nieminen
2015-05-26 12:43 ` Pascal J. Bourguignon
2015-05-28 7:44 ` Juha Nieminen
2015-05-28 18:26 ` John Mastro
[not found] ` <mailman.3855.1432837606.904.help-gnu-emacs@gnu.org>
2015-05-29 8:18 ` Juha Nieminen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.