diff options
| author | Miles Bader | 2010-10-07 16:24:21 +0900 |
|---|---|---|
| committer | Miles Bader | 2010-10-07 16:24:21 +0900 |
| commit | 07ff7702e086ca4eb02aadf438c97a9c87c3389d (patch) | |
| tree | cbd1666f876739d276550641ef3aaaaf4e5d95db | |
| parent | 814cc274efc3002fa80122a3f5d55ed7493656c3 (diff) | |
| download | emacs-07ff7702e086ca4eb02aadf438c97a9c87c3389d.tar.gz emacs-07ff7702e086ca4eb02aadf438c97a9c87c3389d.zip | |
(regexp-opt): Add `symbols' mode.
| -rw-r--r-- | doc/lispref/searching.texi | 6 | ||||
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/emacs-lisp/regexp-opt.el | 11 |
3 files changed, 17 insertions, 4 deletions
diff --git a/doc/lispref/searching.texi b/doc/lispref/searching.texi index b4b4c23b1ed..6cc7d451a6e 100644 --- a/doc/lispref/searching.texi +++ b/doc/lispref/searching.texi | |||
| @@ -918,7 +918,11 @@ for Font Lock mode. | |||
| 918 | If the optional argument @var{paren} is non-@code{nil}, then the | 918 | If the optional argument @var{paren} is non-@code{nil}, then the |
| 919 | returned regular expression is always enclosed by at least one | 919 | returned regular expression is always enclosed by at least one |
| 920 | parentheses-grouping construct. If @var{paren} is @code{words}, then | 920 | parentheses-grouping construct. If @var{paren} is @code{words}, then |
| 921 | that construct is additionally surrounded by @samp{\<} and @samp{\>}. | 921 | that construct is additionally surrounded by @samp{\<} and @samp{\>}; |
| 922 | alternatively, if @var{paren} is @code{symbols}, then that construct | ||
| 923 | is additionally surrounded by @samp{\_<} and @samp{\_>} | ||
| 924 | (@code{symbols} is often appropriate when matching | ||
| 925 | programming-language keywords and the like). | ||
| 922 | 926 | ||
| 923 | This simplified definition of @code{regexp-opt} produces a | 927 | This simplified definition of @code{regexp-opt} produces a |
| 924 | regular expression which is equivalent to the actual value | 928 | regular expression which is equivalent to the actual value |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c8cc564831f..dc851b93f4e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2010-10-07 Miles Bader <Miles Bader <miles@gnu.org>> | ||
| 2 | |||
| 3 | * emacs-lisp/regexp-opt.el (regexp-opt): Add `symbols' mode. | ||
| 4 | |||
| 1 | 2010-10-07 Glenn Morris <rgm@gnu.org> | 5 | 2010-10-07 Glenn Morris <rgm@gnu.org> |
| 2 | 6 | ||
| 3 | * mail/rmail.el (mail-sendmail-delimit-header, mail-header-end) | 7 | * mail/rmail.el (mail-sendmail-delimit-header, mail-header-end) |
diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index a1494741572..6389b62ea04 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el | |||
| @@ -96,19 +96,24 @@ The returned regexp is typically more efficient than the equivalent regexp: | |||
| 96 | (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close)) | 96 | (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close)) |
| 97 | 97 | ||
| 98 | If PAREN is `words', then the resulting regexp is additionally surrounded | 98 | If PAREN is `words', then the resulting regexp is additionally surrounded |
| 99 | by \\=\\< and \\>." | 99 | by \\=\\< and \\>. |
| 100 | If PAREN is `symbols', then the resulting regexp is additionally surrounded | ||
| 101 | by \\=\\_< and \\_>." | ||
| 100 | (save-match-data | 102 | (save-match-data |
| 101 | ;; Recurse on the sorted list. | 103 | ;; Recurse on the sorted list. |
| 102 | (let* ((max-lisp-eval-depth 10000) | 104 | (let* ((max-lisp-eval-depth 10000) |
| 103 | (max-specpdl-size 10000) | 105 | (max-specpdl-size 10000) |
| 104 | (completion-ignore-case nil) | 106 | (completion-ignore-case nil) |
| 105 | (completion-regexp-list nil) | 107 | (completion-regexp-list nil) |
| 106 | (words (eq paren 'words)) | ||
| 107 | (open (cond ((stringp paren) paren) (paren "\\("))) | 108 | (open (cond ((stringp paren) paren) (paren "\\("))) |
| 108 | (sorted-strings (delete-dups | 109 | (sorted-strings (delete-dups |
| 109 | (sort (copy-sequence strings) 'string-lessp))) | 110 | (sort (copy-sequence strings) 'string-lessp))) |
| 110 | (re (regexp-opt-group sorted-strings (or open t) (not open)))) | 111 | (re (regexp-opt-group sorted-strings (or open t) (not open)))) |
| 111 | (if words (concat "\\<" re "\\>") re)))) | 112 | (cond ((eq paren 'words) |
| 113 | (concat "\\<" re "\\>")) | ||
| 114 | ((eq paren 'symbols) | ||
| 115 | (concat "\\_<" re "\\_>")) | ||
| 116 | (t re))))) | ||
| 112 | 117 | ||
| 113 | ;;;###autoload | 118 | ;;;###autoload |
| 114 | (defun regexp-opt-depth (regexp) | 119 | (defun regexp-opt-depth (regexp) |