Subject: Re: bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename

From: Alan Mackenzie <[email-masked]>
Date: 19 Jun 2016 21:14:40 -0000

Hello, Ivan.

In article <[email-masked]> you wrote:
> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> X is.

> -Ivan

> template <typename X, typename... Y>
> class bob {

> };

[ .... ]

The following patch is a first attempt to fontify parameter packs.  After
applying it, please be sure either to recompile CC Mode entirely, or
first to compile cc-langs.el (which contains macros), and then all three
of cc-fonts.el, cc-engine.el, and cc-mode.el.

It seems to fontify the "Y" above OK.  I've tried it on a stock example
out of Wikipedia, and that works.  Could you try it out on your code,
please, and let me know how well it works.

Here's the patch:

diff -r f70569e7cf8e cc-engine.el
--- a/cc-engine.el	Sun Jun 19 11:54:55 2016 +0000
+++ b/cc-engine.el	Sun Jun 19 21:05:32 2016 +0000
@@ -6910,6 +6910,9 @@
       (while (cond
 	      ((looking-at c-decl-hangon-key)
 	       (c-forward-keyword-clause 1))
+	      ((looking-at c-pack-key)
+	       (goto-char (match-end 1))
+	       (c-forward-syntactic-ws))
 	      ((and c-opt-cpp-prefix
 		    (looking-at c-noise-macro-with-parens-name-re))
 	       (c-forward-noise-clause))))
diff -r f70569e7cf8e cc-langs.el
--- a/cc-langs.el	Sun Jun 19 11:54:55 2016 +0000
+++ b/cc-langs.el	Sun Jun 19 21:05:32 2016 +0000
@@ -1304,6 +1304,14 @@
 (c-lang-defvar c-stmt-delim-chars-with-comma
   (c-lang-const c-stmt-delim-chars-with-comma))
 
+(c-lang-defconst c-pack-ops
+  "Ops which signal C++11's \"parameter pack\""
+  t nil
+  c++ '("..."))
+(c-lang-defconst c-pack-key
+  t (c-make-keywords-re 'appendable (c-lang-const c-pack-ops)))
+(c-lang-defvar c-pack-key (c-lang-const c-pack-key))
+
 (c-lang-defconst c-auto-ops
   ;; Ops which signal C++11's new auto uses.
   t nil

-- 
Alan Mackenzie (Nuremberg, Germany).