summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-vars.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2016-02-29 21:51:32 +0000
committerAlan Mackenzie <acm@muc.de>2016-02-29 21:51:32 +0000
commit71dc8213b18d4baa5802cf6b7181d81f1f76cbdb (patch)
tree54831c443e29609d57d02ab4916b4d34a921350d /lisp/progmodes/cc-vars.el
parent93bf7d52841c60ffc10e0c9c789a7987812ce55e (diff)
downloademacs-71dc8213b18d4baa5802cf6b7181d81f1f76cbdb.tar.gz
Handle "noise" macros and compiler directives.
* lisp/progmodes/cc-langs.el (c-symbol-char-key): New language variable. * lisp/progmodes/cc-vars.el (c-noise-macro-names) (c-noise-macro-with-parens-names): New customizable variables. (c-noise-macro-name-re, c-noise-macro-with-parens-name-re): New variables. (c-make-noise-macro-regexps): New function. * lisp/progmodes/cc-engine.el (c-forward-sws, c-backward-sws): Adapt to treat members of c-noise-macro-names as whitespace. (c-forward-noise-clause): New function. (c-forward-keyword-prefixed-id, c-forward-type, c-forward-declarator) (c-forward-decl-or-cast-1, c-backward-over-enum-header) (c-guess-basic-syntax CASE 5A.3, CASE 5A.5, CASE 9A): Handle "noise clauses" in parallel with, e.g., "hangon key clauses". * lisp/progmodes/cc-fonts.el (c-complex-decl-matchers): Handle "noise clauses" in parallel with "prefix-spec keywords". * lisp/progmodes/cc-mode.el (c-mode, c++-mode, objc-mode): call c-make-noise-macro-regexps to initialize the internal variables. * doc/misc/cc-mode.texi ("Noise Macros"): New section documenting the new facilities.
Diffstat (limited to 'lisp/progmodes/cc-vars.el')
-rw-r--r--lisp/progmodes/cc-vars.el43
1 files changed, 43 insertions, 0 deletions
diff --git a/lisp/progmodes/cc-vars.el b/lisp/progmodes/cc-vars.el
index 8cee733ec8e..a6957185a2b 100644
--- a/lisp/progmodes/cc-vars.el
+++ b/lisp/progmodes/cc-vars.el
@@ -1619,6 +1619,49 @@ names)."))
:type 'c-extra-types-widget
:group 'c)
+(defvar c-noise-macro-with-parens-name-re nil)
+(defvar c-noise-macro-name-re nil)
+
+(defcustom c-noise-macro-names nil
+ "A list of names of macros which expand to nothing, or compiler extensions
+like \"????\" which are syntactic noise. Such a macro/extension is complete in
+itself, never having parentheses. All these names must be syntactically valid
+identifiers.
+
+If you change this variable's value, call the function
+`c-make-noise-macro-regexps' to set the necessary internal variables (or do
+this implicitly by reinitialising C/C++/Objc Mode on any buffer)."
+ :type '(repeat :tag "List of names" string)
+ :group 'c)
+
+(defcustom c-noise-macro-with-parens-names nil
+ "A list of names of macros \(or compiler extensions like \"__attribute__\")
+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)
+
+(defun c-make-noise-macro-regexps ()
+ ;; Convert `c-noise-macro-names' and `c-noise-macro-with-parens-names' into
+ ;; `c-noise-macro-name-re' and `c-noise-macro-with-parens-name-re'.
+ (setq c-noise-macro-with-parens-name-re
+ (cond ((null c-noise-macro-with-parens-names) "\\<\\>")
+ ((consp c-noise-macro-with-parens-names)
+ (concat (regexp-opt c-noise-macro-with-parens-names t)
+ "\\([^[:alnum:]_$]\\|$\\)"))
+ ((stringp c-noise-macro-with-parens-names)
+ (copy-sequence c-noise-macro-with-parens-names))
+ (t (error "c-make-noise-macro-regexps: \
+c-noise-macro-with-parens-names is invalid: %s" c-noise-macro-with-parens-names))))
+ (setq c-noise-macro-name-re
+ (cond ((null c-noise-macro-names) "\\<\\>")
+ ((consp c-noise-macro-names)
+ (concat (regexp-opt c-noise-macro-names t)
+ "\\([^[:alnum:]_$]\\|$\\)"))
+ ((stringp c-noise-macro-names)
+ (copy-sequence c-noise-macro-names))
+ (t (error "c-make-noise-macro-regexps: \
+c-noise-macro-names is invalid: %s" c-noise-macro-names)))))
;; Non-customizable variables, still part of the interface to CC Mode
(defvar c-macro-with-semi-re nil