unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Daniel Colascione <danc@merrillpress.com>
To: emacs-devel@gnu.org
Subject: [PATCH] regexp-opt support for \_< and \_>
Date: Tue, 26 May 2009 18:18:36 -0400	[thread overview]
Message-ID: <200905261818.37187.danc@merrillpress.com> (raw)

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)




                 reply	other threads:[~2009-05-26 22:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200905261818.37187.danc@merrillpress.com \
    --to=danc@merrillpress.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).