I'd like to set up an alist (similar to auto-mode-alist
), which is made up from regular expressions as key (AKA car) of the list. Next I'd like to be able, to match, say the major mode, against the regex in order to retrieve the value/cdr of the matching key/car.
(setq jb-string-mode-alist
'(("\\(emacs-\\)?lisp\\(-interaction\\)?-mode" . "Combined")
(lisp-interaction-mode . "Interaction") ; works
(emacs-lisp-mode . "Emacs") ; works also
(lisp-mode . "Lisp") ; works also
(latex-mode . "LaTeX") ; works also
(".*$" . "Default")))
Afterwards I tried something like the following:
(assoc major-mode jb-tools-date-time-string-mode-alist) ; => "Interaction"
Evaluating the expression in the *scratch*
buffer of emacs yields "Interaction"
as the mode of the *scratch*
buffer is lisp-interaction-mode
. This matches the third entry in my alist, but it should match the first entry consisting of the regular expression.
Using assq
instead of assoc
makes no difference.
What is the trick, to evaluate the mode with respect to regular expressions?