annotate lisp/auctex/multi-prompt.el @ 161:28f395d8dc7a r20-3b7

Import from CVS: tag r20-3b7
author cvs
date Mon, 13 Aug 2007 09:42:26 +0200
parents 4103f0995bd7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
1 ;;; multi-prompt.el --- completing read of multiple strings.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
2
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Per Abrahamsen.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
4
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
6 ;; Keywords: extensions
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
7 ;; Version: 0.2
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
8 ;; Bogus-Bureaucratic-Cruft: How 'bout ESR and the LCD people agreed
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
9 ;; on a common format?
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
10
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
11 ;; LCD Archive Entry:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
12 ;; multi-prompt|Per Abrahamsen|abraham@dina.kvl.dk|
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
13 ;; completing read of multiple strings|
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
14 ;; 1996-08-31|0.1|~/functions/multi-prompt.el.Z|
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
15
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
16 ;; This program is free software; you can redistribute it and/or modify
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
19 ;; any later version.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
20 ;;
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
21 ;; This program is distributed in the hope that it will be useful,
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
24 ;; GNU General Public License for more details.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
25 ;;
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
27 ;; along with this program; if not, write to the Free Software
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
28 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
29
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
30 ;;; Commentary:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
31
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
32 ;; This package is written for use in emacs lisp programs, where the
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
33 ;; user is prompted for a string of the form:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
34 ;;
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
35 ;; FOO,BAR,BAZ
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
36 ;;
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
37 ;; where FOO, BAR, and BAZ are elements of some table. The function
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
38 ;; `multi-prompt' is a replacement `completing-read' that will allow
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
39 ;; the user to enter a string like the above, yet get completion on
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
40 ;; both FOO, BAR, and BAZ.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
41
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
42 ;;; Change Log:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
43 ;;
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
44 ;; Sat Feb 15 17:58:31 MET 1997
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
45 ;; * Version 0.2 released.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
46 ;; Renamed predicate to `mp-predicate'.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
47 ;; Sat Aug 31 18:32:20 MET DST 1996
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
48 ;; * Version 0.1 released.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
49 ;; Fixed `predicate' bug.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
50 ;; Added provide.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
51 ;; Added `multi-prompt-found' variable.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
52 ;; Sat Aug 31 16:29:14 MET DST 1996
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
53 ;; * Created.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
54
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
55 ;;; Code:
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
56
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
57 (provide 'multi-prompt)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
58
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
59 (defvar multi-prompt-found nil
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
60 "List of entries currently added during a `multi-prompt'.")
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
61
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
62 (defun multi-prompt (separator
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
63 unique prompt table
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
64 &optional mp-predicate require-match initial history)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
65 "Completing prompt for a list of strings.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
66 The first argument SEPARATOR should be the string (of length 1) to
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
67 separate the elements in the list. The second argument UNIQUE should
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
68 be non-nil, if each element must be unique. The remaining elements
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
69 are the arguments to `completing-read'. See that."
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
70 (let ((old-map (if require-match
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
71 minibuffer-local-must-match-map
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
72 minibuffer-local-completion-map))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
73 (new-map (make-sparse-keymap)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
74 (if (fboundp 'set-keymap-parent)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
75 ;; `set-keymap-parent' was introduced in Emacs 19.32.
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
76 (set-keymap-parent new-map old-map)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
77 (setq new-map (copy-keymap old-map)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
78 (define-key new-map separator (if require-match
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
79 'multi-prompt-next-must-match
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
80 'multi-prompt-next))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
81 (define-key new-map "\C-?" 'multi-prompt-delete)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
82 (let* ((minibuffer-local-completion-map new-map)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
83 (minibuffer-local-must-match-map new-map)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
84 (multi-prompt-found nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
85 (done nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
86 (filter (cond (unique
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
87 (lambda (x)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
88 (and (not (member (car x) multi-prompt-found))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
89 (or (null mp-predicate)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
90 (funcall mp-predicate x)))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
91 (mp-predicate)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
92 (answer (catch 'multi-prompt-exit
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
93 (while t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
94 (let ((extra (catch 'multi-prompt-next
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
95 (throw 'multi-prompt-exit
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
96 (completing-read prompt
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
97 table
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
98 filter
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
99 require-match
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
100 initial
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
101 history)))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
102 (cond ((eq extra 'back)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
103 (when multi-prompt-found
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
104 (setq prompt (substring
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
105 prompt 0
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
106 (- 0 (length separator)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
107 (length
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
108 (car multi-prompt-found))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
109 initial (car multi-prompt-found))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
110 (setq multi-prompt-found
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
111 (cdr multi-prompt-found))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
112 (t
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
113 (setq prompt (concat prompt extra separator)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
114 initial nil)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
115 (setq multi-prompt-found
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
116 (cons extra multi-prompt-found)))))))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
117 (if answer
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
118 (nreverse (cons answer multi-prompt-found))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
119 multi-prompt-found))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
120
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
121 (defun multi-prompt-delete ()
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
122 (interactive)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
123 (if (bobp)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
124 (throw 'multi-prompt-next 'back)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
125 (call-interactively 'backward-delete-char)))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
126
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
127 (defun multi-prompt-next ()
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
128 (interactive)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
129 (throw 'multi-prompt-next
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
130 (buffer-substring-no-properties (point-min) (point-max))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
131
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
132 (defun multi-prompt-next-must-match ()
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
133 (interactive)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
134 (if (call-interactively 'minibuffer-complete)
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
135 (throw 'multi-prompt-next
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
136 (buffer-substring-no-properties (point-min) (point-max)))))
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
137
4103f0995bd7 Import from CVS: tag r19-15b95
cvs
parents:
diff changeset
138 ;;; multi-prompt.el ends here