unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
@ 2016-05-24 17:01 Ivan Andrus
       [not found] ` <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org>
  0 siblings, 1 reply; 11+ messages in thread
From: Ivan Andrus @ 2016-05-24 17:01 UTC (permalink / raw)
  To: 23610

Starting with emacs -Q, Y is not fontified in the snippet below, whereas
X is.

-Ivan


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

};


In GNU Emacs 25.0.94.2 (x86_64-apple-darwin15.4.0, NS appkit-1404.46
Version 10.11.4 (Build 15E65))
of 2016-05-22 built on iandrus-osx
Repository revision: ae8352b8219b3d40f70fda8986ae86fbef7322fb
Windowing system distributor 'Apple', version 10.3.1404
Configured using:
'configure --with-ns --with-modules
PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig'

Configured features:
JPEG RSVG IMAGEMAGICK DBUS NOTIFY ACL GNUTLS LIBXML2 ZLIB
TOOLKIT_SCROLL_BARS NS MODULES

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: C++/l

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t
  abbrev-mode: t

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
user-error: The mark is not set now, so there is no region
Undo!
<C-s-268632064> is undefined
user-error: The mark is not set now, so there is no region
user-error: No mark set in this buffer
Mark set
Undo!

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message dired format-spec rfc822 mml
mml-sec password-cache epg epg-config gnus-util mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util help-fns mail-prsvr mail-utils
cl-extra help-mode cc-mode cc-fonts easymenu cc-guess cc-menus cc-cmds
cc-styles cc-align cc-engine cc-vars cc-defs cl-loaddefs pcase cl-lib
time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel ns-win ucs-normalize term/common-win tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment elisp-mode
lisp-mode prog-mode register page menu-bar rfn-eshadow timer select
scroll-bar mouse jit-lock font-lock syntax facemenu font-core frame
cl-generic cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian
slovak czech european ethiopic indian cyrillic chinese charscript
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind kqueue cocoa
ns multi-tty make-network-process emacs)

Memory information:
((conses 16 216680 9514)
(symbols 48 22190 2)
(miscs 40 50 243)
(strings 32 20775 6226)
(string-bytes 1 712665)
(vectors 16 35464)
(vector-slots 8 687847 4136)
(floats 8 163 110)
(intervals 56 332 8)
(buffers 976 11))





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
       [not found] ` <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org>
@ 2016-05-30 12:57   ` Alan Mackenzie
  2016-05-30 13:49     ` Óscar Fuentes
  2016-07-23 15:13     ` Alan Mackenzie
  2016-06-19 21:14   ` Alan Mackenzie
  1 sibling, 2 replies; 11+ messages in thread
From: Alan Mackenzie @ 2016-05-30 12:57 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 23610

Hello, Ivan.

In article <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org> you wrote:
> Starting with emacs -Q, Y is not fontified in the snippet below, whereas
> X is.

I'm not all that familiar with variadic templates.  In the declaration
below, is the "..." token syntactically part of "typename..." or is
better regarded as part of "... Y"?

I also need to get a feel for what keywords can come before the "...".
Obviously "typename", but what about things like "class"?

Do you know of a good web page where these things are explained
completely and concisely, yet readably?  If so, please tell me!

> -Ivan


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

> };


> In GNU Emacs 25.0.94.2 (x86_64-apple-darwin15.4.0, NS appkit-1404.46
> Version 10.11.4 (Build 15E65))
> of 2016-05-22 built on iandrus-osx
> Repository revision: ae8352b8219b3d40f70fda8986ae86fbef7322fb
> Windowing system distributor 'Apple', version 10.3.1404
> Configured using:
> 'configure --with-ns --with-modules
> PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig'

[ .... ]

-- 
Alan Mackenzie (Nuremberg, Germany).






^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-05-30 12:57   ` Alan Mackenzie
@ 2016-05-30 13:49     ` Óscar Fuentes
  2016-05-30 15:25       ` Alan Mackenzie
  2016-07-23 15:13     ` Alan Mackenzie
  1 sibling, 1 reply; 11+ messages in thread
From: Óscar Fuentes @ 2016-05-30 13:49 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Ivan Andrus, 23610

Hello Alan.

Alan Mackenzie <acm@muc.de> writes:

> I'm not all that familiar with variadic templates.  In the declaration
> below, is the "..." token syntactically part of "typename..." or is
> better regarded as part of "... Y"?

Neiter, I'll say.

