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 08:10:46 +0000
User-agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686))

Roy Smith <address@hidden> wrote on 30 Aug 2005 16:51:20 -0400:
> I'm working on a project which uses a LOCK/END_LOCK macro pair for
> mutex locking in C++ source files.  A typical section of code would
> look like:

>     LOCK (myDataLock)
>         myData = foo;
>     END_LOCK

> 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.

I know that's not quite what you're asking for.  But what you're asking
for isn't entirely reasonable; a macro in C or C++ can expand to
absolutely _anything_.  The CC Mode indentation engine works purely
syntactically, i.e. according to what the source "looks like".  If the
indentation were to be extended to handle "common" macro expansions, it
would add a whole new level of complexity.  For a start, the indentation
engine would have somehow to be told that LOCK should behave like an open
brace and END_LOCK like a close brace.  Would this be done by you setting
a configuration variable, or would CC Mode be expected to scan #include
files, parsing all the macros?  (And if you're not sure just how
complicated the indentation engine already is, take a glance at the
function `c-guess-basic-syntax' in cc-engine.el.)

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

> I'm running GNU Emacs 21.3.1.

-- 
Alan Mackenzie (Munich, Germany)
Email: address@hidden; 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]