summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-vars.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2016-05-09 17:49:45 +0000
committerAlan Mackenzie <acm@muc.de>2016-05-09 17:49:45 +0000
commita8231e00cbad60652ff7ab6ae51a758f1d939971 (patch)
treeabbdd240734fb41710e542335fea763e12601596 /lisp/progmodes/cc-vars.el
parent608f2bd0ac9d950a04ad73bf36d96d25b469b9be (diff)
downloademacs-a8231e00cbad60652ff7ab6ae51a758f1d939971.tar.gz
CC Mode now uses the new :after-hook feature of define-derived-mode
It now runs internal variable setting functions after the mode hooks, no longer runs the mode hooks twice, and declares the configuration variables for noise macros and macros with semicolons as safe variables (when given suitable arguments). Fixes bug #16759 and bug #23476. * .dir-locals: Put the c-noise-macros-with-paren-names setting back into the C Mode value. * lisp/progmodes/cc-mode.el: (c-basic-common-init): Remove the call to c-make-macro-with-semi-re. (c-mode, c++-mode, objc-mode, java-mode, idl-mode, pike-mode, awk-mode): Move c-make-noise-macro-regexps and c-make-macro-with-semi-re (where appropriate) and c-update-modeline into the :after-hook form. Remove the explicit settings of the syntax table, the abbreviation table and the local key map, since they duplicate forms generated by define-derived-mode. Remove the explicit invocation of each mode's mode hook, since they duplicate ones generated by define-derived-mode. * lisp/progmodes/cc-vars.el: (c-string-list-p, c-string-or-string-list-p): New functions. (c-noise-macro-names, c-noise-macro-with-parens-names): give the save-local-variable property c-string-list-p. (c-macro-names-with-semicolon): give the save-local-variable property c-string-or-string-list-p. * doc/misc/cc-mode.texi: (Macros with ;, Noise Macros): Note that it's not necessary to call the regexp generating functions after setting the pertinent configuration values in a mode hook.
Diffstat (limited to 'lisp/progmodes/cc-vars.el')
-rw-r--r--lisp/progmodes/cc-vars.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index 98195da9456..8cad27fd86d 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -229,7 +229,20 @@ See `c-offsets-alist'."
(setq offset (cdr offset)))
(null offset)))))
-
+(defun c-string-list-p (val)
+ "Return non-nil if VAL is a list of strings."
+ (and
+ (listp val)
+ (catch 'string
+ (dolist (elt val)
+ (if (not (stringp elt))
+ (throw 'string nil)))
+ t)))
+
+(defun c-string-or-string-list-p (val)
+ "Return non-nil if VAL is a string or a list of strings."
+ (or (stringp val)
+ (c-string-list-p val)))
;;; User variables
@@ -1633,6 +1646,7 @@ If you change this variable's value, call the function
this implicitly by reinitializing C/C++/Objc Mode on any buffer)."
:type '(repeat :tag "List of names" string)
:group 'c)
+(put 'c-noise-macro-names 'safe-local-variable #'c-string-list-p)
(defcustom c-noise-macro-with-parens-names nil
"A list of names of macros \(or compiler extensions like \"__attribute__\")
@@ -1640,6 +1654,7 @@ which optionally have arguments in parentheses, and which expand to nothing.
These are recognized by CC Mode only in declarations."
:type '(regexp :tag "List of names (possibly empty)" string)
:group 'c)
+(put 'c-noise-macro-with-parens-names 'safe-local-variable #'c-string-list-p)
(defun c-make-noise-macro-regexps ()
;; Convert `c-noise-macro-names' and `c-noise-macro-with-parens-names' into
@@ -1690,6 +1705,8 @@ variables.
Note that currently \(2008-11-04) this variable is a prototype,
and is likely to disappear or change its form soon.")
(make-variable-buffer-local 'c-macro-names-with-semicolon)
+(put 'c-macro-names-with-semicolon 'safe-local-variable
+ #'c-string-or-string-list-p)
(defun c-make-macro-with-semi-re ()
;; Convert `c-macro-names-with-semicolon' into the regexp