emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r111466: * lisp/emacs-lisp/crm.el: Al


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r111466: * lisp/emacs-lisp/crm.el: Allow any regexp for separators.
Date: Wed, 09 Jan 2013 21:45:31 -0500
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111466
author: Roland Winkler <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Wed 2013-01-09 21:45:31 -0500
message:
  * lisp/emacs-lisp/crm.el: Allow any regexp for separators.
  (crm-default-separator): All spaces around the default comma separator.
  (crm--completion-command): New macro.
  (crm-completion-help, crm-complete, crm-complete-word): Use it.
  (crm-complete-and-exit): Handle non-single-char separators.
modified:
  etc/NEWS
  lisp/ChangeLog
  lisp/emacs-lisp/crm.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2013-01-08 23:50:40 +0000
+++ b/etc/NEWS  2013-01-10 02:45:31 +0000
@@ -66,6 +66,9 @@
 
 * Changes in Specialized Modes and Packages in Emacs 24.4
 
+** completing-read-multiple's separator can now be a regexp.
+The default separator is changed to allow surrounding spaces around the comma.
+
 ** Battery
 
 *** Battery information via the BSD `apm' utility is now supported.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-01-09 21:24:42 +0000
+++ b/lisp/ChangeLog    2013-01-10 02:45:31 +0000
@@ -1,3 +1,11 @@
+2013-01-10  Roland Winkler  <address@hidden>
+
+       * emacs-lisp/crm.el: Allow any regexp for separators.
+       (crm-default-separator): All spaces around the default comma separator.
+       (crm--completion-command): New macro.
+       (crm-completion-help, crm-complete, crm-complete-word): Use it.
+       (crm-complete-and-exit): Handle non-single-char separators.
+
 2013-01-09  Elias Pipping  <address@hidden>
 
        * doc-view.el: Add support for DjVu (bug#13164).

=== modified file 'lisp/emacs-lisp/crm.el'
--- a/lisp/emacs-lisp/crm.el    2013-01-01 09:11:05 +0000
+++ b/lisp/emacs-lisp/crm.el    2013-01-10 02:45:31 +0000
@@ -30,12 +30,12 @@
 ;; a single prompt, optionally using completion.
 
 ;; Multiple strings are specified by separating each of the strings
-;; with a prespecified separator character.  For example, if the
-;; separator character is a comma, the strings 'alice', 'bob', and
+;; with a prespecified separator regexp.  For example, if the
+;; separator regexp is ",", the strings 'alice', 'bob', and
 ;; 'eve' would be specified as 'alice,bob,eve'.
 
-;; The default value for the separator character is the value of
-;; `crm-default-separator' (comma).  The separator character may be
+;; The default value for the separator regexp is the value of
+;; `crm-default-separator' (comma).  The separator regexp may be
 ;; changed by modifying the value of `crm-separator'.
 
 ;; Contiguous strings of non-separator-characters are referred to as
@@ -96,14 +96,14 @@
 ;;   first revamped version
 
 ;;; Code:
-(defconst crm-default-separator ","
-  "Default separator for `completing-read-multiple'.")
+(defconst crm-default-separator "[ \t]*,[ \t]*"
+  "Default separator regexp for `completing-read-multiple'.")
 
 (defvar crm-separator crm-default-separator
-  "Separator used for separating strings in `completing-read-multiple'.
-It should be a single character string that doesn't appear in the list of
-completion candidates.  Modify this value to make `completing-read-multiple'
-use a separator other than `crm-default-separator'.")
+  "Separator regexp used for separating strings in `completing-read-multiple'.
+It should be a regexp that does not match the list of completion candidates.
+Modify this value to make `completing-read-multiple' use a separator other
+than `crm-default-separator'.")
 
 (defvar crm-local-completion-map
   (let ((map (make-sparse-keymap)))
@@ -173,13 +173,17 @@
     (overlay-put ol 'field (make-symbol "crm"))
     ol))
 
+(defmacro crm--completion-command (command)
+  "Make COMMAND a completion command for `completing-read-multiple'."
+  `(let ((ol (crm--select-current-element)))
+     (unwind-protect
+         ,command
+       (delete-overlay ol))))
+
 (defun crm-completion-help ()
   "Display a list of possible completions of the current minibuffer element."
   (interactive)
-  (let ((ol (crm--select-current-element)))
-    (unwind-protect
-        (minibuffer-completion-help)
-      (delete-overlay ol)))
+  (crm--completion-command (minibuffer-completion-help))
   nil)
 
 (defun crm-complete ()
@@ -188,19 +192,13 @@
 
 Return t if the current element is now a valid match; otherwise return nil."
   (interactive)
-  (let ((ol (crm--select-current-element)))
-    (unwind-protect
-        (minibuffer-complete)
-      (delete-overlay ol))))
+  (crm--completion-command (minibuffer-complete)))
 
 (defun crm-complete-word ()
   "Complete the current element at most a single word.
 Like `minibuffer-complete-word' but for `completing-read-multiple'."
   (interactive)
-  (let ((ol (crm--select-current-element)))
-    (unwind-protect
-        (minibuffer-complete-word)
-      (delete-overlay ol))))
+  (crm--completion-command (minibuffer-complete-word)))
 
 (defun crm-complete-and-exit ()
   "If all of the minibuffer elements are valid completions then exit.
@@ -222,9 +220,10 @@
                      (setq doexit nil))
                  (goto-char (overlay-end ol))
                  (delete-overlay ol))
-               (not (eobp))))
+               (not (eobp)))
+             (looking-at crm-separator))
       ;; Skip to the next element.
-      (forward-char 1))
+      (goto-char (match-end 0)))
     (if doexit (exit-minibuffer))))
 
 (defun crm--choose-completion-string (choice buffer base-position
@@ -248,12 +247,12 @@
 single prompt, optionally using completion.
 
 Multiple strings are specified by separating each of the strings with
-a prespecified separator character.  For example, if the separator
-character is a comma, the strings 'alice', 'bob', and 'eve' would be
+a prespecified separator regexp.  For example, if the separator
+regexp is \",\", the strings 'alice', 'bob', and 'eve' would be
 specified as 'alice,bob,eve'.
 
-The default value for the separator character is the value of
-`crm-default-separator' (comma).  The separator character may be
+The default value for the separator regexp is the value of
+`crm-default-separator' (comma).  The separator regexp may be
 changed by modifying the value of `crm-separator'.
 
 Contiguous strings of non-separator-characters are referred to as
@@ -282,8 +281,8 @@
               (map (if require-match
                        crm-local-must-match-map
                      crm-local-completion-map))
-              ;; If the user enters empty input, read-from-minibuffer returns
-              ;; the empty string, not DEF.
+              ;; If the user enters empty input, `read-from-minibuffer'
+              ;; returns the empty string, not DEF.
               (input (read-from-minibuffer
                       prompt initial-input map
                       nil hist def inherit-input-method)))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]