Function: c-make-keywords-re
c-make-keywords-re is a byte-compiled function defined in
cc-defs.el.gz.
Signature
(c-make-keywords-re ADORN LIST &optional MODE)
Documentation
Make a regexp that matches any string in LIST.
Duplicates and nil elements in the list are removed. The resulting regexp may contain zero or more submatch expressions.
In the typical case when all members of LIST are valid symbols, the resulting regexp is bracketed in \_<\( .... \)\_>.
When LIST is a mixture of symbols and non-symbols, the symbol part of the resulting regexp is bracketed in \_< .... \_> and the first submatch of the regexp surrounds the entire matched string.
Otherwise, if ADORN is t there will be at least one submatch and the first surrounds the matched alternative, and the regexp will also not match a prefix of any identifier.
Adorned regexps can now (2025-06) be appended to. In versions prior to
2025-06, there was also the value appendable for ADORN. Since normal
adorned regexps can now be appended to anyway, this is no longer needed,
but older code using it will still work.
The optional MODE specifies the language whose syntax table will be used
to characterize the input strings. The default is the current language
taken from c-buffer-is-cc-mode.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-defs.el.gz
(defun c-make-keywords-re (adorn list &optional mode)
"Make a regexp that matches any string in LIST.
Duplicates and nil elements in the list are removed. The
resulting regexp may contain zero or more submatch expressions.
In the typical case when all members of LIST are valid symbols, the
resulting regexp is bracketed in \\_<\\( .... \\)\\_>.
When LIST is a mixture of symbols and non-symbols, the symbol part of
the resulting regexp is bracketed in \\_< .... \\_> and the first
submatch of the regexp surrounds the entire matched string.
Otherwise, if ADORN is t there will be at least one submatch and the
first surrounds the matched alternative, and the regexp will also not
match a prefix of any identifier.
Adorned regexps can now (2025-06) be appended to. In versions prior to
2025-06, there was also the value `appendable' for ADORN. Since normal
adorned regexps can now be appended to anyway, this is no longer needed,
but older code using it will still work.
The optional MODE specifies the language whose syntax table will be used
to characterize the input strings. The default is the current language
taken from `c-buffer-is-cc-mode'."
(c-with-syntax-table
;; If we're being called at run time, we use the mode's run time syntax
;; table. Otherwise, generate one as needed for the current MODE.
(let ((cur-syn-tab-sym
(intern (concat (symbol-name (or mode c-buffer-is-cc-mode))
"-syntax-table"))))
(if (and (boundp cur-syn-tab-sym)
(syntax-table-p (symbol-value cur-syn-tab-sym)))
(symbol-value cur-syn-tab-sym)
(funcall (c-get-lang-constant 'c-make-mode-syntax-table nil mode))))
(let ((liszt (remq nil list))
symbols non-symbols)
(dolist (elt liszt)
(if (string-match "\\`\\(\\sw\\|\\s_\\)*\\'" elt)
(push elt symbols)
(push elt non-symbols)))
(cond
((null liszt)
(if adorn
"\\(\\`a\\`\\)"
"\\`a\\`"))
((and symbols non-symbols)
(let ((symbol-re (regexp-opt symbols 'symbols))
(non-symbol-re (regexp-opt non-symbols t)))
(concat "\\(" symbol-re "\\|" non-symbol-re "\\)")))
(symbols
(regexp-opt symbols 'symbols))
(adorn (regexp-opt non-symbols t))
(t (regexp-opt non-symbols))))))