aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2026-03-02 15:59:14 +0000
committerEli Zaretskii2026-03-03 16:19:16 +0200
commitb5e2b0bec12042b7be4eea5e87be4fe2174bc55c (patch)
tree503147a8606b6d10cecc8ce84f53d68e40f81299
parent9563101c4752fd2e8eda21423abd7a6cc5afcacb (diff)
downloademacs-b5e2b0bec12042b7be4eea5e87be4fe2174bc55c.tar.gz
emacs-b5e2b0bec12042b7be4eea5e87be4fe2174bc55c.zip
CC Mode: Handle mixed symbols and non-symbols in regexps
This fixes bug#80507. * lisp/progmodes/cc-defs.el (c-make-keywords-re): When a mixed list of symbols and non-symbols is presented to this function, put "\_< .... \_>" brackets around the part which handles the symbols in the resulting regexp.
-rw-r--r--lisp/progmodes/cc-defs.el39
1 files changed, 24 insertions, 15 deletions
diff --git a/lisp/progmodes/cc-defs.el b/lisp/progmodes/cc-defs.el
index a41f7eb3622..b6ad0b83765 100644
--- a/lisp/progmodes/cc-defs.el
+++ b/lisp/progmodes/cc-defs.el
@@ -2152,13 +2152,18 @@ resulting regexp may contain zero or more submatch expressions.
2152In the typical case when all members of LIST are valid symbols, the 2152In the typical case when all members of LIST are valid symbols, the
2153resulting regexp is bracketed in \\_<\\( .... \\)\\_>. 2153resulting regexp is bracketed in \\_<\\( .... \\)\\_>.
2154 2154
2155When LIST is a mixture of symbols and non-symbols, the symbol part of
2156the resulting regexp is bracketed in \\_< .... \\_> and the first
2157submatch of the regexp surrounds the entire matched string.
2158
2155Otherwise, if ADORN is t there will be at least one submatch and the 2159Otherwise, if ADORN is t there will be at least one submatch and the
2156first surrounds the matched alternative, and the regexp will also not 2160first surrounds the matched alternative, and the regexp will also not
2157match a prefix of any identifier. Adorned regexps can now (2025-06) be 2161match a prefix of any identifier.
2158appended to. In versions prior to 2025-06, there was also the value 2162
2159`appendable' for ADORN. Since normal adorned regexps can now be 2163Adorned regexps can now (2025-06) be appended to. In versions prior to
2160appended to anyway, this is no longer needed, but older code using it 21642025-06, there was also the value `appendable' for ADORN. Since normal
2161will still work. 2165adorned regexps can now be appended to anyway, this is no longer needed,
2166but older code using it will still work.
2162 2167
2163The optional MODE specifies the language whose syntax table will be used 2168The optional MODE specifies the language whose syntax table will be used
2164to characterize the input strings. The default is the current language 2169to characterize the input strings. The default is the current language
@@ -2173,21 +2178,25 @@ taken from `c-buffer-is-cc-mode'."
2173 (syntax-table-p (symbol-value cur-syn-tab-sym))) 2178 (syntax-table-p (symbol-value cur-syn-tab-sym)))
2174 (symbol-value cur-syn-tab-sym) 2179 (symbol-value cur-syn-tab-sym)
2175 (funcall (c-get-lang-constant 'c-make-mode-syntax-table nil mode)))) 2180 (funcall (c-get-lang-constant 'c-make-mode-syntax-table nil mode))))
2176 (let ((liszt (remq nil list))) 2181 (let ((liszt (remq nil list))
2182 symbols non-symbols)
2183 (dolist (elt liszt)
2184 (if (string-match "\\`\\(\\sw\\|\\s_\\)*\\'" elt)
2185 (push elt symbols)
2186 (push elt non-symbols)))
2177 (cond 2187 (cond
2178 ((null liszt) 2188 ((null liszt)
2179 (if adorn 2189 (if adorn
2180 "\\(\\`a\\`\\)" 2190 "\\(\\`a\\`\\)"
2181 "\\`a\\`")) 2191 "\\`a\\`"))
2182 ((catch 'symbols 2192 ((and symbols non-symbols)
2183 (dolist (elt liszt) 2193 (let ((symbol-re (regexp-opt symbols 'symbols))
2184 (unless (string-match "\\`\\(\\sw\\|\\s_\\)*\\'" elt) 2194 (non-symbol-re (regexp-opt non-symbols t)))
2185 (throw 'symbols nil))) 2195 (concat "\\(" symbol-re "\\|" non-symbol-re "\\)")))
2186 t) 2196 (symbols
2187 (regexp-opt liszt 'symbols)) 2197 (regexp-opt symbols 'symbols))
2188 (adorn (regexp-opt liszt t)) 2198 (adorn (regexp-opt non-symbols t))
2189 (t (regexp-opt liszt)))))) 2199 (t (regexp-opt non-symbols))))))
2190
2191(put 'c-make-keywords-re 'lisp-indent-function 1) 2200(put 'c-make-keywords-re 'lisp-indent-function 1)
2192 2201
2193(defun c-make-bare-char-alt (chars &optional inverted) 2202(defun c-make-bare-char-alt (chars &optional inverted)