ert-x trivia
[bpt/emacs.git] / lisp / emacs-lisp / crm.el
index b24c2d9..87c9b28 100644 (file)
@@ -1,17 +1,16 @@
 ;;; crm.el --- read multiple strings with completion
 
-;; Copyright (C) 1985, 1986, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-;;   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1993-2012 Free Software Foundation, Inc.
 
 ;; Author: Sen Nagata <sen@eccosys.com>
 ;; Keywords: completion, minibuffer, multiple elements
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -146,7 +143,7 @@ nil if none.
 
 The value of FLAG is used to specify the type of completion operation.
 A value of nil specifies `try-completion'.  A value of t specifies
-`all-completions'.  A value of lambda specifes a test for an exact match.
+`all-completions'.  A value of lambda specifies a test for an exact match.
 
 For more information on STRING, PREDICATE, and FLAG, see the Elisp
 Reference sections on 'Programmed Completion' and 'Basic Completion
@@ -230,6 +227,17 @@ This function is modeled after `minibuffer-complete-and-exit'."
       (forward-char 1))
     (if doexit (exit-minibuffer))))
 
+(defun crm--choose-completion-string (choice buffer base-position
+                                             &rest ignored)
+  "Completion string chooser for `completing-read-multiple'.
+This is called from `choose-completion-string-functions'.
+It replaces the string that is currently being completed, without
+exiting the minibuffer."
+  (let ((completion-no-auto-exit t)
+        (choose-completion-string-functions nil))
+    (choose-completion-string choice buffer base-position)
+    t))
+
 ;; superemulates behavior of completing_read in src/minibuf.c
 ;;;###autoload
 (defun completing-read-multiple
@@ -261,22 +269,28 @@ The return value of this function is a list of the read strings.
 See the documentation for `completing-read' for details on the arguments:
 PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HIST, DEF, and
 INHERIT-INPUT-METHOD."
-  (let* ((minibuffer-completion-table #'crm--collection-fn)
-        (minibuffer-completion-predicate predicate)
-        ;; see completing_read in src/minibuf.c
-        (minibuffer-completion-confirm
-         (unless (eq require-match t) require-match))
-        (crm-completion-table table)
-        (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.
-        (input (read-from-minibuffer
-                prompt initial-input map
-                nil hist def inherit-input-method)))
-    (and def (string-equal input "") (setq input def))
-    (split-string input crm-separator)))
+  (unwind-protect
+      (progn
+       (add-hook 'choose-completion-string-functions
+                 'crm--choose-completion-string)
+       (let* ((minibuffer-completion-table #'crm--collection-fn)
+              (minibuffer-completion-predicate predicate)
+              ;; see completing_read in src/minibuf.c
+              (minibuffer-completion-confirm
+               (unless (eq require-match t) require-match))
+              (crm-completion-table table)
+              (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.
+              (input (read-from-minibuffer
+                      prompt initial-input map
+                      nil hist def inherit-input-method)))
+         (and def (string-equal input "") (setq input def))
+         (split-string input crm-separator)))
+    (remove-hook 'choose-completion-string-functions
+                'crm--choose-completion-string)))
 
 (define-obsolete-function-alias 'crm-minibuffer-complete 'crm-complete "23.1")
 (define-obsolete-function-alias
@@ -306,5 +320,4 @@ INHERIT-INPUT-METHOD."
 
 (provide 'crm)
 
-;; arch-tag: db1911d9-86c6-4a42-b32a-4910701b15a6
 ;;; crm.el ends here