all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: "Óscar Fuentes" <ofv@wanadoo.es>
Cc: 36650@debbugs.gnu.org
Subject: bug#36650: 27.0.50; CC Mode: Support C++ attributes
Date: Sun, 21 Jul 2019 11:33:05 +0000	[thread overview]
Message-ID: <20190721113305.GA11223@ACM> (raw)
In-Reply-To: <87d0i48hzc.fsf@telefonica.net>

Hello, Óscar.

Thanks for the rapid response!

On Sun, Jul 21, 2019 at 00:21:43 +0200, Óscar Fuentes wrote:
> Alan Mackenzie <acm@muc.de> writes:

> > The patch below (which should apply cleanly to the master branch) is
> > a first attempt at handling C++ attributes.

> Thank you Alan. Wow, it required more changes than I would expect.

These attributes can appear anywhere.  That's why.

> Seems that it mostly works. The only issue I've found so far is

> struct S {
>   S[[using : const]]()
>   : data(0)
>   {}
>   int data;
> };

> Note how ": data(0)" is not indented. If the attribute is moved before the
> name:

> struct S {
>   [[using : const]] S()
>     : data(0)
>   {}
>   int data;
> };

> or after the parameter list:

> struct S {
>   S() [[using: const]]
>     : data(0)
>   {}
>   int data;
> };


> then the indentation is correct. This only happens if the attribute is
> of the form "using:" (it is irrelevant if there is space between "using"
> and the colon).

Yes.  More precisely, it was the presence of the colon inside the
attribute which confused a low level CC Mode function
(c-crosses-statement-barrier-p).   This function scans forward for a
character which might be relevant for statement boundaries, and one of
these characters is :.  I've added handling for [[...]] into this
function, and it now seems to be working.

Would you please apply the following supplementary patch to your current
master state, try it out again, and let me know how it goes.

Thanks!



--- cc-engine.el~	2019-07-20 17:45:13.944753490 +0000
+++ cc-engine.el	2019-07-21 10:43:31.470078502 +0000
@@ -697,6 +697,21 @@
       (overlay-put (make-overlay end ol-end) 'face face))))
 
 \f
+(defmacro c-looking-at-c++-attribute ()
+  ;; If we're in C++ Mode, and point is at the [[ introducing an attribute,
+  ;; return the position of the end of the attribute, otherwise return nil.
+  ;; The match data are NOT preserved over this macro.
+  `(and
+    (c-major-mode-is 'c++-mode)
+    (looking-at "\\[\\[")
+    (save-excursion
+      (and
+       (c-go-list-forward)
+       (eq (char-before) ?\])
+       (eq (char-before (1- (point))) ?\])
+       (point)))))
+
+\f
 ;; `c-beginning-of-statement-1' and accompanying stuff.
 
 ;; KLUDGE ALERT: c-maybe-labelp is used to pass information between
@@ -1420,9 +1435,15 @@
 		      c-opt-cpp-symbol			 ; usually "#"
 		      (substring c-stmt-delim-chars 1))	 ; e.g. ";{}?:"
 	    c-stmt-delim-chars))
+	 (skip-chars
+	  (if (c-major-mode-is 'c++-mode)
+	      (concat (substring skip-chars 0 1) ; "^"
+		      "["			 ; to catch C++ attributes
+		      (substring skip-chars 1))	; e.g. "#;{}?:"
+	    skip-chars))
 	 (non-skip-list
 	  (append (substring skip-chars 1) nil)) ; e.g. (?# ?\; ?{ ?} ?? ?:)
-	 lit-range lit-start vsemi-pos)
+	 lit-range lit-start vsemi-pos attr-end)
     (save-restriction
       (widen)
       (save-excursion
@@ -1446,6 +1467,11 @@
 	     ;; In a string/comment?
 	     ((setq lit-range (c-literal-limits from))
 	      (goto-char (cdr lit-range)))
+	     ;; Skip over a C++ attribute?
+	     ((eq (char-after) ?\[)
+	      (if (setq attr-end (c-looking-at-c++-attribute))
+		  (goto-char attr-end)
+		(forward-char)))
 	     ((eq (char-after) ?:)
 	      (forward-char)
 	      (if (and (eq (char-after) ?:)
@@ -1839,21 +1865,6 @@
 ;; enclosing END, if any, else nil.
 (defvar c-sws-lit-limits nil)
 
-(defmacro c-looking-at-c++-attribute ()
-  ;; If we're in C++ Mode, and point is at the [[ introducing an attribute,
-  ;; return the position of the end of the attribute, otherwise return nil.
-  ;; The match data are NOT preserved over this macro.
-  `(and
-    (c-major-mode-is 'c++-mode)
-    (looking-at "\\[\\[")
-    (save-excursion
-      (and
-       (c-go-list-forward)
-       (eq (char-before) ?\])
-       (eq (char-before (1- (point))) ?\])
-       (point)))))
-
-;; (defmacro c-enclosing-c++-attribute ()
 (defun c-enclosing-c++-attribute ()
   ;; If we're in C++ Mode, and point is within a correctly balanced [[ ... ]]
   ;; attribute structure, return a cons of its starting and ending positions.


-- 
Alan Mackenzie (Nuremberg, Germany).





  reply	other threads:[~2019-07-21 11:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-14 14:49 bug#36650: 27.0.50; CC Mode: Support C++ attributes Óscar Fuentes
     [not found] ` <mailman.1275.1563115806.2688.bug-gnu-emacs@gnu.org>
2019-07-15 14:27   ` Alan Mackenzie
2019-07-15 15:17     ` Óscar Fuentes
2019-07-20 18:02       ` Alan Mackenzie
2019-07-20 22:21         ` Óscar Fuentes
2019-07-21 11:33           ` Alan Mackenzie [this message]
2019-07-21 14:56             ` Óscar Fuentes
2019-07-21 21:16               ` 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=20190721113305.GA11223@ACM \
    --to=acm@muc.de \
    --cc=36650@debbugs.gnu.org \
    --cc=ofv@wanadoo.es \
    /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.