emacs-devel
[Top][All Lists]
Advanced

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

Re: Indentation of ?: in C-mode


From: Stefan Monnier
Subject: Re: Indentation of ?: in C-mode
Date: Mon, 16 Jul 2018 11:54:17 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

>> >> > +        find_start_value
>> >> > +          = CONSP (state.levelstarts) ? XINT (XCAR (state.levelstarts))
>> >> > +          : state.thislevelstart >= 0 ? state.thislevelstart
>> >> > +          : find_start_value;
>> >> Please use parentheses here for better readability (to clearly show
>> >> which parts belong to which condition).
>> > Yes, it didn't indent well by itself.  Maybe I should raise this with
>> > the CC Mode maintainer.  But yes, I'll put parens in.
>> This is one of those rare cases where sm-c-mode handles it better:
>> 
>>     find_start_value
>>       = CONSP (state.levelstarts) ? XINT (XCAR (state.levelstarts))
>>         : state.thislevelstart >= 0 ? state.thislevelstart
>>         : find_start_value;
>> 
>> This said, I don't see either indentation as problematic and I'm not
>> sure what would be "better for readability".
> This:
>
>     find_start_value = CONSP (state.levelstarts)
>                        ? XINT (XCAR (state.levelstarts))
>                        : (state.thislevelstart >= 0
>                           ? state.thislevelstart
>                           : find_start_value);

Interesting: I find this one to be (ever so slightly) less readable.
Basically, I read

     find_start_value
       = CONSP (state.levelstarts) ? XINT (XCAR (state.levelstarts))
         : state.thislevelstart >= 0 ? state.thislevelstart
         : find_start_value;

as a C version of

     (setq find_start_value
           (cond
            ((consp state.levelstarts) (XINT (XCAR (state.levelstarts))))
            ((>= state.thislevelstart 0) state.thislevelstart)
            (t find_start_value)));

so I find the ": condition ? value" lines to be very natural (the only
odd line is really the first one because it doesn't start with ":").


        Stefan


PS: This was the opportunity to see that sm-c-mode misindents the last
line of the middle example if you remove the parens:

  find_start_value = CONSP (state.levelstarts)
                     ? XINT (XCAR (state.levelstarts))
                     : state.thislevelstart >= 0
                       ? state.thislevelstart
                     : find_start_value;

although now that I see it, I wonder if sm-c-mode.el read my mind and
took ": condition ? value" as a logical entity, just to try and show me
where this idea breaks down.



reply via email to

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