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 \_<\( .... \)\_>.
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 \\_<\\( .... \\)\\_>.
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)))
(cond
((null liszt)
(if adorn
"\\(\\`a\\`\\)"
"\\`a\\`"))
((catch 'symbols
(dolist (elt liszt)
(unless (string-match "\\`\\(\\sw\\|\\s_\\)*\\'" elt)
(throw 'symbols nil)))
t)
(regexp-opt liszt 'symbols))
(adorn (regexp-opt liszt t))
(t (regexp-opt liszt))))))