[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.
- Re: CC Mode and electric-pair "problem"., (continued)
- Re: CC Mode and electric-pair "problem"., João Távora, 2018/07/01
- Re: CC Mode and electric-pair "problem"., Eli Zaretskii, 2018/07/01
- scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Alan Mackenzie, 2018/07/01
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Stephen Leake, 2018/07/08
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Stephen Leake, 2018/07/15
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Eli Zaretskii, 2018/07/15
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Alan Mackenzie, 2018/07/15
- Indentation of ?: in C-mode (was: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".]), Stefan Monnier, 2018/07/15
- Re: Indentation of ?: in C-mode (was: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".]), Eli Zaretskii, 2018/07/16
- Re: Indentation of ?: in C-mode,
Stefan Monnier <=
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Alan Mackenzie, 2018/07/15
- Re: scratch/fontify-open-string. [Was: CC Mode and electric-pair "problem".], Stephen Leake, 2018/07/16
Re: CC Mode and electric-pair "problem"., Eli Zaretskii, 2018/07/01
Re: CC Mode and electric-pair "problem"., Paul Eggert, 2018/07/01
Re: CC Mode and electric-pair "problem"., Stephen Leake, 2018/07/06