aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-03-16 00:44:02 +0000
committerChong Yidong2009-03-16 00:44:02 +0000
commitabb3c752e2bc19405956aaab5ce842ac55d883f8 (patch)
tree376a440b3d49c6cd0e65bd3ca43b7a4544803017
parent112b8d1773fca21bdcac92b3b03c4af80d6257f7 (diff)
downloademacs-abb3c752e2bc19405956aaab5ce842ac55d883f8.tar.gz
emacs-abb3c752e2bc19405956aaab5ce842ac55d883f8.zip
(crm--choose-completion-string): New function.
(completing-read-multiple): Set and restore choose-completion-string-functions (Bug#1080).
-rw-r--r--lisp/emacs-lisp/crm.el54
1 files changed, 38 insertions, 16 deletions
diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el
index cedfb1504b1..12d92bc0a6d 100644
--- a/lisp/emacs-lisp/crm.el
+++ b/lisp/emacs-lisp/crm.el
@@ -228,6 +228,22 @@ This function is modeled after `minibuffer-complete-and-exit'."
228 (forward-char 1)) 228 (forward-char 1))
229 (if doexit (exit-minibuffer)))) 229 (if doexit (exit-minibuffer))))
230 230
231(defun crm--choose-completion-string (choice buffer mini-p base-size)
232 "Completion string chooser for `completing-read-multiple'.
233This is called from `choose-completion-string-functions'.
234It replaces the string that is currently being completed, without
235exiting the minibuffer."
236 (let ((ol (crm--select-current-element)))
237 (if base-size
238 (delete-region (+ base-size (field-beginning)) (point))
239 (choose-completion-delete-max-match choice))
240 (insert choice)
241 (remove-text-properties (- (point) (length choice)) (point)
242 '(mouse-face nil))
243 ;; Update point in the window that BUFFER is showing in.
244 (let ((window (get-buffer-window buffer t)))
245 (set-window-point window (point)))))
246
231;; superemulates behavior of completing_read in src/minibuf.c 247;; superemulates behavior of completing_read in src/minibuf.c
232;;;###autoload 248;;;###autoload
233(defun completing-read-multiple 249(defun completing-read-multiple
@@ -259,22 +275,28 @@ The return value of this function is a list of the read strings.
259See the documentation for `completing-read' for details on the arguments: 275See the documentation for `completing-read' for details on the arguments:
260PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF, and 276PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF, and
261INHERIT-INPUT-METHOD." 277INHERIT-INPUT-METHOD."
262 (let* ((minibuffer-completion-table #'crm--collection-fn) 278 (unwind-protect
263 (minibuffer-completion-predicate predicate) 279 (progn
264 ;; see completing_read in src/minibuf.c 280 (add-hook 'choose-completion-string-functions
265 (minibuffer-completion-confirm 281 'crm--choose-completion-string)
266 (unless (eq require-match t) require-match)) 282 (let* ((minibuffer-completion-table #'crm--collection-fn)
267 (crm-completion-table table) 283 (minibuffer-completion-predicate predicate)
268 (map (if require-match 284 ;; see completing_read in src/minibuf.c
269 crm-local-must-match-map 285 (minibuffer-completion-confirm
270 crm-local-completion-map)) 286 (unless (eq require-match t) require-match))
271 ;; If the user enters empty input, read-from-minibuffer returns 287 (crm-completion-table table)
272 ;; the empty string, not DEF. 288 (map (if require-match
273 (input (read-from-minibuffer 289 crm-local-must-match-map
274 prompt initial-input map 290 crm-local-completion-map))
275 nil hist def inherit-input-method))) 291 ;; If the user enters empty input, read-from-minibuffer returns
276 (and def (string-equal input "") (setq input def)) 292 ;; the empty string, not DEF.
277 (split-string input crm-separator))) 293 (input (read-from-minibuffer
294 prompt initial-input map
295 nil hist def inherit-input-method)))
296 (and def (string-equal input "") (setq input def))
297 (split-string input crm-separator)))
298 (remove-hook 'choose-completion-string-functions
299 'crm--choose-completion-string)))
278 300
279(define-obsolete-function-alias 'crm-minibuffer-complete 'crm-complete "23.1") 301(define-obsolete-function-alias 'crm-minibuffer-complete 'crm-complete "23.1")
280(define-obsolete-function-alias 302(define-obsolete-function-alias