emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 11b81a5: Partially correct fontification of "(b*3)"


From: Alan Mackenzie
Subject: [Emacs-diffs] master 11b81a5: Partially correct fontification of "(b*3)", and the like, in C++ Mode
Date: Thu, 29 Dec 2016 15:37:54 +0000 (UTC)

branch: master
commit 11b81a54d538e8deca3cd64521cf85409efb617b
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Partially correct fontification of "(b*3)", and the like, in C++ Mode
    
    This problem is caused by the fundamental ambiguity in C++ between
    argument declarations and initialisation clauses.
    
    * lisp/progmodes/cc-fonts.el (c-font-lock-declarations): If we have an open
    paren preceded by an arithmetic operator, we give this the context nil, not
    'arglist.
    
    * lisp/progmodes/cc-langs.el (c-arithmetic-operators, 
c-arithmetic-op-regexp):
    New lang consts and vars.
---
 lisp/progmodes/cc-fonts.el |    7 +++++++
 lisp/progmodes/cc-langs.el |   16 ++++++++++++++++
 2 files changed, 23 insertions(+)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index 26a002a..39e68f0 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1311,6 +1311,13 @@ casts and declarations are fontified.  Used on level 2 
and higher."
                     ;; multiline declaration.
                     (c-put-char-property (1- match-pos)
                                          'c-type 'c-decl-arg-start))
+                   ;; Got an open paren preceded by an arith operator.
+                   ((and (eq (char-before match-pos) ?\()
+                         (save-excursion
+                           (and (zerop (c-backward-token-2 2))
+                                (looking-at c-arithmetic-op-regexp))))
+                    (setq context nil
+                          c-restricted-<>-arglists nil))
                    (t (setq context 'arglist
                             c-restricted-<>-arglists t))))
 
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 3c32848..83b8db3 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1248,6 +1248,22 @@ operators."
 (c-lang-defvar c-assignment-op-regexp
   (c-lang-const c-assignment-op-regexp))
 
+(c-lang-defconst c-arithmetic-operators
+  "List of all arithmetic operators, including \"+=\", etc."
+  ;; Note: in the following, there are too many operators for AWK and IDL.
+  t (append (c-lang-const c-assignment-operators)
+           '("+" "-" "*" "/" "%"
+             "<<" ">>"
+             "<" ">" "<=" ">="
+             "==" "!="
+             "&" "^" "|"
+             "&&" "||")))
+
+(c-lang-defconst c-arithmetic-op-regexp
+  t (c-make-keywords-re nil
+      (c-lang-const c-arithmetic-operators)))
+(c-lang-defvar c-arithmetic-op-regexp (c-lang-const c-arithmetic-op-regexp))
+
 (c-lang-defconst c-:$-multichar-token-regexp
   ;; Regexp matching all tokens ending in ":" which are longer than one char.
   ;; Currently (2016-01-07) only used in C++ Mode.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]