It is legal to omit the name of the parameter pack (the `Y' in the
example).

> I also need to get a feel for what keywords can come before the "...".
> Obviously "typename", but what about things like "class"?

Yes, `class' and `typename' are interchangeable here. There is also
`sizeof':

template <typename ... Ts> struct Foo {
  void print() {
    printf("Intantiated with %d parameters.\n", sizeof...(Ts));
  }
};

int main() {
  Foo<int, double> foo;
  foo.print();
  return 0;
}


Prints

Intantiated with 2 parameters.


> Do you know of a good web page where these things are explained
> completely and concisely, yet readably?  If so, please tell me!

Try this, which is short and precise:

http://en.cppreference.com/w/cpp/language/parameter_pack





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-05-30 13:49     ` Óscar Fuentes
@ 2016-05-30 15:25       ` Alan Mackenzie
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Mackenzie @ 2016-05-30 15:25 UTC (permalink / raw)
  To: Óscar Fuentes; +Cc: Ivan Andrus, 23610

Hello, Óscar.

Thanks for your post!

On Mon, May 30, 2016 at 03:49:57PM +0200, Óscar Fuentes wrote:
> Hello Alan.

> Alan Mackenzie <acm@muc.de> writes:

> > I'm not all that familiar with variadic templates.  In the declaration
> > below, is the "..." token syntactically part of "typename..." or is
> > better regarded as part of "... Y"?

> Neither, I'll say.

> It is legal to omit the name of the parameter pack (the `Y' in the
> example).

> > I also need to get a feel for what keywords can come before the "...".
> > Obviously "typename", but what about things like "class"?

> Yes, `class' and `typename' are interchangeable here. There is also
> `sizeof':

I thought there might be something like that.  ;-)

> template <typename ... Ts> struct Foo {
>   void print() {
>     printf("Instantiated with %d parameters.\n", sizeof...(Ts));
>   }
> };

> int main() {
>   Foo<int, double> foo;
>   foo.print();
>   return 0;
> }


> Prints

> Intantiated with 2 parameters.


> > Do you know of a good web page where these things are explained
> > completely and concisely, yet readably?  If so, please tell me!

> Try this, which is short and precise:

> http://en.cppreference.com/w/cpp/language/parameter_pack

That looks like exactly what I need.  Thanks very much!

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
       [not found] ` <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org>
  2016-05-30 12:57   ` Alan Mackenzie
@ 2016-06-19 21:14   ` Alan Mackenzie
  2016-06-22 15:22     ` Ivan Andrus
  1 sibling, 1 reply; 11+ messages in thread
From: Alan Mackenzie @ 2016-06-19 21:14 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 23610

Hello, Ivan.

In article <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org> 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).






^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-06-19 21:14   ` Alan Mackenzie
@ 2016-06-22 15:22     ` Ivan Andrus
  2016-06-30 14:36       ` Alan Mackenzie
  2016-06-30 17:24       ` Alan Mackenzie
  0 siblings, 2 replies; 11+ messages in thread
From: Ivan Andrus @ 2016-06-22 15:22 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: 23610

On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm@muc.de> wrote:
> Hello, Ivan.
>
> In article <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org> 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.

It looks pretty good.  I didn't notice this before, but the following example
from Wikipedia is fontified differently if the ... is removed from before the
`args`.  In that case args is fontified with `font-lock-variable-name-face`.

  template<typename... Args> inline void expand(Args&&... args) {
    pass( some_function(args)... );
  }

FWIW, I've seen similar mis-fontifications before (without ...) and it hasn't
bothered me too much.  I just found a reproducible case, so I guess I'll
open a bug for it.

Thanks for working on this.  The raw string support is awesome!

-Ivan





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-06-22 15:22     ` Ivan Andrus
@ 2016-06-30 14:36       ` Alan Mackenzie
  2016-06-30 15:10         ` John Yates
  2016-06-30 17:24       ` Alan Mackenzie
  1 sibling, 1 reply; 11+ messages in thread
From: Alan Mackenzie @ 2016-06-30 14:36 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 23610

Hello, Ivan.

On Wed, Jun 22, 2016 at 09:22:01AM -0600, Ivan Andrus wrote:
> On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm@muc.de> wrote:
> > In article <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org> 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.

> It looks pretty good.  I didn't notice this before, but the following example
> from Wikipedia is fontified differently if the ... is removed from before the
> `args`.  In that case args is fontified with `font-lock-variable-name-face`.

>   template<typename... Args> inline void expand(Args&&... args) {
>     pass( some_function(args)... );
>   }

What is this "&&" operator?  It cannot be a logical and, and doesn't look
like anything to do with a move constructor.  I've tried, and failed, to
find an explanation in http://en.cppreference.com/w/cpp/language.  I
didn't find and explanation in the article "variadic templates" in
wikipedia either.  A pointer to a web page explaining it would be much
appreciated.

I'm tempted to commit the patch as it is at the moment, but feel I ought
to understand this "&&" first.

> FWIW, I've seen similar mis-fontifications before (without ...) and it hasn't
> bothered me too much.  I just found a reproducible case, so I guess I'll
> open a bug for it.

> Thanks for working on this.  The raw string support is awesome!

Thanks!  There've recently been one or two bugs fixed for raw string
support.  The corrections are in the Emacs master branch.

> -Ivan

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-06-30 14:36       ` Alan Mackenzie
@ 2016-06-30 15:10         ` John Yates
  2016-06-30 16:47           ` Alan Mackenzie
  0 siblings, 1 reply; 11+ messages in thread
