unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Alan Mackenzie <acm@muc.de>
Cc: Daniel Colascione <dancol@dancol.org>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: POC: customizable cc-mode keywords
Date: Mon, 08 Sep 2014 13:28:32 -0400	[thread overview]
Message-ID: <jwvtx4iowv2.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20140518213331.GB2577@acm.acm> (Alan Mackenzie's message of "Sun, 18 May 2014 21:33:31 +0000")

> :-)  This problem was first highlighted as such, by you, this month, not
> several years ago.  Your patch is complicated, it's disruptive, yet you
> seem put out that I want to discuss it and understand it, rather than
> just blindly applying it as it is.

FWIW, his patch is not that complicated.  It has 2 parts:
- get rid of some of the compile-time precomputation of settings.
- add a new (set of) custom vars and use them where appropriate.

The second part is very straightforward (quoted below, for reference).
The first part mostly removes code, and more specifically removes
complex code, so it actually makes the code simpler.

I think the performance impact is higher than what Daniel claims
(his machine is clearly faster than mine), but I suspect that this can
be fixed.

>> It's not a massive change in architecture.
> As I said, I don't fully understand the change, yet.

Take another look at it, below.

> But moving calculations from compile time to run time _is_ a change of
> architecture, and it seems to me not to be small.

Right, this one is larger, but if it can be made without significant
performance degradation, then it's a good change.

> It seems to me that the rigid separation between language (e.g. C) and
> user configuration is being broken down.  How much easier will it be
> for a user mistakenly to attempt to configure her CC Mode by messing
> around with the c-lang-consts?

I'm not too worried ;-)


        Stefan


=== modified file 'lisp/progmodes/cc-langs.el'
--- lisp/progmodes/cc-langs.el	2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-langs.el	2014-05-02 05:19:24 +0000
@@ -1921,15 +1921,13 @@
   ;; declaration.  Specifically, they aren't recognized in the middle
   ;; of multi-token types, inside declarators, and between the
   ;; identifier and the arglist paren of a function declaration.
