aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMichal Nazarewicz2020-05-04 19:08:10 +0100
committerMichal Nazarewicz2020-05-09 11:30:32 +0100
commitae3c510696f02f01d03052f070e5ce65b4018a45 (patch)
tree7ffda57aed8788d8b0cbfbb16d486c0d0db15b97 /lisp
parentfab23328512e47a50caced8d074e86e583cc8a9f (diff)
downloademacs-ae3c510696f02f01d03052f070e5ce65b4018a45.tar.gz
emacs-ae3c510696f02f01d03052f070e5ce65b4018a45.zip
cc-mode: extend regexp used by ‘c-or-c++-mode’
* lisp/progmodes/cc-mode (c-or-c++-mode--regexp): Expand the regexp to match some more C++-only constructs and recognise a few more standard C++ header files. Also make sure identifiers start with non-digit. (c-or-c++-mode): Add ‘(interactive)’ declaration. * test/lisp/progmodes/cc-mode-tests.el (c-or-c++-mode): Add test case for the newly recognised constructs.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/cc-mode.el21
1 files changed, 15 insertions, 6 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index f92d3efdeb7..e3a924efb06 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -2541,13 +2541,21 @@ Key bindings:
2541 2541
2542(defconst c-or-c++-mode--regexp 2542(defconst c-or-c++-mode--regexp
2543 (eval-when-compile 2543 (eval-when-compile
2544 (let ((id "[a-zA-Z0-9_]+") (ws "[ \t\r]+") (ws-maybe "[ \t\r]*")) 2544 (let ((id "[a-zA-Z_][a-zA-Z0-9_]*") (ws "[ \t\r]+") (ws-maybe "[ \t\r]*")
2545 (headers '("string" "string_view" "iostream" "map" "unordered_map"
2546 "set" "unordered_set" "vector" "tuple")))
2545 (concat "^" ws-maybe "\\(?:" 2547 (concat "^" ws-maybe "\\(?:"
2546 "using" ws "\\(?:namespace" ws "std;\\|std::\\)" 2548 "using" ws "\\(?:namespace" ws
2547 "\\|" "namespace" "\\(:?" ws id "\\)?" ws-maybe "{" 2549 "\\|" id "::"
2548 "\\|" "class" ws id ws-maybe "[:{\n]" 2550 "\\|" id ws-maybe "=\\)"
2549 "\\|" "template" ws-maybe "<.*>" 2551 "\\|" "\\(?:inline" ws "\\)?namespace"
2550 "\\|" "#include" ws-maybe "<\\(?:string\\|iostream\\|map\\)>" 2552 "\\(:?" ws "\\(?:" id "::\\)*" id "\\)?" ws-maybe "{"
2553 "\\|" "class" ws id
2554 "\\(?:" ws "final" "\\)?" ws-maybe "[:{;\n]"
2555 "\\|" "struct" ws id "\\(?:" ws "final" ws-maybe "[:{\n]"
2556 "\\|" ws-maybe ":\\)"
2557 "\\|" "template" ws-maybe "<.*?>"
2558 "\\|" "#include" ws-maybe "<" (regexp-opt headers) ">"
2551 "\\)"))) 2559 "\\)")))
2552 "A regexp applied to C header files to check if they are really C++.") 2560 "A regexp applied to C header files to check if they are really C++.")
2553 2561
@@ -2563,6 +2571,7 @@ should be used.
2563This function attempts to use file contents to determine whether 2571This function attempts to use file contents to determine whether
2564the code is C or C++ and based on that chooses whether to enable 2572the code is C or C++ and based on that chooses whether to enable
2565`c-mode' or `c++-mode'." 2573`c-mode' or `c++-mode'."
2574 (interactive)
2566 (if (save-excursion 2575 (if (save-excursion
2567 (save-restriction 2576 (save-restriction
2568 (save-match-data 2577 (save-match-data