all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] regexp-opt support for \_< and \_>
@ 2009-05-26 22:18 Daniel Colascione
  0 siblings, 0 replies; only message in thread
From: Daniel Colascione @ 2009-05-26 22:18 UTC (permalink / raw)
  To: emacs-devel

Trivial patch to allow regexp-opt to wrap words in \_< and \_> instead of \< and \>. Also document the behavior of regexp-opt when PAREN is a string.

Index: regexp-opt.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/emacs-lisp/regexp-opt.el,v
retrieving revision 1.42
diff -u -r1.42 regexp-opt.el
--- regexp-opt.el	5 Jan 2009 03:21:08 -0000	1.42
+++ regexp-opt.el	26 May 2009 22:17:43 -0000
@@ -95,20 +95,28 @@
  (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 \\>."
+If PAREN is a string, use that string instead of the opening
+\\=(. Note that because a closing parenthesis is still added to
+the generated regular expression, PAREN should contain an open
+parenthesis.
+
+If PAREN is `words', then the resulting regexp is additionally
+surrounded by \\=\\< and \\>. If PAREN is `symbols', then the
+resulting regexp is additionally surrounded by \\=\\_< and \\_>."
   (save-match-data
     ;; Recurse on the sorted list.
     (let* ((max-lisp-eval-depth 10000)
 	   (max-specpdl-size 10000)
 	   (completion-ignore-case nil)
 	   (completion-regexp-list nil)
-	   (words (eq paren 'words))
-	   (open (cond ((stringp paren) paren) (paren "\\(")))
+           (open (cond ((stringp paren) paren) (paren "\\(")))
 	   (sorted-strings (delete-dups
 			    (sort (copy-sequence strings) 'string-lessp)))
 	   (re (regexp-opt-group sorted-strings (or open t) (not open))))
-      (if words (concat "\\<" re "\\>") re))))
+      (cond ((eq paren 'words) (concat "\\<" re "\\>"))
+            ((eq paren 'symbols) (concat "\\_<" re "\\_>"))
+            (t re)))))
+
 
 ;;;###autoload
 (defun regexp-opt-depth (regexp)




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-26 22:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-26 22:18 [PATCH] regexp-opt support for \_< and \_> Daniel Colascione

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.