-  ;;
-  ;; FIXME: This ought to be user customizable since compiler stuff
-  ;; like this usually is wrapped in project specific macros.  (It'd
-  ;; of course be even better if we could cope without knowing this.)
-  t nil
-  (c c++) '(;; GCC extension.
-	    "__attribute__"
-	    ;; MSVC extension.
-	    "__declspec"))
+  t (when (boundp (c-mode-symbol "extra-keywords"))
+      (mapcar #'car (c-mode-var "extra-keywords")))
+  (c c++) (append (c-lang-const c-decl-hangon-kwds)
+                  '( ;; GCC extension.
+                    "__attribute__"
+                    ;; MSVC extension.
+                    "__declspec")))

 (c-lang-defconst c-decl-hangon-key
   ;; Adorned regexp matching `c-decl-hangon-kwds'.
@@ -2120,11 +2118,18 @@
 (c-lang-defconst c-paren-nontype-kwds
   "Keywords that may be followed by a parenthesis expression that doesn't
 contain type identifiers."
-  t       nil
-  (c c++) '(;; GCC extension.
-	    "__attribute__"
-	    ;; MSVC extension.
-	    "__declspec"))
+  t       (when (boundp (c-mode-symbol "extra-keywords"))
+            (apply 'nconc
+                   (mapcar (lambda (kw)
+                             (when (cdr kw)
+                               (list (car kw))))
+                           (c-mode-var "extra-keywords"))))
+  (c c++) (append
+           (c-lang-const c-paren-nontype-kwds)
+           '( ;; GCC extension.
+             "__attribute__"
+             ;; MSVC extension.
+             "__declspec")))

 (c-lang-defconst c-paren-type-kwds
   "Keywords that may be followed by a parenthesis expression containing
=== modified file 'lisp/progmodes/cc-vars.el'
--- lisp/progmodes/cc-vars.el	2014-01-01 07:43:34 +0000
+++ lisp/progmodes/cc-vars.el	2014-05-02 05:24:28 +0000
@@ -1614,6 +1614,75 @@
   :group 'c)

 \f
+
+(define-widget 'c-extra-keywords-widget 'lazy
+  "Internal CC Mode widget for the `*-extra-keywords' variables."
+  :type '(repeat
+          (cons
+           (string :tag "Keyword")
+           (boolean :tag "Parenthesized expression follows"))))
+
+(defun c-make-extra-keywords-blurb (mode1 mode2)
+  (concat "\
+*List of extra keywords to recognize in "
+          mode1 " mode.
+Each list item should be a cons (KW . PAREN).
+KW should be a string naming a single identifier.
+PAREN should be nil or t.  If t, expect the a parenthesized expression
+after KW and skip over it.
+
+Note that this variable is only consulted when the major mode is
+initialized.  If you change it later you have to reinitialize CC
+Mode by doing \\[" mode2 "].  Additionally, if you change this
+variable outside of customize, you need to call
+`c-clear-value-cache' to make your changes take effect."))
+
+(defun c-extra-keywords-setter (sym val)
+  (set-default sym val)
+  (c-clear-value-cache))
+
+(defcustom c-extra-keywords
+  nil
+  (c-make-extra-keywords-blurb "C" "c-mode")
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+(defcustom c++-extra-keywords
+  nil
+  (c-make-extra-keywords-blurb "C++" "c++-mode")
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+(defcustom objc-extra-keywords
+  nil
+  (c-make-extra-keywords-blurb "ObjC" "objc-mode")
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+(defcustom java-extra-keywords
+  nil
+  (c-make-extra-keywords-blurb "Java" "java-mode")
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+(defcustom idl-extra-keywords nil
+  nil
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+(defcustom pike-extra-keywords
+  nil
+  (c-make-extra-keywords-blurb "Pike" "pike-mode")
+  :type 'c-extra-keywords-widget
+  :set 'c-extra-keywords-setter
+  :group 'c)
+
+\f
 ;; Non-customizable variables, still part of the interface to CC Mode
 (defvar c-macro-with-semi-re nil
   ;; Regular expression which matches a (#define'd) symbol whose expansion


[[End of PGP Signed Part]]



  parent reply	other threads:[~2014-09-08 17:28 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-02  5:26 POC: customizable cc-mode keywords Daniel Colascione
2014-05-10 23:13 ` Daniel Colascione
2014-05-11 21:13 ` Alan Mackenzie
2014-05-11 21:23   ` Daniel Colascione
2014-05-16 17:52     ` Alan Mackenzie
2014-05-16 18:06       ` Daniel Colascione
2014-05-18 21:33         ` Alan Mackenzie
2014-05-18 22:28           ` Daniel Colascione
2014-05-19  2:25             ` Stefan Monnier
2014-05-25 18:08             ` Alan Mackenzie
2014-09-08 17:28           ` Stefan Monnier [this message]
2014-09-11 13:55             ` Further CC-mode changes Stefan Monnier
2014-09-12 23:59               ` Alan Mackenzie
2014-09-13  1:09                 ` Ivan Andrus
2014-09-13 10:04                   ` Alan Mackenzie
2014-09-13  3:04                 ` Stefan Monnier
2014-09-13 15:10                   ` Alan Mackenzie
2014-09-13 19:24                     ` Stefan Monnier
2014-09-13 23:08                       ` Syntax-propertize and CC-mode [Was: Further CC-mode changes] Alan Mackenzie
2014-09-14  4:04                         ` Stefan Monnier
2014-09-16 17:30                       ` Sync'ing cc-mode Stefan Monnier
2014-09-26 19:19                         ` Stefan Monnier
2014-09-15 20:24                     ` Further CC-mode changes Glenn Morris
2014-09-16  3:07                       ` Stephen J. Turnbull
2014-09-16 13:39                         ` Stefan Monnier
2014-09-16 14:22                         ` David Kastrup
2014-09-16 23:40                           ` Stephen J. Turnbull
2014-09-17  1:02                             ` Stefan Monnier
2014-09-17  1:48                               ` Stephen J. Turnbull
2014-09-17  5:22                                 ` David Kastrup
2014-09-17 13:00                                   ` Stefan Monnier
2014-09-17 18:31                               ` Glenn Morris
2014-09-17 19:12                                 ` David Kastrup
2014-09-17  5:24                             ` Eli Zaretskii
2014-09-17  6:54                               ` Stephen J. Turnbull
2014-09-17  7:20                                 ` Eli Zaretskii
2014-09-17  7:30                                 ` David Kastrup
2014-09-17 13:04                                 ` Stefan Monnier
2014-09-17 18:25                                   ` Glenn Morris
2014-09-18  5:20                                   ` Stephen J. Turnbull
2014-09-18  9:44                             ` Emilio Lopes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvtx4iowv2.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=acm@muc.de \
    --cc=dancol@dancol.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).