1 ;;; riece-complete.el --- completion
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: minibuffer, completion
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (eval-when-compile (require 'cl)) ;butlast
29 (require 'riece-compat)
31 (defvar riece-minibuffer-map
32 (let ((map (make-sparse-keymap)))
33 (set-keymap-parent map minibuffer-local-map)
34 (define-key map "?" 'riece-minibuffer-help)
37 (defvar riece-temp-minibuffer-message nil)
39 ;; stolen (and renamed) from XEmacs's minibuf.el.
40 (defun riece-temp-minibuffer-message (message)
41 (let ((end (point-max)))
43 (goto-char (point-max))
46 (let ((inhibit-quit t))
48 (delete-region end (point-max)))))
50 (defun riece-minibuffer-help ()
52 (if riece-temp-minibuffer-message
53 (riece-temp-minibuffer-message riece-temp-minibuffer-message)))
55 ;;; stolen (and renamed) from crm.el.
56 (defvar riece-completing-read-multiple-separator ",")
57 (defvar riece-completing-read-multiple-table nil)
59 (defun riece-completing-read-multiple-1 (string predicate flag)
60 "Function used by `riece-completing-read-multiple'.
61 The value of STRING is the string to be completed.
63 The value of PREDICATE is a function to filter possible matches, or
66 The value of FLAG is used to specify the type of completion operation.
67 A value of nil specifies `try-completion'. A value of t specifies
68 `all-completions'. A value of lambda specifes a test for an exact match.
70 For more information on STRING, PREDICATE, and FLAG, see the Elisp
71 Reference sections on 'Programmed Completion' and 'Basic Completion
73 (let ((except (split-string string riece-completing-read-multiple-separator))
74 (table (copy-sequence riece-completing-read-multiple-table))
76 ;; Remove a partially matched word construct if it exists.
78 (concat riece-completing-read-multiple-separator "$")
80 (setq except (butlast except)))
82 (concat ".*" riece-completing-read-multiple-separator)
84 (setq lead (substring string 0 (match-end 0))
85 string (substring string (match-end 0))))
87 (let ((entry (assoc (car except) table)))
89 (setq table (delq entry table)))
90 (setq except (cdr except))))
93 (setq string (try-completion string table predicate))
95 (concat lead string)))
97 (eq t (try-completion string table predicate))
99 (all-completions string table predicate))))))
101 (defun riece-completing-read-multiple
102 (prompt table &optional predicate require-match initial-input
104 "Execute `completing-read' consequently.
106 See the documentation for `completing-read' for details on the arguments:
107 PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-INPUT, HISTORY, DEFAULT."
109 (format "%s (separated by \"%s\"): "
110 prompt riece-completing-read-multiple-separator))
111 (riece-completing-read-multiple-table table))
114 prompt #'riece-completing-read-multiple-1
115 predicate require-match initial-input history default)
116 riece-completing-read-multiple-separator)))
118 (provide 'riece-complete)
120 ;;; riece-complete.el ends here