Subject: Re: bug#42581: Wrong C++ indentation when using class MY_DLL_EXPORT_MACRO foo

From: Alan Mackenzie <[email-masked]>
Date: Fri, 31 Jul 2020 19:44:51 +0000

Hello, Stéphane.

Just one little thing: could you please keep the buglist address in the
Cc: when you reply, so that everybody can keep track of the conversation.
Thanks.

On Wed, Jul 29, 2020 at 10:28:07 +0200, Stephane A wrote:
> On Tue, Jul 28, 2020 at 8:38 PM Alan Mackenzie <[email-masked]> wrote:

> > In article <[email-masked]> you wrote:
> > > [-- text/plain, encoding quoted-printable, charset: UTF-8, 41 lines --]

> > > Hello,

> > > Thank you for the advice :) I didn't know this one.

> > > We have on *_EXPORT macro per module. So I would need to configure noise
> > > macros by regexp.

> > > I found *c-make-noise-macro-regexps *in the Emacs documentation
> > > <
> > https://www.gnu.org/software/emacs/manual/html_node/ccmode/Noise-Macros.html

> > > but don't know how to set it up in my emacs file
> > > <https://github.com/astephane/emacs/blob/master/emacs.el> since the
> > syntax
> > > is not documented.

> > The syntax and semantics or regular expressions are documented
> > thoroughly in the Emacs Lisp manual (elisp.info).

> > The mechanics of the CC Mode hooks are similarly described in the CC
> > Mode manual (ccmode.info).  c-noise-macro-names can be either a list of
> > strings (one of which would be "MY_EXPORT_DLL_MACRO") or just a regular
> > expression, which you seem to need here.

> > There is an example .emacs file in an appendix to the CC Mode manual.

> > > I though of adding a call to the c++-mode-hook
> > > <https://github.com/astephane/emacs/blob/master/emacs.el#L245>.

> > The c++-mode-hook would be an excellent place to make this setting, yes.

> Following the CC mode example [1], I added (add-to-list 'c-noise-macro-names
> "[:space:].+_EXPORT[:space:]") in the lambda of the c++-mode-hook [2], but
> there's no difference of indentation in the code (I check with
> linux/gnu/stroustrup styles). I don't know if I've done something wrong or
> if this workaround does work.

There are a couple of misunderstandings, here (for which I blame the
documentation (largely written by me)).

Firstly, the regexp must match the noise macro exactly, not also any
spaces which may be around it, or anything like that.  So your regexp
should look something like:

    "[A-Z_]+_MACRO" ; which matches "MY_EXPORT_DLL_MACRO"
    or
    "MODULE_[A-Z_]_+EXPORT" ; which matches "MODULES_NAME_EXPORT".

> Note: our macros are of the form MODULE_NAME_EXPORT.

Also, your `add-to-list' form is mistaken.  That would give you a one
element list, that element being the regexp.  What you need is the
variable set to the regexp itself.  For this, you want something like:

    (setq c-noise-macro-names "MODULE_[A-Z_]+_EXPORT")

> [1]
> https://www.gnu.org/software/emacs/manual/html_node/ccmode/Sample-Init-File.html#Sample-Init-File
> [2] https://github.com/astephane/emacs/blob/master/emacs.el#L254

> Regards,

> Stéphane

-- 
Alan Mackenzie (Nuremberg, Germany).