aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2013-01-09 21:45:31 -0500
committerStefan Monnier2013-01-09 21:45:31 -0500
commitb14abca9476cba2f500b5eda89441d593dd0f12b (patch)
treea09d1217a657e3bac4ddac05e633db9d23bf72f6
parent6466e676b9e7d102e36f043df92351fe235b82f5 (diff)
downloademacs-b14abca9476cba2f500b5eda89441d593dd0f12b.tar.gz
emacs-b14abca9476cba2f500b5eda89441d593dd0f12b.zip
* 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.
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/emacs-lisp/crm.el59
3 files changed, 40 insertions, 30 deletions
diff --git a/etc/NEWS b/etc/NEWS
index 29e0d5a9fe5..52429a3e21d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -66,6 +66,9 @@ bound to <f11> and M-<f10>, respectively.
66 66
67* Changes in Specialized Modes and Packages in Emacs 24.4 67* Changes in Specialized Modes and Packages in Emacs 24.4
68 68
69** completing-read-multiple's separator can now be a regexp.
70The default separator is changed to allow surrounding spaces around the comma.
71
69** Battery 72** Battery
70 73
71*** Battery information via the BSD `apm' utility is now supported. 74*** Battery information via the BSD `apm' utility is now supported.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3ccb944a2f4..7c3443a916c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12013-01-10 Roland Winkler <winkler@gnu.org>
2
3 * emacs-lisp/crm.el: Allow any regexp for separators.
4 (crm-default-separator): All spaces around the default comma separator.
5 (crm--completion-command): New macro.
6 (crm-completion-help, crm-complete, crm-complete-word): Use it.
7 (crm-complete-and-exit): Handle non-single-char separators.
8
12013-01-09 Elias Pipping <pipping@lavabit.com> 92013-01-09 Elias Pipping <pipping@lavabit.com>
2 10
3 * doc-view.el: Add support for DjVu (bug#13164). 11 * doc-view.el: Add support for DjVu (bug#13164).
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el
index 5607c9b0698..f88cb0ef9bb 100644
--- a/lisp/emacs-lisp/crm.el
+++ b/lisp/emacs-lisp/crm.el
@@ -30,12 +30,12 @@
30;; a single prompt, optionally using completion. 30;; a single prompt, optionally using completion.
31 31
32;; Multiple strings are specified by separating each of the strings 32;; Multiple strings are specified by separating each of the strings
33;; with a prespecified separator character. For example, if the 33;; with a prespecified separator regexp. For example, if the
34;; separator character is a comma, the strings 'alice', 'bob', and 34;; separator regexp is ",", the strings 'alice', 'bob', and
35;; 'eve' would be specified as 'alice,bob,eve'. 35;; 'eve' would be specified as 'alice,bob,eve'.
36 36
37;; The default value for the separator character is the value of 37;; The default value for the separator regexp is the value of
38;; `crm-default-separator' (comma). The separator character may be 38;; `crm-default-separator' (comma). The separator regexp may be
39;; changed by modifying the value of `crm-separator'. 39;; changed by modifying the value of `crm-separator'.
40 40
41;; Contiguous strings of non-separator-characters are referred to as 41;; Contiguous strings of non-separator-characters are referred to as
@@ -96,14 +96,14 @@
96;; first revamped version 96;; first revamped version
97 97
98;;; Code: 98;;; Code:
99(defconst crm-default-separator "," 99(defconst crm-default-separator "[ \t]*,[ \t]*"
100 "Default separator for `completing-read-multiple'.") 100 "Default separator regexp for `completing-read-multiple'.")
101 101
102(defvar crm-separator crm-default-separator 102(defvar crm-separator crm-default-separator
103 "Separator used for separating strings in `completing-read-multiple'. 103 "Separator regexp used for separating strings in `completing-read-multiple'.
104It should be a single character string that doesn't appear in the list of 104It should be a regexp that does not match the list of completion candidates.
105completion candidates. Modify this value to make `completing-read-multiple' 105Modify this value to make `completing-read-multiple' use a separator other
106use a separator other than `crm-default-separator'.") 106than `crm-default-separator'.")
107 107
108(defvar crm-local-completion-map 108(defvar crm-local-completion-map
109 (let ((map (make-sparse-keymap))) 109 (let ((map (make-sparse-keymap)))
@@ -173,13 +173,17 @@ Place an overlay on the element, with a `field' property, and return it."
173 (overlay-put ol 'field (make-symbol "crm")) 173 (overlay-put ol 'field (make-symbol "crm"))
174 ol)) 174 ol))
175 175
176(defmacro crm--completion-command (command)
177 "Make COMMAND a completion command for `completing-read-multiple'."
178 `(let ((ol (crm--select-current-element)))
179 (unwind-protect
180 ,command
181 (delete-overlay ol))))
182
176(defun crm-completion-help () 183(defun crm-completion-help ()
177 "Display a list of possible completions of the current minibuffer element." 184 "Display a list of possible completions of the current minibuffer element."
178 (interactive) 185 (interactive)
179 (let ((ol (crm--select-current-element))) 186 (crm--completion-command (minibuffer-completion-help))
180 (unwind-protect
181 (minibuffer-completion-help)
182 (delete-overlay ol)))
183 nil) 187 nil)
184 188
185(defun crm-complete () 189(defun crm-complete ()
@@ -188,19 +192,13 @@ If no characters can be completed, display a list of possible completions.
188 192
189Return t if the current element is now a valid match; otherwise return nil." 193Return t if the current element is now a valid match; otherwise return nil."
190 (interactive) 194 (interactive)
191 (let ((ol (crm--select-current-element))) 195 (crm--completion-command (minibuffer-complete)))
192 (unwind-protect
193 (minibuffer-complete)
194 (delete-overlay ol))))
195 196
196(defun crm-complete-word () 197(defun crm-complete-word ()
197 "Complete the current element at most a single word. 198 "Complete the current element at most a single word.
198Like `minibuffer-complete-word' but for `completing-read-multiple'." 199Like `minibuffer-complete-word' but for `completing-read-multiple'."
199 (interactive) 200 (interactive)
200 (let ((ol (crm--select-current-element))) 201 (crm--completion-command (minibuffer-complete-word)))
201 (unwind-protect
202 (minibuffer-complete-word)
203 (delete-overlay ol))))
204 202
205(defun crm-complete-and-exit () 203(defun crm-complete-and-exit ()
206 "If all of the minibuffer elements are valid completions then exit. 204 "If all of the minibuffer elements are valid completions then exit.
@@ -222,9 +220,10 @@ This function is modeled after `minibuffer-complete-and-exit'."
222 (setq doexit nil)) 220 (setq doexit nil))
223 (goto-char (overlay-end ol)) 221 (goto-char (overlay-end ol))
224 (delete-overlay ol)) 222 (delete-overlay ol))
225 (not (eobp)))) 223 (not (eobp)))
224 (looking-at crm-separator))
226 ;; Skip to the next element. 225 ;; Skip to the next element.
227 (forward-char 1)) 226 (goto-char (match-end 0)))
228 (if doexit (exit-minibuffer)))) 227 (if doexit (exit-minibuffer))))
229 228
230(defun crm--choose-completion-string (choice buffer base-position 229(defun crm--choose-completion-string (choice buffer base-position
@@ -248,12 +247,12 @@ By using this functionality, a user may specify multiple strings at a
248single prompt, optionally using completion. 247single prompt, optionally using completion.
249 248
250Multiple strings are specified by separating each of the strings with 249Multiple strings are specified by separating each of the strings with
251a prespecified separator character. For example, if the separator 250a prespecified separator regexp. For example, if the separator
252character is a comma, the strings 'alice', 'bob', and 'eve' would be 251regexp is \",\", the strings 'alice', 'bob', and 'eve' would be
253specified as 'alice,bob,eve'. 252specified as 'alice,bob,eve'.
254 253
255The default value for the separator character is the value of 254The default value for the separator regexp is the value of
256`crm-default-separator' (comma). The separator character may be 255`crm-default-separator' (comma). The separator regexp may be
257changed by modifying the value of `crm-separator'. 256changed by modifying the value of `crm-separator'.
258 257
259Contiguous strings of non-separator-characters are referred to as 258Contiguous strings of non-separator-characters are referred to as
@@ -282,8 +281,8 @@ INHERIT-INPUT-METHOD."
282 (map (if require-match 281 (map (if require-match
283 crm-local-must-match-map 282 crm-local-must-match-map
284 crm-local-completion-map)) 283 crm-local-completion-map))
285 ;; If the user enters empty input, read-from-minibuffer returns 284 ;; If the user enters empty input, `read-from-minibuffer'
286 ;; the empty string, not DEF. 285 ;; returns the empty string, not DEF.
287 (input (read-from-minibuffer 286 (input (read-from-minibuffer
288 prompt initial-input map 287 prompt initial-input map
289 nil hist def inherit-input-method))) 288 nil hist def inherit-input-method)))