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

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

Re: How to indent on LOCK(); macro???


From: Alan Mackenzie
Subject: Re: How to indent on LOCK(); macro???
Date: Wed, 31 Aug 2005 15:20:13 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Roy Smith <roy@panix.com> wrote on Wed, 31 Aug 2005 08:31:33 -0400:
> Alan Mackenzie <acm@muc.de> wrote:
>> > How can I convince the indenting engine to treat the LOCK and END_LOCK
>> > lines as beginning and ending blocks?

>> Only with braces:

>> LOCK (MyDataLock) {
>>     myData = foo;
>> } END_LOCK;

>> (The semicolon ater END_LOCK will prevent the next statement being
>> indented one level too many.)  And if you use auto-newline, you might
>> want to extend the functionality of c-snug-do-while so as to indent
>> the LOCK construct like a do-while, as above.

> Hmmm, I need to think on this, it may be good enough.  The LOCK and
> END_LOCK macros already include the braces (and the trailing
> semicolon), but I can't think of any reason why an extra set of braces
> or an extra semicolon will break anything.

It can't break anything.  The contents of a brace pair are a compound
statement, i.e. syntactically seen, just another statement.

> Still, it's not the style used here, and (for better or worse), it's
> difficult (and often a bad idea) to not go along with the established
> style on a big project.

It's _always_ a bad idea.  ;-(  (From somebody who's been edged out of
projects more than once for questioning the way things are done.)

Er, can I retract the answer I gave on my last post, please?  You sound
like the sort of guy who can write Elisp.  There is a hook called
`c-special-indent-hook' called after each line has been indented.  You
could put a function onto it that would check if the previous line was a
"LOCK", or the current line is an "END_LOCK", and if so give the line one
more/one less level of indentation.  That hook is described in the CC
Manual on page "Other Special Indentation".

And if you're not a Lisp hacker (or can't be bothered), say so, and I'll
throw some code together for you.

[ .... ]

>> The other thing is, do you really want your C++ code to look more like
>> Pascal?  ;-)

> Well, to be honest, I want my C++ code to look more like Python, but
> I'm the new kid on a project with 10 years of history, so I don't
> always get what I want :-(

Oh, _that_ sort of project.  ;-(

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").



reply via email to

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