From: John Yates @ 2016-06-30 15:10 UTC (permalink / raw)
  To: Alan Mackenzie; +Cc: Ivan Andrus, 23610

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

On Thu, Jun 30, 2016 at 10:36 AM, Alan Mackenzie <acm@muc.de> wrote:

> What is this "&&" operator?


​It is an "rvalue reference".

/john​



-- 
John Yates
109 Chandler St, #1
Boston, MA 02116

[-- Attachment #2: Type: text/html, Size: 885 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-06-30 15:10         ` John Yates
@ 2016-06-30 16:47           ` Alan Mackenzie
  0 siblings, 0 replies; 11+ messages in thread
From: Alan Mackenzie @ 2016-06-30 16:47 UTC (permalink / raw)
  To: John Yates; +Cc: Ivan Andrus, 23610

Hello, John.

On Thu, Jun 30, 2016 at 11:10:13AM -0400, John Yates wrote:
> On Thu, Jun 30, 2016 at 10:36 AM, Alan Mackenzie <acm@muc.de> wrote:

> > What is this "&&" operator?


> It is an "rvalue reference".

Thanks, that's exactly what I needed to know.  I've now got these
"Args&&... args" expressions fontifying.

> /john



> -- 
> John Yates
> 109 Chandler St, #1
> Boston, MA 02116

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-06-22 15:22     ` Ivan Andrus
  2016-06-30 14:36       ` Alan Mackenzie
@ 2016-06-30 17:24       ` Alan Mackenzie
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Mackenzie @ 2016-06-30 17:24 UTC (permalink / raw)
  To: Ivan Andrus; +Cc: 23610

Hello again, Ivan.

On Wed, Jun 22, 2016 at 09:22:01AM -0600, Ivan Andrus wrote:
> On Sun, Jun 19, 2016 at 3:14 PM, Alan Mackenzie <acm@muc.de> wrote:
> > Hello, Ivan.

> > In article <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org> 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.

> It looks pretty good.  I didn't notice this before, but the following example
> from Wikipedia is fontified differently if the ... is removed from before the
> `args`.  In that case args is fontified with `font-lock-variable-name-face`.

>   template<typename... Args> inline void expand(Args&&... args) {
>     pass( some_function(args)... );
>   }

OK.  I think the patch below fixes it.  Please try it out and report
back.  (Same instructions about recompilation of CC Mode as last time
apply, since further macros in cc-langs.el have been modified).  Please
note that the patch below is complete in itself, it isn't incremental,
based on the last patch.  It's based on a current Emacs master branch.




diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 48b9e5e..cc60175 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -7090,6 +7090,9 @@ c-forward-type
       (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 --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 4d36684..b903190 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1329,6 +1329,14 @@ 'c-opt-op-identitier-prefix
 (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
@@ -2958,6 +2966,10 @@ 'c-opt-op-identitier-prefix
 		   "\\)"
 		   "\\([^=]\\|$\\)")
   c++  (concat "\\("
+	       "&&"
+	       "\\|"
+	       "\\.\\.\\."
+	       "\\|"
 	       "[*(&]"
 	       "\\|"
 	       (c-lang-const c-type-decl-prefix-key)


> -Ivan

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename
  2016-05-30 12:57   ` Alan Mackenzie
  2016-05-30 13:49     ` Óscar Fuentes
@ 2016-07-23 15:13     ` Alan Mackenzie
  1 sibling, 0 replies; 11+ messages in thread
From: Alan Mackenzie @ 2016-07-23 15:13 UTC (permalink / raw)
  To: 23610-done; +Cc: Ivan Andrus

Bug fixed in master.

-- 
Alan Mackenzie (Nuremberg, Germany).





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-07-23 15:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-24 17:01 bug#23610: 25.0.94; c++-mode doesn't fontify typename... like typename Ivan Andrus
     [not found] ` <mailman.202.1464109329.1216.bug-gnu-emacs@gnu.org>
2016-05-30 12:57   ` Alan Mackenzie
2016-05-30 13:49     ` Óscar Fuentes
2016-05-30 15:25       ` Alan Mackenzie
2016-07-23 15:13     ` Alan Mackenzie
2016-06-19 21:14   ` Alan Mackenzie
2016-06-22 15:22     ` Ivan Andrus
2016-06-30 14:36       ` Alan Mackenzie
2016-06-30 15:10         ` John Yates
2016-06-30 16:47           ` Alan Mackenzie
2016-06-30 17:24       ` Alan Mackenzie

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).