[Top][All Lists]

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

Re: POC: customizable cc-mode keywords

From: Stefan Monnier
Subject: Re: POC: customizable cc-mode keywords
Date: Mon, 08 Sep 2014 13:28:32 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> :-)  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 ;-)


=== 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)

+(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)
 ;; 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]]

reply via email to

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