all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
Subject: Re: How to indent on LOCK(); macro???
Date: Wed, 31 Aug 2005 08:10:46 +0000	[thread overview]
Message-ID: <6mo3fd.46.ln@acm.acm> (raw)
In-Reply-To: df2gs8$rcp$1@panix2.panix.com

Roy Smith <roy@panix.com> 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: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

  parent reply	other threads:[~2005-08-31  8:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-30 20:51 How to indent on LOCK(); macro??? Roy Smith
2005-08-30 21:21 ` Denis Bueno
2005-08-30 21:27   ` Roy Smith
2005-08-31  8:10 ` Alan Mackenzie [this message]
2005-08-31 12:31   ` Roy Smith
2005-08-31 15:20     ` Alan Mackenzie
2005-08-31 23:50       ` Roy Smith
2005-09-01 16:28         ` Alan Mackenzie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6mo3fd.46.ln@acm.acm \
    --to=acm@muc.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.