all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Chris Hecker <checker@d6.com>
Cc: 59953@debbugs.gnu.org, acm@muc.de
Subject: bug#59953: 28.2; c type modifiers only work as prefixes for font-lock, cc-mode
Date: Sat, 14 Oct 2023 15:52:34 +0000	[thread overview]
Message-ID: <ZSq5QkHrAw2FfCkk@ACM> (raw)
In-Reply-To: <eme5131790-d23f-43d3-b37c-e35bcb51ac99@checker-blade15>

[-- Attachment #1: Type: text/plain, Size: 1982 bytes --]

Hello, Chris.

Thanks for taking the trouble to file this bug, but sorry it's been such
a long time without a response.

I've now looked at the bug and it wasn't that difficult to patch.  If you
don't mind too much, I'll put your test file into the CC Mode test suite,
having added one line ("long int unsigned Three;") to it.

Would you please now apply the attached patch to your current Emacs (the
file cc-engine.el is in lisp/progmodes), byte compile cc-engine.el (or
just the whole of CC Mode), load the result into your Emacs and try it
out on your real source code.  Then please confirm to me that the bug is
fixed, or tell me what's still not right.  Thanks!  (If you want any help
in the patching of byte compilation, feel free to send me private email.)

On Sat, Dec 10, 2022 at 22:31:18 +0000, Chris Hecker wrote:
>    cc-mode doesn't seem to recognize that c type specifiers can come in
>    any order (and I prefer them after so they're modifying the base type),
>    so the highlighting doesn't work right for the variable name.  Here's
>    an example in a struct, works the same way in a function:

>    struct foo {
>      unsigned int One;
>     int unsigned Two;
>    };

>    emacs -Q results:

>    [cid:emf20eaa32-35e0-4df0-a1fb-4e6ad9397939@checker-blade15]

>    I couldn't see an easy way of fixing this (besides just adding all the
>    combos to *-font-lock-extra-types).  Seems like there needs to be a
>    c-primitive-type-postfix-kwds variable to do this right?

>    Thanks,

>    Chris

>    In GNU Emacs 28.2 (build 2, x86_64-w64-mingw32)
>    Â of 2022-09-13 built on AVALON

>    Windowing system distributor 'Microsoft Corp.', version 10.0.19044
>    System Description: Microsoft Windows 10 Home (v10.0.2009.19044.2251)
>    Configured using:
>    Â 'configure --with-modules --without-dbus --with-native-compilation
>    Â --without-compress-install CFLAGS=-O2'
>    Configured features:

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).


[-- Attachment #2: diff.20231014.diff --]
[-- Type: text/plain, Size: 2574 bytes --]

diff -r 97876aef276f cc-engine.el
--- a/cc-engine.el	Fri Oct 13 14:13:43 2023 +0000
+++ b/cc-engine.el	Sat Oct 14 15:51:43 2023 +0000
@@ -9461,37 +9461,47 @@
 		 (or c-promote-possible-types (eq res t)))
 	(c-record-type-id (cons (match-beginning 1) (match-end 1))))
 
-      (if (and c-opt-type-component-key
+      (cond
+       ((and c-opt-type-component-key
 	       (save-match-data
 		 (looking-at c-opt-type-component-key)))
 	  ;; There might be more keywords for the type.
-	  (let (safe-pos)
-	    (c-forward-keyword-clause 1 t)
-	    (while (progn
-		     (setq safe-pos (point))
-		     (c-forward-syntactic-ws)
-		     (looking-at c-opt-type-component-key))
-	      (when (and c-record-type-identifiers
-			 (looking-at c-primitive-type-key))
-		(c-record-type-id (cons (match-beginning 1)
-					(match-end 1))))
-	      (c-forward-keyword-clause 1 t))
-	    (if (looking-at c-primitive-type-key)
-		(progn
-		  (when c-record-type-identifiers
-		    (c-record-type-id (cons (match-beginning 1)
-					    (match-end 1))))
-		  (c-forward-keyword-clause 1 t)
-		  (setq res t))
-	      (goto-char safe-pos)
-	      (setq res 'prefix))
-	    (setq pos (point)))
-	(if (save-match-data (c-forward-keyword-clause 1 t))
-	    (setq pos (point))
-	  (if pos
-	      (goto-char pos)
-	    (goto-char (match-end 1))
-	    (setq pos (point)))))
+	(let (safe-pos)
+	  (c-forward-keyword-clause 1 t)
+	  (while (progn
+		   (setq safe-pos (point))
+		   (c-forward-syntactic-ws)
+		   (looking-at c-opt-type-component-key))
+	    (when (and c-record-type-identifiers
+		       (looking-at c-primitive-type-key))
+	      (c-record-type-id (cons (match-beginning 1)
+				      (match-end 1))))
+	    (c-forward-keyword-clause 1 t))
+	  (if (looking-at c-primitive-type-key)
+	      (progn
+		(when c-record-type-identifiers
+		  (c-record-type-id (cons (match-beginning 1)
+					  (match-end 1))))
+		(c-forward-keyword-clause 1 t)
+		(setq res t)
+		(while (progn
+			 (setq safe-pos (point))
+			 (c-forward-syntactic-ws)
+			 (looking-at c-opt-type-component-key))
+		  (c-forward-keyword-clause 1 t)))
+	    (goto-char safe-pos)
+	    (setq res 'prefix))
+	  (setq pos (point))))
+	((save-match-data (c-forward-keyword-clause 1 t))
+	 (while (progn
+		  (setq pos (point))
+		  (c-forward-syntactic-ws)
+		  (and c-opt-type-component-key
+		       (looking-at c-opt-type-component-key)))
+	   (c-forward-keyword-clause 1 t)))
+	(pos (goto-char pos))
+	(t (goto-char (match-end 1))
+	   (setq pos (point))))
       (c-forward-syntactic-ws))
 
      ((and (eq name-res t)

  reply	other threads:[~2023-10-14 15:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10 22:31 bug#59953: 28.2; c type modifiers only work as prefixes for font-lock, cc-mode Chris Hecker
2023-10-14 15:52 ` Alan Mackenzie [this message]
2023-11-24 12:29   ` 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=ZSq5QkHrAw2FfCkk@ACM \
    --to=acm@muc.de \
    --cc=59953@debbugs.gnu.org \
    --cc=checker@d6.com \
    /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.