GNU bug report logs - #66911
CC Mode 5.35.2 (C++//l); Noise macro being taken as anchor to class-open

Previous Next

Package: cc-mode;

Reported by: Arsen Arsenović <arsen <at> aarsen.me>

Date: Fri, 3 Nov 2023 10:24:02 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #32 received at 66911 <at> debbugs.gnu.org (full text, mbox):

From: Alan Mackenzie <acm <at> muc.de>
To: Arsen Arsenović <arsen <at> aarsen.me>
Cc: acm <at> muc.de, 66911 <at> debbugs.gnu.org
Subject: Re: bug#66911: CC Mode 5.35.2 (C++//l); Noise macro being taken as
 anchor to class-open
Date: Fri, 17 Nov 2023 20:17:47 +0000
Hello, Arsen.

On Fri, Nov 17, 2023 at 20:16:31 +0100, Arsen Arsenović wrote:
> Hi Alan,

> Thanks (again!) for working on this.

Appreciated!

> Alan Mackenzie <acm <at> muc.de> writes:

> > On Thu, Nov 16, 2023 at 21:29:29 +0100, Arsen Arsenović wrote:

> >> The following did work nicely (after I made c-langelem-2nd-col, by
> >> copying and altering c-langelem-col as is obvious).  I'm not sure if it
> >> is idiomatic or the cleanest solution, though (plus, my Elisp-fu is
> >> poor).

I think c-langelem-2nd-col is as good as anything else.  It's better to
have it as a function than open coding it everywhere it's used.

> >> --8<---------------cut here---------------start------------->8---
> >> (defun glibcxx-style/line-up-struct (sym-form)
> >>   "Lines up a class-open with its prior struct line"
> >>   (if (not (eq 'class-open (c-langelem-sym sym-form)))
> >>       nil
> >>     (let ((col (c-langelem-2nd-col c-syntactic-element t)))
> >>       (if col
> >> 	  (vector col)
> >> 	nil))))
> >> --8<---------------cut here---------------end--------------->8---

> >> ... however, I noticed that class-close still anchors on the template
> >> that precedes it, and seems to not have a 2nd-pos to play with, so the
> >> above line-up fn, when set on class-open, produces:

> >> --8<---------------cut here---------------start------------->8---
> >> template<typename foo>
> >>   struct f
> >>   {
> >> };
> >> --8<---------------cut here---------------end--------------->8---

> > Yes.  I should have noticed this myself.  :-(

> >> ... so, we're getting quite close!

> > So, please try out the new patch (below) which supplies the second anchor
> > point to class-close too.  The patch applies cleanly to the Emacs master
> > branch.  Again, please start off with a clean cc-engine.el before
> > applying the new patch, not the version with the previous patch applied.

> Excellent!  The following did it:

> --8<---------------cut here---------------start------------->8---
> (defun glibcxx-style/line-up-struct (sym-form)
>   "Lines up a class-open/close with its prior struct line"
>   (if (not (seq-contains-p '(class-open class-close)
> 			   (c-langelem-sym sym-form)))
>       nil
>     (let ((col (c-langelem-2nd-col c-syntactic-element t)))
>       (if col
> 	  (vector col)
> 	nil))))
> --8<---------------cut here---------------end--------------->8---

> Again, unsure if it is the most elegant solution, or even if it's a good
> one.  But it did work!

Working is rather more important than elegance.  ;-)

> I've copied c-langelem-2nd-col again to do the above.  Is that helper
> intentionally omitted?  Is there perhaps a more idiomatic solution?

I don't think so.

> In any case, I'll be sure to use this as soon as it lands in the Emacs
> VCS.

This might take a few days - I've still got to amend the (stand alone CC
Mode) test suite and the documentation.  And I've got quite a lot on in
Real Life in the next few days.

> Thanks again, have a lovely night!

Thanks.  You too!

> -- 
> Arsen Arsenović

-- 
Alan Mackenzie (Nuremberg, Germany).




This bug report was last modified 1 year and 174 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.