Function: apropos-parse-pattern
apropos-parse-pattern is a byte-compiled function defined in
apropos.el.gz.
Signature
(apropos-parse-pattern PATTERN &optional MULTILINE-P)
Documentation
Rewrite a list of words to a regexp matching all permutations.
If PATTERN is a string, that means it is already a regexp.
MULTILINE-P, if non-nil, means produce a regexp that will match
the words even if separated by newlines.
This updates variables apropos-pattern, apropos-pattern-quoted,
apropos-regexp, apropos-words, and apropos-all-words-regexp.
Source Code
;; Defined in /usr/src/emacs/lisp/apropos.el.gz
(defun apropos-parse-pattern (pattern &optional multiline-p)
"Rewrite a list of words to a regexp matching all permutations.
If PATTERN is a string, that means it is already a regexp.
MULTILINE-P, if non-nil, means produce a regexp that will match
the words even if separated by newlines.
This updates variables `apropos-pattern', `apropos-pattern-quoted',
`apropos-regexp', `apropos-words', and `apropos-all-words-regexp'."
(setq apropos-words nil
apropos-all-words nil)
(if (consp pattern)
;; We don't actually make a regexp matching all permutations.
;; Instead, for e.g. "a b c", we make a regexp matching
;; any combination of two or more words like this:
;; (a|b|c).*(a|b|c) which may give some false matches,
;; but as long as it also gives the right ones, that's ok.
;; (Actually, when MULTILINE-P is non-nil, instead of '.' we
;; use a trick that would find a match even if the words are
;; on different lines.
(let ((words pattern))
(setq apropos-pattern (mapconcat #'identity pattern " ")
apropos-pattern-quoted (regexp-quote apropos-pattern))
(dolist (word words)
(let ((syn apropos-synonyms) (s word) (a word))
(while syn
(if (member word (car syn))
(progn
(setq a (mapconcat #'identity (car syn) "\\|"))
(if (member word (cdr (car syn)))
(setq s a))
(setq syn nil))
(setq syn (cdr syn))))
(setq apropos-words (cons s apropos-words)
apropos-all-words (cons a apropos-all-words))))
(setq apropos-all-words-regexp
(apropos-words-to-regexp apropos-all-words
;; The [^b-a] trick matches any
;; character including a newline.
(if multiline-p "[^b-a]+?" ".+")))
(setq apropos-regexp
(apropos-words-to-regexp apropos-words
(if multiline-p "[^b-a]*?" ".*?"))))
(setq apropos-pattern-quoted (regexp-quote pattern)
apropos-all-words-regexp pattern
apropos-pattern pattern
apropos-regexp pattern)))