From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs 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 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0GqiNvNDYqJhOHbW" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33254"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59953@debbugs.gnu.org, acm@muc.de To: Chris Hecker Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 14 17:54:07 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qrgxr-0008T4-Dz for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 14 Oct 2023 17:54:07 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qrgxS-00024a-AZ; Sat, 14 Oct 2023 11:53:42 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qrgxP-00024J-UR for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 11:53:39 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qrgxO-00007u-Es for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 11:53:38 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qrgxl-0000HA-PX for bug-gnu-emacs@gnu.org; Sat, 14 Oct 2023 11:54:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 14 Oct 2023 15:54:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59953 X-GNU-PR-Package: emacs Original-Received: via spool by 59953-submit@debbugs.gnu.org id=B59953.1697298797995 (code B ref 59953); Sat, 14 Oct 2023 15:54:01 +0000 Original-Received: (at 59953) by debbugs.gnu.org; 14 Oct 2023 15:53:17 +0000 Original-Received: from localhost ([127.0.0.1]:50248 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrgx2-0000Fz-Qt for submit@debbugs.gnu.org; Sat, 14 Oct 2023 11:53:17 -0400 Original-Received: from mail.muc.de ([193.149.48.3]:43305) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qrgwy-0000Fi-4C for 59953@debbugs.gnu.org; Sat, 14 Oct 2023 11:53:15 -0400 Original-Received: (qmail 47300 invoked by uid 3782); 14 Oct 2023 17:52:41 +0200 Original-Received: from acm.muc.de (pd953a921.dip0.t-ipconnect.de [217.83.169.33]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sat, 14 Oct 2023 17:52:40 +0200 Original-Received: (qmail 8785 invoked by uid 1000); 14 Oct 2023 15:52:34 -0000 Content-Disposition: inline In-Reply-To: X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272437 Archived-At: --0GqiNvNDYqJhOHbW Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit 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). --0GqiNvNDYqJhOHbW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="diff.20231014.diff" 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) --0GqiNvNDYqJhOHbW--