Commit b14abca9 authored by Roland Winkler's avatar Roland Winkler Committed by Stefan Monnier
Browse files

* 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.
parent 6466e676
...@@ -66,6 +66,9 @@ bound to <f11> and M-<f10>, respectively. ...@@ -66,6 +66,9 @@ bound to <f11> and M-<f10>, respectively.
* Changes in Specialized Modes and Packages in Emacs 24.4 * 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
*** Battery information via the BSD `apm' utility is now supported. *** Battery information via the BSD `apm' utility is now supported.
......
2013-01-10 Roland Winkler <winkler@gnu.org>
* 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 <pipping@lavabit.com> 2013-01-09 Elias Pipping <pipping@lavabit.com>
* doc-view.el: Add support for DjVu (bug#13164). * doc-view.el: Add support for DjVu (bug#13164).
......
...@@ -30,12 +30,12 @@ ...@@ -30,12 +30,12 @@
;; a single prompt, optionally using completion. ;; a single prompt, optionally using completion.
;; Multiple strings are specified by separating each of the strings ;; Multiple strings are specified by separating each of the strings
;; with a prespecified separator character. For example, if the ;; with a prespecified separator regexp. For example, if the
;; separator character is a comma, the strings 'alice', 'bob', and ;; separator regexp is ",", the strings 'alice', 'bob', and
;; 'eve' would be specified as 'alice,bob,eve'. ;; 'eve' would be specified as 'alice,bob,eve'.
;; The default value for the separator character is the value of ;; The default value for the separator regexp is the value of
;; `crm-default-separator' (comma). The separator character may be ;; `crm-default-separator' (comma). The separator regexp may be
;; changed by modifying the value of `crm-separator'. ;; changed by modifying the value of `crm-separator'.
;; Contiguous strings of non-separator-characters are referred to as ;; Contiguous strings of non-separator-characters are referred to as
...@@ -96,14 +96,14 @@ ...@@ -96,14 +96,14 @@
;; first revamped version ;; first revamped version
;;; Code: ;;; Code:
(defconst crm-default-separator "," (defconst crm-default-separator "[ \t]*,[ \t]*"
"Default separator for `completing-read-multiple'.") "Default separator regexp for `completing-read-multiple'.")
(defvar crm-separator crm-default-separator (defvar crm-separator crm-default-separator
"Separator used for separating strings in `completing-read-multiple'. "Separator regexp used for separating strings in `completing-read-multiple'.
It should be a single character string that doesn't appear in the list of It should be a regexp that does not match the list of completion candidates.
completion candidates. Modify this value to make `completing-read-multiple' Modify this value to make `completing-read-multiple' use a separator other
use a separator other than `crm-default-separator'.") than `crm-default-separator'.")
(defvar crm-local-completion-map (defvar crm-local-completion-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
...@@ -173,13 +173,17 @@ Place an overlay on the element, with a `field' property, and return it." ...@@ -173,13 +173,17 @@ Place an overlay on the element, with a `field' property, and return it."
(overlay-put ol 'field (make-symbol "crm")) (overlay-put ol 'field (make-symbol "crm"))
ol)) 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 () (defun crm-completion-help ()
"Display a list of possible completions of the current minibuffer element." "Display a list of possible completions of the current minibuffer element."
(interactive) (interactive)
(let ((ol (crm--select-current-element))) (crm--completion-command (minibuffer-completion-help))
(unwind-protect
(minibuffer-completion-help)
(delete-overlay ol)))
nil) nil)
(defun crm-complete () (defun crm-complete ()
...@@ -188,19 +192,13 @@ If no characters can be completed, display a list of possible completions. ...@@ -188,19 +192,13 @@ If no characters can be completed, display a list of possible completions.
Return t if the current element is now a valid match; otherwise return nil." Return t if the current element is now a valid match; otherwise return nil."
(interactive) (interactive)
(let ((ol (crm--select-current-element))) (crm--completion-command (minibuffer-complete)))
(unwind-protect
(minibuffer-complete)
(delete-overlay ol))))
(defun crm-complete-word () (defun crm-complete-word ()
"Complete the current element at most a single word. "Complete the current element at most a single word.
Like `minibuffer-complete-word' but for `completing-read-multiple'." Like `minibuffer-complete-word' but for `completing-read-multiple'."
(interactive) (interactive)
(let ((ol (crm--select-current-element))) (crm--completion-command (minibuffer-complete-word)))
(unwind-protect
(minibuffer-complete-word)
(delete-overlay ol))))
(defun crm-complete-and-exit () (defun crm-complete-and-exit ()
"If all of the minibuffer elements are valid completions then exit. "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,9 +220,10 @@ This function is modeled after `minibuffer-complete-and-exit'."
(setq doexit nil)) (setq doexit nil))
(goto-char (overlay-end ol)) (goto-char (overlay-end ol))
(delete-overlay ol)) (delete-overlay ol))
(not (eobp)))) (not (eobp)))
(looking-at crm-separator))
;; Skip to the next element. ;; Skip to the next element.
(forward-char 1)) (goto-char (match-end 0)))
(if doexit (exit-minibuffer)))) (if doexit (exit-minibuffer))))
(defun crm--choose-completion-string (choice buffer base-position (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 ...@@ -248,12 +247,12 @@ By using this functionality, a user may specify multiple strings at a
single prompt, optionally using completion. single prompt, optionally using completion.
Multiple strings are specified by separating each of the strings with Multiple strings are specified by separating each of the strings with
a prespecified separator character. For example, if the separator a prespecified separator regexp. For example, if the separator
character is a comma, the strings 'alice', 'bob', and 'eve' would be regexp is \",\", the strings 'alice', 'bob', and 'eve' would be
specified as 'alice,bob,eve'. specified as 'alice,bob,eve'.
The default value for the separator character is the value of The default value for the separator regexp is the value of
`crm-default-separator' (comma). The separator character may be `crm-default-separator' (comma). The separator regexp may be
changed by modifying the value of `crm-separator'. changed by modifying the value of `crm-separator'.
Contiguous strings of non-separator-characters are referred to as Contiguous strings of non-separator-characters are referred to as
...@@ -282,8 +281,8 @@ INHERIT-INPUT-METHOD." ...@@ -282,8 +281,8 @@ INHERIT-INPUT-METHOD."
(map (if require-match (map (if require-match
crm-local-must-match-map crm-local-must-match-map
crm-local-completion-map)) crm-local-completion-map))
;; If the user enters empty input, read-from-minibuffer returns ;; If the user enters empty input, `read-from-minibuffer'
;; the empty string, not DEF. ;; returns the empty string, not DEF.
(input (read-from-minibuffer (input (read-from-minibuffer
prompt initial-input map prompt initial-input map
nil hist def inherit-input-method))) nil hist def inherit-input-method)))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment