tags:

views:

30

answers:

2

I've started playing around with elisp to create font-locks (syntax highlighting) in Emacs. Most of the tutorials out there mention using an elisp function "regexp-opt" to optimize regular expressions, but my version of emacs (23.2) doesn't seem to have that function. Furthermore, Googling for the answer doesn't seem to turn up useful results. Any ideas?

+4  A: 

As you can find out via C-h f regexp-opt:

regexp-opt is a compiled Lisp function.

(regexp-opt strings &optional paren)

Return a regexp to match a string in the list strings. Each string should be unique in strings and should not contain any regexps, quoted or not. If optional paren is non-nil, ensure that the returned regexp is enclosed by at least one regexp grouping construct. The returned regexp is typically more efficient than the equivalent regexp:

(let ((open (if paren "\(" "")) (close (if paren "\)" "")))
(concat open (mapconcat 'regexp-quote strings "\|") close))

If paren is `words', then the resulting regexp is additionally surrounded by \< and >.

Note, that it is a function to be used in Lisp code, not an interactive command which you could run with M-x

Dirk
+1  A: 

regexexp-opt is a elisp function but not an emacs command. That is why you cannot execute it by running: M-x regexp-opt

However, you can execute any elisp function from the elisp shell. Type in M-x eshell. And from this shell you can run regexp-opt

Matthew Manela