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#64204: C/C++ local variables not syntax highlighted if they start with $ Date: Wed, 21 Jun 2023 19:25:41 +0000 Message-ID: References: <87edm52fu1.fsf@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10934"; mail-complaints-to="usenet@ciao.gmane.io" Cc: acm@muc.de, 64204@debbugs.gnu.org To: Po Lu , Joseph Garvin Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 21 21:26:22 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 1qC3TC-0002eZ-Gl for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 21 Jun 2023 21:26:22 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qC3Sz-0005Bs-Bx; Wed, 21 Jun 2023 15:26:09 -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 1qC3St-0005BZ-P5 for bug-gnu-emacs@gnu.org; Wed, 21 Jun 2023 15:26:07 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qC3Ss-0004d5-4K for bug-gnu-emacs@gnu.org; Wed, 21 Jun 2023 15:26:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qC3Sr-0000Xj-LJ for bug-gnu-emacs@gnu.org; Wed, 21 Jun 2023 15:26: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: Wed, 21 Jun 2023 19:26:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64204 X-GNU-PR-Package: emacs Original-Received: via spool by 64204-submit@debbugs.gnu.org id=B64204.16873755502067 (code B ref 64204); Wed, 21 Jun 2023 19:26:01 +0000 Original-Received: (at 64204) by debbugs.gnu.org; 21 Jun 2023 19:25:50 +0000 Original-Received: from localhost ([127.0.0.1]:34233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qC3Sg-0000XH-EW for submit@debbugs.gnu.org; Wed, 21 Jun 2023 15:25:50 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:33683) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qC3Se-0000X2-Go for 64204@debbugs.gnu.org; Wed, 21 Jun 2023 15:25:49 -0400 Original-Received: (qmail 87841 invoked by uid 3782); 21 Jun 2023 21:25:41 +0200 Original-Received: from acm.muc.de (pd953aea6.dip0.t-ipconnect.de [217.83.174.166]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Wed, 21 Jun 2023 21:25:41 +0200 Original-Received: (qmail 14244 invoked by uid 1000); 21 Jun 2023 19:25:41 -0000 Content-Disposition: inline In-Reply-To: <87edm52fu1.fsf@yahoo.com> 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:263846 Archived-At: Hello, Joseph and Po. On Wed, Jun 21, 2023 at 19:51:50 +0800, Po Lu wrote: > Joseph Garvin writes: > > Start emacs with `emacs -Q`, press C-x C-f and type in a filename that > > ends in .cpp like "foo.cpp". Then type in: > > int main() > > { > > int a = 0; > > int b = 0; > > int $ = 0; > > int d$ = 0; > > int $e = 0; > > } > > Yes it compiles! GCC, Clang, and MSVC all have a non-standard > > extension that allows $ signs to appear in C/C++ variable and type > > names: https://gcc.gnu.org/onlinedocs/gcc/Dollar-Signs.html > > Then a,b,d$ will be highlighted correctly as local vars, but not $ or > > $e. The highlighting doesn't appear to work whenever $ is the first or > > only character. Since emacs is accepting of the $ sign anywhere else in > > the variable name, I suspect supporting $ was intended, even though it's > > non-standard. Even if not intended, it's a popular syntax > > extension supported by the major current compilers and whose history > > goes back to the DEC compiler, so support would be nice. > This is a bug indeed. Alan, would you please look into this? OK, I've amended C Mode, C++ Mode and Objective C Mode to fontify identifiers starting with a $. Please apply the patch below to .../lisp/progmodes/cc-langs.el, and (since Lisp macros have been changed) recompile the entire CC Mode files and reload them. (Joseph, if you want any help with the patching or compiling, feel free to send me private email.) Then please try out the new version on your real code, and confirm to me that the bug has been fixed, or tell me what's still wrong. Thanks! diff -r c45cc2208ed4 cc-langs.el --- a/cc-langs.el Wed Jun 21 14:58:04 2023 +0000 +++ b/cc-langs.el Wed Jun 21 19:14:40 2023 +0000 @@ -819,8 +819,9 @@ keyword. It's unspecified how far it matches. Does not contain a \\| operator at the top level." t (concat "[" c-alpha "_]") + (c c++) (concat "[" c-alpha "_$]") java (concat "[" c-alpha "_@]") - objc (concat "[" c-alpha "@]") + objc (concat "[" c-alpha "@$]") pike (concat "[" c-alpha "_`]")) (c-lang-defvar c-symbol-start (c-lang-const c-symbol-start)) @@ -844,9 +845,10 @@ t (concat (c-lang-const c-symbol-start) "[" (c-lang-const c-symbol-chars) "]\\{,1000\\}") pike (concat - ;; Use the value from C here since the operator backquote is + ;; Use the value from AWK here since the operator backquote is ;; covered by the other alternative. - (c-lang-const c-symbol-key c) + (c-lang-const c-symbol-key awk + ) "\\|" (c-make-keywords-re nil (c-lang-const c-overloadable-operators)))) -- Alan Mackenzie (Nuremberg, Germany).