70
|
1 ;;; minibuf.el
|
0
|
2 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 ;; Copyright (C) 1995 Tinker Systems
|
|
4 ;; Copyright (C) 1995, 1996 Ben Wing
|
|
5
|
|
6 ;; This file is part of XEmacs.
|
|
7
|
|
8 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
9 ;; under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 ;; General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
70
|
19 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
20 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
21 ;; Boston, MA 02111-1307, USA.
|
0
|
22
|
|
23 ;;; Synched up with: all the minibuffer history stuff is synched with
|
70
|
24 ;;; 19.30. Not sure about the rest.
|
0
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; Written by Richard Mlynarik 2-Oct-92
|
|
29
|
|
30 ;;; Code:
|
|
31
|
|
32 (defvar insert-default-directory t
|
|
33 "*Non-nil means when reading a filename start with default dir in minibuffer."
|
|
34 )
|
|
35
|
|
36 (defvar minibuffer-completion-table nil
|
|
37 "Alist or obarray used for completion in the minibuffer.
|
|
38 This becomes the ALIST argument to `try-completion' and `all-completions'.
|
|
39
|
|
40 The value may alternatively be a function, which is given three arguments:
|
|
41 STRING, the current buffer contents;
|
|
42 PREDICATE, the predicate for filtering possible matches;
|
|
43 CODE, which says what kind of things to do.
|
|
44 CODE can be nil, t or `lambda'.
|
|
45 nil means to return the best completion of STRING, nil if there is none,
|
|
46 or t if it is was already a unique completion.
|
|
47 t means to return a list of all possible completions of STRING.
|
|
48 `lambda' means to return t if STRING is a valid completion as it stands.")
|
|
49
|
|
50 (defvar minibuffer-completion-predicate nil
|
|
51 "Within call to `completing-read', this holds the PREDICATE argument.")
|
|
52
|
|
53 (defvar minibuffer-completion-confirm nil
|
|
54 "Non-nil => demand confirmation of completion before exiting minibuffer.")
|
|
55
|
|
56 (defvar minibuffer-confirm-incomplete nil
|
|
57 "If true, then in contexts where completing-read allows answers which
|
|
58 are not valid completions, an extra RET must be typed to confirm the
|
|
59 response. This is helpful for catching typos, etc.")
|
|
60
|
|
61 (defvar completion-auto-help t
|
|
62 "*Non-nil means automatically provide help for invalid completion input.")
|
|
63
|
|
64 (defvar enable-recursive-minibuffers nil
|
|
65 "*Non-nil means to allow minibuffer commands while in the minibuffer.
|
|
66 More precisely, this variable makes a difference when the minibuffer window
|
|
67 is the selected window. If you are in some other window, minibuffer commands
|
|
68 are allowed even if a minibuffer is active.")
|
|
69
|
|
70 (defvar minibuffer-max-depth 1
|
|
71 ;; See comment in #'minibuffer-max-depth-exceeded
|
|
72 "*Global maximum number of minibuffers allowed;
|
|
73 compare to enable-recursive-minibuffers, which is only consulted when the
|
|
74 minibuffer is reinvoked while it is the selected window.")
|
|
75
|
|
76 ;; Moved to C. The minibuffer prompt must be setup before this is run
|
|
77 ;; and that can only be done from the C side.
|
|
78 ;(defvar minibuffer-setup-hook nil
|
|
79 ; "Normal hook run just after entry to minibuffer.")
|
|
80
|
|
81 (defvar minibuffer-exit-hook nil
|
|
82 "Normal hook run just after exit from minibuffer.")
|
|
83
|
|
84 (defvar minibuffer-help-form nil
|
|
85 "Value that `help-form' takes on inside the minibuffer.")
|
|
86
|
|
87 (defvar minibuffer-local-map
|
|
88 (let ((map (make-sparse-keymap 'minibuffer-local-map)))
|
|
89 map)
|
|
90 "Default keymap to use when reading from the minibuffer.")
|
|
91
|
|
92 (defvar minibuffer-local-completion-map
|
|
93 (let ((map (make-sparse-keymap 'minibuffer-local-completion-map)))
|
|
94 (set-keymap-parents map (list minibuffer-local-map))
|
|
95 map)
|
|
96 "Local keymap for minibuffer input with completion.")
|
|
97
|
|
98 (defvar minibuffer-local-must-match-map
|
|
99 (let ((map (make-sparse-keymap 'minibuffer-must-match-map)))
|
|
100 (set-keymap-parents map (list minibuffer-local-completion-map))
|
|
101 map)
|
|
102 "Local keymap for minibuffer input with completion, for exact match.")
|
|
103
|
|
104 ;; (define-key minibuffer-local-map "\C-g" 'abort-recursive-edit)
|
|
105 (define-key minibuffer-local-map "\C-g" 'minibuffer-keyboard-quit) ;; moved here from pending-del.el
|
|
106 (define-key minibuffer-local-map "\r" 'exit-minibuffer)
|
|
107 (define-key minibuffer-local-map "\n" 'exit-minibuffer)
|
|
108
|
|
109 ;; Historical crock. Unused by anything but user code, if even that
|
|
110 ;(defvar minibuffer-local-ns-map
|
|
111 ; (let ((map (make-sparse-keymap 'minibuffer-local-ns-map)))
|
|
112 ; (set-keymap-parents map (list minibuffer-local-map))
|
|
113 ; map)
|
|
114 ; "Local keymap for the minibuffer when spaces are not allowed.")
|
|
115 ;(define-key minibuffer-local-ns-map [space] 'exit-minibuffer)
|
|
116 ;(define-key minibuffer-local-ns-map [tab] 'exit-minibuffer)
|
|
117 ;(define-key minibuffer-local-ns-map [?\?] 'self-insert-and-exit)
|
|
118
|
|
119 (define-key minibuffer-local-completion-map "\t" 'minibuffer-complete)
|
|
120 (define-key minibuffer-local-completion-map " " 'minibuffer-complete-word)
|
|
121 (define-key minibuffer-local-completion-map "?" 'minibuffer-completion-help)
|
|
122 (define-key minibuffer-local-must-match-map "\r" 'minibuffer-complete-and-exit)
|
|
123 (define-key minibuffer-local-must-match-map "\n" 'minibuffer-complete-and-exit)
|
|
124
|
|
125 (define-key minibuffer-local-map "\M-n" 'next-history-element)
|
|
126 (define-key minibuffer-local-map "\M-p" 'previous-history-element)
|
|
127 (define-key minibuffer-local-map '[next] "\M-n")
|
|
128 (define-key minibuffer-local-map '[prior] "\M-p")
|
|
129 (define-key minibuffer-local-map "\M-r" 'previous-matching-history-element)
|
|
130 (define-key minibuffer-local-map "\M-s" 'next-matching-history-element)
|
|
131 (define-key minibuffer-local-must-match-map [next]
|
|
132 'next-complete-history-element)
|
|
133 (define-key minibuffer-local-must-match-map [prior]
|
|
134 'previous-complete-history-element)
|
|
135
|
|
136 ;; This is an experiment--make up and down arrows do history.
|
|
137 (define-key minibuffer-local-map [up] 'previous-history-element)
|
|
138 (define-key minibuffer-local-map [down] 'next-history-element)
|
|
139 (define-key minibuffer-local-completion-map [up] 'previous-history-element)
|
|
140 (define-key minibuffer-local-completion-map [down] 'next-history-element)
|
|
141 (define-key minibuffer-local-must-match-map [up] 'previous-history-element)
|
|
142 (define-key minibuffer-local-must-match-map [down] 'next-history-element)
|
|
143
|
|
144 (defvar read-expression-map (let ((map (make-sparse-keymap
|
|
145 'read-expression-map)))
|
|
146 (set-keymap-parents map
|
|
147 (list minibuffer-local-map))
|
|
148 (define-key map "\M-\t" 'lisp-complete-symbol)
|
|
149 map)
|
|
150 "Minibuffer keymap used for reading Lisp expressions.")
|
|
151
|
|
152 (defvar read-shell-command-map
|
|
153 (let ((map (make-sparse-keymap 'read-shell-command-map)))
|
|
154 (set-keymap-parents map (list minibuffer-local-map))
|
|
155 (define-key map "\t" 'comint-dynamic-complete)
|
|
156 (define-key map "\M-\t" 'comint-dynamic-complete)
|
|
157 (define-key map "\M-?" 'comint-dynamic-list-completions)
|
|
158 map)
|
|
159 "Minibuffer keymap used by shell-command and related commands.")
|
|
160
|
|
161 (defvar minibuffer-electric-file-name-behavior t
|
|
162 "If non-nil, slash and tilde in certain places cause immediate deletion.
|
|
163 These are the same places where this behavior would occur later on anyway,
|
|
164 in `substitute-in-file-name'.")
|
|
165
|
|
166 (defun minibuffer-electric-slash ()
|
|
167 ;; by Stig@hackvan.com
|
|
168 (interactive)
|
|
169 (and minibuffer-electric-file-name-behavior
|
|
170 (eq ?/ (preceding-char))
|
|
171 (not (eq (point) (1+ (point-min)))) ; permit `//hostname/path/to/file'
|
|
172 (not (eq ?: (char-after (- (point) 2)))) ; permit `http://url/goes/here'
|
|
173 (delete-region (point-min) (point)))
|
|
174 (insert ?/))
|
|
175
|
|
176 (defun minibuffer-electric-tilde ()
|
|
177 (interactive)
|
|
178 (and minibuffer-electric-file-name-behavior
|
|
179 (eq ?/ (preceding-char))
|
|
180 ;; permit URL's with //, for e.g. http://hostname/~user
|
|
181 (not (save-excursion (search-backward "//" nil t)))
|
|
182 (delete-region (point-min) (point)))
|
|
183 (insert ?~))
|
|
184
|
|
185 (defvar read-file-name-map
|
|
186 (let ((map (make-sparse-keymap 'read-file-name-map)))
|
|
187 (set-keymap-parents map (list minibuffer-local-completion-map))
|
|
188 (define-key map "/" 'minibuffer-electric-slash)
|
|
189 (define-key map "~" 'minibuffer-electric-tilde)
|
|
190 map
|
|
191 ))
|
|
192
|
|
193 (defvar read-file-name-must-match-map
|
|
194 (let ((map (make-sparse-keymap 'read-file-name-map)))
|
|
195 (set-keymap-parents map (list minibuffer-local-must-match-map))
|
|
196 (define-key map "/" 'minibuffer-electric-slash)
|
|
197 (define-key map "~" 'minibuffer-electric-tilde)
|
|
198 map
|
|
199 ))
|
|
200
|
|
201 (defun minibuffer-keyboard-quit ()
|
|
202 "Abort recursive edit.
|
|
203 If `zmacs-regions' is true, and the zmacs region is active, then this
|
|
204 key deactivates the region without beeping."
|
|
205 (interactive)
|
|
206 (if (and zmacs-regions (zmacs-deactivate-region))
|
|
207 ;; pseudo-zmacs compatibility: don't beep if this ^G is simply
|
|
208 ;; deactivating the region. If it is inactive, beep.
|
|
209 nil
|
|
210 (abort-recursive-edit)))
|
|
211
|
|
212 ;;;; Guts of minibuffer invocation
|
|
213
|
|
214 ;;#### The only things remaining in C are
|
|
215 ;; "Vminibuf_prompt" and the display junk
|
|
216 ;; "minibuf_prompt_width" and "minibuf_prompt_pix_width"
|
|
217 ;; Also "active_frame", though I suspect I could already
|
|
218 ;; hack that in Lisp if I could make any sense of the
|
|
219 ;; complete mess of frame/frame code in XEmacs.
|
|
220 ;; Vminibuf_prompt could easily be made Lisp-bindable.
|
|
221 ;; I suspect that minibuf_prompt*_width are actually recomputed
|
|
222 ;; by redisplay as needed -- or could be arranged to be so --
|
|
223 ;; and that there could be need for read-minibuffer-internal to
|
|
224 ;; save and restore them.
|
|
225 ;;#### The only other thing which read-from-minibuffer-internal does
|
|
226 ;; which we can't presently do in Lisp is move the frame cursor
|
|
227 ;; to the start of the minibuffer line as it returns. This is
|
|
228 ;; a rather nice touch and should be preserved -- probably by
|
|
229 ;; providing some Lisp-level mechanism (extension to cursor-in-echo-area ?)
|
|
230 ;; to effect it.
|
|
231
|
|
232
|
|
233 ;; Like reset_buffer in FSF's buffer.c
|
|
234 ;; (Except that kill-all-local-variables doesn't nuke 'permanent-local
|
|
235 ;; variables -- we preserve them, reset_buffer doesn't.)
|
|
236 (defun reset-buffer (buffer)
|
|
237 (save-excursion
|
|
238 (set-buffer buffer)
|
|
239 ;(if (fboundp 'unlock-buffer) (unlock-buffer))
|
|
240 (kill-all-local-variables)
|
|
241 (setq buffer-read-only nil)
|
|
242 (erase-buffer)
|
|
243 ;(setq default-directory nil)
|
|
244 (setq buffer-file-name nil)
|
|
245 (setq buffer-file-truename nil)
|
|
246 (set-buffer-modified-p nil)
|
|
247 (setq buffer-backed-up nil)
|
|
248 (setq buffer-auto-save-file-name nil)
|
|
249 (set-buffer-dedicated-frame buffer nil)
|
|
250 buffer))
|
|
251
|
|
252 (defvar minibuffer-history-variable 'minibuffer-history
|
|
253 "History list symbol to add minibuffer values to.
|
|
254 Each minibuffer output is added with
|
|
255 (set minibuffer-history-variable
|
|
256 (cons STRING (symbol-value minibuffer-history-variable)))")
|
|
257 (defvar minibuffer-history-position)
|
|
258
|
|
259 (defvar minibuffer-history-minimum-string-length 3
|
|
260 "If this variable is non-nil, a string will not be added to the
|
|
261 minibuffer history if its length is less than that value.")
|
|
262
|
|
263 (defun read-from-minibuffer (prompt &optional initial-contents
|
|
264 keymap
|
|
265 readp
|
|
266 history
|
|
267 abbrev-table)
|
|
268 "Read a string from the minibuffer, prompting with string PROMPT.
|
|
269 If optional second arg INITIAL-CONTENTS is non-nil, it is a string
|
|
270 to be inserted into the minibuffer before reading input.
|
|
271 If INITIAL-CONTENTS is (STRING . POSITION), the initial input
|
|
272 is STRING, but point is placed POSITION characters into the string.
|
|
273 Third arg KEYMAP is a keymap to use whilst reading;
|
|
274 if omitted or nil, the default is `minibuffer-local-map'.
|
|
275 If fourth arg READ is non-nil, then interpret the result as a lisp object
|
|
276 and return that object:
|
|
277 in other words, do `(car (read-from-string INPUT-STRING))'
|
|
278 Fifth arg HISTORY, if non-nil, specifies a history list
|
|
279 and optionally the initial position in the list.
|
|
280 It can be a symbol, which is the history list variable to use,
|
|
281 or it can be a cons cell (HISTVAR . HISTPOS).
|
|
282 In that case, HISTVAR is the history list variable to use,
|
|
283 and HISTPOS is the initial position (the position in the list
|
|
284 which INITIAL-CONTENTS corresponds to).
|
|
285 If HISTORY is `t', no history will be recorded.
|
|
286 Positions are counted starting from 1 at the beginning of the list.
|
|
287 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table'
|
|
288 in the minibuffer.
|
|
289
|
|
290 See also the variable completion-highlight-first-word-only for control over
|
|
291 completion display."
|
|
292 (if (and (not enable-recursive-minibuffers)
|
|
293 (> (minibuffer-depth) 0)
|
|
294 (eq (selected-window) (minibuffer-window)))
|
|
295 (error "Command attempted to use minibuffer while in minibuffer"))
|
|
296
|
|
297 (if (and minibuffer-max-depth
|
|
298 (> minibuffer-max-depth 0)
|
|
299 (>= (minibuffer-depth) minibuffer-max-depth))
|
|
300 (minibuffer-max-depth-exceeded))
|
|
301
|
|
302 ;; catch this error before the poor user has typed something...
|
|
303 (if history
|
|
304 (if (symbolp history)
|
|
305 (or (boundp history)
|
|
306 (error "History list %S is unbound" history))
|
|
307 (or (boundp (car history))
|
|
308 (error "History list %S is unbound" (car history)))))
|
|
309
|
|
310 (if (noninteractive)
|
|
311 (progn
|
|
312 ;; XEmacs in -batch mode calls minibuffer: print the prompt.
|
|
313 (message "%s" (gettext prompt))
|
|
314 ;;#### force-output
|
|
315
|
|
316 ;;#### Should this even be falling though to the code below?
|
|
317 ;;#### How does this stuff work now, anyway?
|
|
318 ))
|
|
319 (let* ((dir default-directory)
|
|
320 (owindow (selected-window))
|
|
321 (oframe (selected-frame))
|
|
322 (window (minibuffer-window))
|
|
323 (buffer (if (eq (minibuffer-depth) 0)
|
|
324 (window-buffer window)
|
|
325 (get-buffer-create (format " *Minibuf-%d"
|
|
326 (minibuffer-depth)))))
|
|
327 (frame (window-frame window))
|
|
328 (mconfig (if (eq frame (selected-frame))
|
|
329 nil (current-window-configuration frame)))
|
|
330 (oconfig (current-window-configuration))
|
|
331 ;; dynamic scope sucks sucks sucks sucks sucks sucks.
|
|
332 ;; `M-x doctor' makes history a local variable, and thus
|
|
333 ;; our binding above is buffer-local and doesn't apply
|
|
334 ;; once we switch buffers!!!! We demand better scope!
|
|
335 (_history_ history))
|
|
336 (unwind-protect
|
|
337 (progn
|
|
338 (set-buffer buffer)
|
|
339 (reset-buffer buffer)
|
|
340 (setq default-directory dir)
|
|
341 (make-local-variable 'print-escape-newlines)
|
|
342 (setq print-escape-newlines t)
|
|
343 (if (not minibuffer-smart-completion-tracking-behavior)
|
|
344 nil
|
|
345 (make-local-variable 'mode-motion-hook)
|
|
346 (or mode-motion-hook
|
|
347 ;;####disgusting
|
|
348 (setq mode-motion-hook 'minibuffer-mouse-tracker))
|
|
349 (make-local-variable 'mouse-track-click-hook)
|
|
350 (add-hook 'mouse-track-click-hook
|
2
|
351 'minibuffer-smart-maybe-select-highlighted-completion))
|
0
|
352 (set-window-buffer window buffer)
|
|
353 (select-window window)
|
|
354 (set-window-hscroll window 0)
|
|
355 (buffer-enable-undo buffer)
|
|
356 (message nil)
|
|
357 (if initial-contents
|
|
358 (if (consp initial-contents)
|
|
359 (progn
|
|
360 (insert (car initial-contents))
|
|
361 (goto-char (1+ (cdr initial-contents))))
|
|
362 (insert initial-contents)))
|
|
363 (use-local-map (or keymap minibuffer-local-map))
|
|
364 (let ((mouse-grabbed-buffer
|
|
365 (and minibuffer-smart-completion-tracking-behavior
|
|
366 (current-buffer)))
|
|
367 (current-prefix-arg current-prefix-arg)
|
|
368 (help-form minibuffer-help-form)
|
|
369 (minibuffer-history-variable (cond ((not _history_)
|
|
370 'minibuffer-history)
|
|
371 ((consp _history_)
|
|
372 (car _history_))
|
|
373 (t
|
|
374 _history_)))
|
|
375 (minibuffer-history-position (cond ((consp _history_)
|
|
376 (cdr _history_))
|
|
377 (t
|
|
378 0)))
|
|
379 (minibuffer-scroll-window owindow))
|
|
380 (if abbrev-table
|
|
381 (setq local-abbrev-table abbrev-table
|
|
382 abbrev-mode t))
|
|
383 ;; This is now run from read-minibuffer-internal
|
|
384 ;(if minibuffer-setup-hook
|
|
385 ; (run-hooks 'minibuffer-setup-hook))
|
|
386 ;(message nil)
|
|
387 (if (eq 't
|
|
388 (catch 'exit
|
|
389 (if (> (recursion-depth) (minibuffer-depth))
|
|
390 (let ((standard-output t)
|
|
391 (standard-input t))
|
|
392 (read-minibuffer-internal prompt))
|
|
393 (read-minibuffer-internal prompt))))
|
|
394 ;; Translate an "abort" (throw 'exit 't)
|
|
395 ;; into a real quit
|
|
396 (signal 'quit '())
|
|
397 ;; return value
|
|
398 (let* ((val (progn (set-buffer buffer)
|
|
399 (if minibuffer-exit-hook
|
|
400 (run-hooks 'minibuffer-exit-hook))
|
|
401 (buffer-string)))
|
|
402 (err nil))
|
|
403 (if readp
|
|
404 (condition-case e
|
|
405 (let ((v (read-from-string val)))
|
|
406 (if (< (cdr v) (length val))
|
|
407 (save-match-data
|
|
408 (or (string-match "[ \t\n]*\\'" val (cdr v))
|
|
409 (error "Trailing garbage following expression"))))
|
|
410 (setq v (car v))
|
|
411 ;; total total kludge
|
|
412 (if (stringp v) (setq v (list 'quote v)))
|
|
413 (setq val v))
|
70
|
414 (error (setq err e))))
|
0
|
415 ;; Add the value to the appropriate history list unless
|
|
416 ;; it's already the most recent element, or it's only
|
|
417 ;; two characters long.
|
|
418 (if (and (symbolp minibuffer-history-variable)
|
|
419 (boundp minibuffer-history-variable))
|
|
420 (let ((list (symbol-value minibuffer-history-variable)))
|
|
421 (or (eq list t)
|
|
422 (null val)
|
70
|
423 (and list (equal val (car list)))
|
0
|
424 (and (stringp val)
|
|
425 minibuffer-history-minimum-string-length
|
|
426 (< (length val)
|
|
427 minibuffer-history-minimum-string-length))
|
70
|
428 (set minibuffer-history-variable (cons val list)))))
|
0
|
429 (if err (signal (car err) (cdr err)))
|
|
430 val))))
|
|
431 ;; stupid display code requires this for some reason
|
|
432 (set-buffer buffer)
|
|
433 (buffer-disable-undo buffer)
|
|
434 (setq buffer-read-only nil)
|
|
435 (erase-buffer)
|
|
436
|
|
437 ;; restore frame configurations
|
|
438 (if (and mconfig (frame-live-p oframe)
|
|
439 (eq frame (selected-frame)))
|
|
440 ;; if we changed frames (due to surrogate minibuffer),
|
|
441 ;; and we're still on the new frame, go back to the old one.
|
|
442 (select-frame oframe))
|
|
443 (if mconfig (set-window-configuration mconfig))
|
|
444 (set-window-configuration oconfig))))
|
|
445
|
|
446
|
|
447 (defun minibuffer-max-depth-exceeded ()
|
|
448 ;;
|
|
449 ;; This signals an error if an Nth minibuffer is invoked while N-1 are
|
|
450 ;; already active, whether the minibuffer window is selected or not.
|
|
451 ;; Since, under X, it's easy to jump out of the minibuffer (by doing M-x,
|
|
452 ;; getting distracted, and clicking elsewhere) many many novice users have
|
|
453 ;; had the problem of having multiple minibuffers build up, even to the
|
|
454 ;; point of exceeding max-lisp-eval-depth. Since the variable
|
|
455 ;; enable-recursive-minibuffers historically/crockishly is only consulted
|
|
456 ;; when the minibuffer is currently active (like typing M-x M-x) it doesn't
|
|
457 ;; help in this situation.
|
|
458 ;;
|
|
459 ;; This routine also offers to edit .emacs for you to get rid of this
|
|
460 ;; complaint, like `disabled' commands do, since it's likely that non-novice
|
|
461 ;; users will be annoyed by this change, so we give them an easy way to get
|
|
462 ;; rid of it forever.
|
|
463 ;;
|
|
464 (beep t 'minibuffer-limit-exceeded)
|
|
465 (message
|
|
466 "Minibuffer already active: abort it with `^]', enable new one with `n': ")
|
|
467 (let ((char (let ((cursor-in-echo-area t)) ; #### doesn't always work??
|
|
468 (read-char))))
|
|
469 (cond
|
|
470 ((eq char ?n)
|
|
471 (cond
|
|
472 ((y-or-n-p "Enable recursive minibuffers for other sessions too? ")
|
|
473 ;; This is completely disgusting, but it's basically what novice.el
|
|
474 ;; does. This kind of thing should be generalized.
|
|
475 (setq minibuffer-max-depth nil)
|
|
476 (save-excursion
|
|
477 (set-buffer
|
|
478 (find-file-noselect
|
|
479 (substitute-in-file-name "~/.emacs")))
|
|
480 (goto-char (point-min))
|
|
481 (if (re-search-forward
|
|
482 "^(setq minibuffer-max-depth \\([0-9]+\\|'?nil\\|'?()\\))\n"
|
|
483 nil t)
|
|
484 (delete-region (match-beginning 0 ) (match-end 0))
|
|
485 ;; Must have been disabled by default.
|
|
486 (goto-char (point-max)))
|
|
487 (insert"\n(setq minibuffer-max-depth nil)\n")
|
|
488 (save-buffer))
|
|
489 (message "Multiple minibuffers enabled")
|
|
490 (sit-for 1))))
|
|
491 ((eq char ?)
|
|
492 (abort-recursive-edit))
|
|
493 (t
|
|
494 (error "Minibuffer already active")))))
|
|
495
|
|
496
|
|
497 ;;;; Guts of minibuffer completion
|
|
498
|
|
499
|
|
500 ;; Used by minibuffer-do-completion
|
|
501 (defvar last-exact-completion)
|
|
502
|
|
503 (defun temp-minibuffer-message (m)
|
|
504 (let ((savemax (point-max)))
|
|
505 (save-excursion
|
|
506 (goto-char (point-max))
|
|
507 (message nil)
|
|
508 (insert m))
|
|
509 (let ((inhibit-quit t))
|
|
510 (sit-for 2)
|
|
511 (delete-region savemax (point-max))
|
|
512 ;; If the user types a ^G while we're in sit-for, then quit-flag
|
|
513 ;; gets set. In this case, we want that ^G to be interpreted
|
|
514 ;; as a normal character, and act just like typeahead.
|
|
515 (if (and quit-flag (not unread-command-event))
|
|
516 (setq unread-command-event (character-to-event (quit-char))
|
|
517 quit-flag nil)))))
|
|
518
|
|
519
|
|
520 ;; Determines whether buffer-string is an exact completion
|
|
521 (defun exact-minibuffer-completion-p (buffer-string)
|
|
522 (cond ((not minibuffer-completion-table)
|
|
523 ;; Empty alist
|
|
524 nil)
|
|
525 ((vectorp minibuffer-completion-table)
|
|
526 (let ((tem (intern-soft buffer-string
|
|
527 minibuffer-completion-table)))
|
|
528 (if (or tem
|
|
529 (and (string-equal buffer-string "nil")
|
|
530 ;; intern-soft loses for 'nil
|
|
531 (catch 'found
|
|
532 (mapatoms #'(lambda (s)
|
|
533 (if (string-equal
|
|
534 (symbol-name s)
|
|
535 buffer-string)
|
|
536 (throw 'found t)))
|
|
537 minibuffer-completion-table)
|
|
538 nil)))
|
|
539 (if minibuffer-completion-predicate
|
|
540 (funcall minibuffer-completion-predicate
|
|
541 tem)
|
|
542 t)
|
|
543 nil)))
|
|
544 ((and (consp minibuffer-completion-table)
|
|
545 ;;#### Emacs-Lisp truly sucks!
|
|
546 ;; lambda, autoload, etc
|
|
547 (not (symbolp (car minibuffer-completion-table))))
|
|
548 (if (not completion-ignore-case)
|
|
549 (assoc buffer-string minibuffer-completion-table)
|
|
550 (let ((s (upcase buffer-string))
|
|
551 (tail minibuffer-completion-table)
|
|
552 tem)
|
|
553 (while tail
|
|
554 (setq tem (car (car tail)))
|
|
555 (if (or (equal tem buffer-string)
|
|
556 (equal tem s)
|
|
557 (equal (upcase tem) s))
|
|
558 (setq s 'win
|
|
559 tail nil) ;exit
|
|
560 (setq tail (cdr tail))))
|
|
561 (eq s 'win))))
|
|
562 (t
|
|
563 (funcall minibuffer-completion-table
|
|
564 buffer-string
|
|
565 minibuffer-completion-predicate
|
|
566 'lambda)))
|
|
567 )
|
|
568
|
|
569 ;; 0 'none no possible completion
|
|
570 ;; 1 'unique was already an exact and unique completion
|
|
571 ;; 3 'exact was already an exact (but nonunique) completion
|
|
572 ;; NOT USED 'completed-exact-unique completed to an exact and completion
|
|
573 ;; 4 'completed-exact completed to an exact (but nonunique) completion
|
|
574 ;; 5 'completed some completion happened
|
|
575 ;; 6 'uncompleted no completion happened
|
|
576 (defun minibuffer-do-completion-1 (buffer-string completion)
|
|
577 (cond ((not completion)
|
|
578 'none)
|
|
579 ((eq completion t)
|
|
580 ;; exact and unique match
|
|
581 'unique)
|
|
582 (t
|
|
583 ;; It did find a match. Do we match some possibility exactly now?
|
|
584 (let ((completedp (not (string-equal completion buffer-string))))
|
|
585 (if completedp
|
|
586 (progn
|
|
587 ;; Some completion happened
|
|
588 (erase-buffer)
|
|
589 (insert completion)
|
|
590 (setq buffer-string completion)))
|
|
591 (if (exact-minibuffer-completion-p buffer-string)
|
|
592 ;; An exact completion was possible
|
|
593 (if completedp
|
|
594 ;; Since no callers need to know the difference, don't bother
|
|
595 ;; with this (potentially expensive) discrimination.
|
|
596 ;; (if (eq (try-completion completion
|
|
597 ;; minibuffer-completion-table
|
|
598 ;; minibuffer-completion-predicate)
|
|
599 ;; 't)
|
|
600 ;; 'completed-exact-unique
|
|
601 'completed-exact
|
|
602 ;; )
|
|
603 'exact)
|
|
604 ;; Not an exact match
|
|
605 (if completedp
|
|
606 'completed
|
|
607 'uncompleted))))))
|
|
608
|
|
609
|
|
610 (defun minibuffer-do-completion (buffer-string)
|
|
611 (let* ((completion (try-completion buffer-string
|
|
612 minibuffer-completion-table
|
|
613 minibuffer-completion-predicate))
|
|
614 (status (minibuffer-do-completion-1 buffer-string completion))
|
|
615 (last last-exact-completion))
|
|
616 (setq last-exact-completion nil)
|
|
617 (cond ((eq status 'none)
|
|
618 ;; No completions
|
|
619 (ding nil 'no-completion)
|
|
620 (temp-minibuffer-message " [No match]"))
|
|
621 ((eq status 'unique)
|
|
622 )
|
|
623 (t
|
|
624 ;; It did find a match. Do we match some possibility exactly now?
|
|
625 (if (not (string-equal completion buffer-string))
|
|
626 (progn
|
|
627 ;; Some completion happened
|
|
628 (erase-buffer)
|
|
629 (insert completion)
|
|
630 (setq buffer-string completion)))
|
|
631 (cond ((eq status 'exact)
|
|
632 ;; If the last exact completion and this one were
|
|
633 ;; the same, it means we've already given a
|
|
634 ;; "Complete but not unique" message and that the
|
|
635 ;; user's hit TAB again, so now we give help.
|
|
636 (setq last-exact-completion completion)
|
|
637 (if (equal buffer-string last)
|
|
638 (minibuffer-completion-help)))
|
|
639 ((eq status 'uncompleted)
|
|
640 (if completion-auto-help
|
|
641 (minibuffer-completion-help)
|
|
642 (temp-minibuffer-message " [Next char not unique]")))
|
|
643 (t
|
|
644 nil))))
|
|
645 status))
|
|
646
|
|
647
|
|
648 ;;;; completing-read
|
|
649
|
|
650 (defun completing-read (prompt table
|
|
651 &optional predicate require-match
|
|
652 initial-contents history)
|
|
653 "Read a string in the minibuffer, with completion.
|
|
654 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY.
|
|
655 PROMPT is a string to prompt with; normally it ends in a colon and a space.
|
|
656 TABLE is an alist whose elements' cars are strings, or an obarray.
|
|
657 PREDICATE limits completion to a subset of TABLE.
|
|
658 See `try-completion' for more details on completion, TABLE, and PREDICATE.
|
|
659 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
|
|
660 the input is (or completes to) an element of TABLE or is null.
|
|
661 If it is also not t, Return does not exit if it does non-null completion.
|
|
662 If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially.
|
|
663 If it is (STRING . POSITION), the initial input
|
|
664 is STRING, but point is placed POSITION characters into the string.
|
|
665 HISTORY, if non-nil, specifies a history list
|
|
666 and optionally the initial position in the list.
|
|
667 It can be a symbol, which is the history list variable to use,
|
|
668 or it can be a cons cell (HISTVAR . HISTPOS).
|
|
669 In that case, HISTVAR is the history list variable to use,
|
|
670 and HISTPOS is the initial position (the position in the list
|
|
671 which INITIAL-CONTENTS corresponds to).
|
|
672 If HISTORY is `t', no history will be recorded.
|
|
673 Positions are counted starting from 1 at the beginning of the list.
|
|
674 Completion ignores case if the ambient value of
|
|
675 `completion-ignore-case' is non-nil."
|
|
676 (let ((minibuffer-completion-table table)
|
|
677 (minibuffer-completion-predicate predicate)
|
|
678 (minibuffer-completion-confirm (if (eq require-match 't) nil t))
|
|
679 (last-exact-completion nil))
|
|
680 (read-from-minibuffer prompt
|
|
681 initial-contents
|
|
682 (if (not require-match)
|
|
683 minibuffer-local-completion-map
|
|
684 minibuffer-local-must-match-map)
|
|
685 nil
|
|
686 history)))
|
|
687
|
|
688
|
|
689 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
690 ;;;; Minibuffer completion commands ;;;;
|
|
691 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
692
|
|
693
|
|
694 (defun minibuffer-complete ()
|
|
695 "Complete the minibuffer contents as far as possible.
|
|
696 Return nil if there is no valid completion, else t.
|
|
697 If no characters can be completed, display a list of possible completions.
|
|
698 If you repeat this command after it displayed such a list,
|
|
699 scroll the window of possible completions."
|
|
700 (interactive)
|
|
701 ;; If the previous command was not this, then mark the completion
|
|
702 ;; buffer obsolete.
|
|
703 (or (eq last-command this-command)
|
|
704 (setq minibuffer-scroll-window nil))
|
|
705 (let ((window minibuffer-scroll-window))
|
|
706 (if (and window (windowp window) (window-buffer window)
|
|
707 (buffer-name (window-buffer window)))
|
|
708 ;; If there's a fresh completion window with a live buffer
|
|
709 ;; and this command is repeated, scroll that window.
|
|
710 (let ((obuf (current-buffer)))
|
|
711 (unwind-protect
|
|
712 (progn
|
|
713 (set-buffer (window-buffer window))
|
|
714 (if (pos-visible-in-window-p (point-max) window)
|
|
715 ;; If end is in view, scroll up to the beginning.
|
|
716 (set-window-start window (point-min))
|
|
717 ;; Else scroll down one frame.
|
|
718 (scroll-other-window)))
|
|
719 (set-buffer obuf))
|
|
720 nil)
|
|
721 (let ((status (minibuffer-do-completion (buffer-string))))
|
|
722 (if (eq status 'none)
|
|
723 nil
|
|
724 (progn
|
|
725 (cond ((eq status 'unique)
|
|
726 (temp-minibuffer-message
|
|
727 " [Sole completion]"))
|
|
728 ((eq status 'exact)
|
|
729 (temp-minibuffer-message
|
|
730 " [Complete, but not unique]")))
|
|
731 t))))))
|
|
732
|
|
733
|
|
734 (defun minibuffer-complete-and-exit ()
|
|
735 "Complete the minibuffer contents, and maybe exit.
|
|
736 Exit if the name is valid with no completion needed.
|
|
737 If name was completed to a valid match,
|
|
738 a repetition of this command will exit."
|
|
739 (interactive)
|
|
740 (if (= (point-min) (point-max))
|
|
741 ;; Crockishly allow user to specify null string
|
|
742 (throw 'exit nil))
|
|
743 (let ((buffer-string (buffer-string)))
|
|
744 ;; Short-cut -- don't call minibuffer-do-completion if we already
|
|
745 ;; have an (possibly nonunique) exact completion.
|
|
746 (if (exact-minibuffer-completion-p buffer-string)
|
|
747 (throw 'exit nil))
|
|
748 (let ((status (minibuffer-do-completion buffer-string)))
|
|
749 (if (or (eq status 'unique)
|
|
750 (eq status 'exact)
|
|
751 (if (or (eq status 'completed-exact)
|
|
752 (eq status 'completed-exact-unique))
|
|
753 (if minibuffer-completion-confirm
|
|
754 (progn (temp-minibuffer-message " [Confirm]")
|
|
755 nil)
|
|
756 t)))
|
|
757 (throw 'exit nil)))))
|
|
758
|
|
759
|
|
760 (defun self-insert-and-exit ()
|
|
761 "Terminate minibuffer input."
|
|
762 (interactive)
|
|
763 (self-insert-command 1)
|
|
764 (throw 'exit nil))
|
|
765
|
|
766 (defun exit-minibuffer ()
|
|
767 "Terminate this minibuffer argument.
|
|
768 If minibuffer-confirm-incomplete is true, and we are in a completing-read
|
|
769 of some kind, and the contents of the minibuffer is not an existing
|
|
770 completion, requires an additional RET before the minibuffer will be exited
|
|
771 \(assuming that RET was the character that invoked this command:
|
|
772 the character in question must be typed again)."
|
|
773 (interactive)
|
|
774 (if (not minibuffer-confirm-incomplete)
|
|
775 (throw 'exit nil))
|
|
776 (let ((buffer-string (buffer-string)))
|
|
777 (if (exact-minibuffer-completion-p buffer-string)
|
|
778 (throw 'exit nil))
|
|
779 (let ((completion (if (not minibuffer-completion-table)
|
|
780 t
|
|
781 (try-completion buffer-string
|
|
782 minibuffer-completion-table
|
|
783 minibuffer-completion-predicate))))
|
|
784 (if (or (eq completion 't)
|
|
785 ;; Crockishly allow user to specify null string
|
|
786 (string-equal buffer-string ""))
|
|
787 (throw 'exit nil))
|
|
788 (if completion ;; rewritten for I18N3 snarfing
|
|
789 (temp-minibuffer-message " [incomplete; confirm]")
|
|
790 (temp-minibuffer-message " [no completions; confirm]"))
|
|
791 (let ((event (let ((inhibit-quit t))
|
|
792 (prog1
|
|
793 (next-command-event)
|
|
794 (setq quit-flag nil)))))
|
|
795 (cond ((equal event last-command-event)
|
|
796 (throw 'exit nil))
|
|
797 ((equal (quit-char) (event-to-character event))
|
|
798 ;; Minibuffer abort.
|
|
799 (throw 'exit t)))
|
|
800 (dispatch-event event)))))
|
|
801
|
|
802 ;;;; minibuffer-complete-word
|
|
803
|
|
804
|
|
805 ;;;#### I think I have done this correctly; it certainly is simpler
|
|
806 ;;;#### than what the C code seemed to be trying to do.
|
|
807 (defun minibuffer-complete-word ()
|
|
808 "Complete the minibuffer contents at most a single word.
|
|
809 After one word is completed as much as possible, a space or hyphen
|
|
810 is added, provided that matches some possible completion.
|
|
811 Return nil if there is no valid completion, else t."
|
|
812 (interactive)
|
|
813 (let* ((buffer-string (buffer-string))
|
|
814 (completion (try-completion buffer-string
|
|
815 minibuffer-completion-table
|
|
816 minibuffer-completion-predicate))
|
|
817 (status (minibuffer-do-completion-1 buffer-string completion)))
|
|
818 (cond ((eq status 'none)
|
|
819 (ding nil 'no-completion)
|
|
820 (temp-minibuffer-message " [No match]")
|
|
821 nil)
|
|
822 ((eq status 'unique)
|
|
823 ;; New message, only in this new Lisp code
|
|
824 (temp-minibuffer-message " [Sole completion]")
|
|
825 t)
|
|
826 (t
|
|
827 (cond ((or (eq status 'uncompleted)
|
|
828 (eq status 'exact))
|
|
829 (let ((foo #'(lambda (s)
|
|
830 (condition-case nil
|
|
831 (if (try-completion
|
|
832 (concat buffer-string s)
|
|
833 minibuffer-completion-table
|
|
834 minibuffer-completion-predicate)
|
|
835 (progn
|
|
836 (goto-char (point-max))
|
|
837 (insert s)
|
|
838 t)
|
|
839 nil)
|
|
840 (error nil))))
|
|
841 (char last-command-char))
|
|
842 ;; Try to complete by adding a word-delimiter
|
|
843 (or (and (integerp char) (> char 0)
|
|
844 (funcall foo (char-to-string char)))
|
|
845 (and (not (eq char ?\ ))
|
|
846 (funcall foo " "))
|
|
847 (and (not (eq char ?\-))
|
|
848 (funcall foo "-"))
|
|
849 (progn
|
|
850 (if completion-auto-help
|
|
851 (minibuffer-completion-help)
|
|
852 ;; New message, only in this new Lisp code
|
|
853 ;; rewritten for I18N3 snarfing
|
|
854 (if (eq status 'exact)
|
|
855 (temp-minibuffer-message
|
|
856 " [Complete, but not unique]")
|
|
857 (temp-minibuffer-message " [Ambiguous]")))
|
|
858 nil))))
|
|
859 (t
|
|
860 (erase-buffer)
|
|
861 (insert completion)
|
|
862 ;; First word-break in stuff found by completion
|
|
863 (goto-char (point-min))
|
|
864 (let ((len (length buffer-string))
|
|
865 n)
|
|
866 (if (and (< len (length completion))
|
|
867 (catch 'match
|
|
868 (setq n 0)
|
|
869 (while (< n len)
|
|
870 (if (char-equal
|
|
871 (upcase (aref buffer-string n))
|
|
872 (upcase (aref completion n)))
|
|
873 (setq n (1+ n))
|
|
874 (throw 'match nil)))
|
|
875 t)
|
|
876 (progn
|
|
877 (goto-char (point-min))
|
|
878 (forward-char len)
|
|
879 (re-search-forward "\\W" nil t)))
|
|
880 (delete-region (point) (point-max))
|
|
881 (goto-char (point-max))))
|
|
882 t))))))
|
|
883
|
|
884
|
|
885 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
886 ;;;; "Smart minibuffer" hackery ;;;;
|
|
887 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
888
|
|
889 ;;; ("Kludgy minibuffer hackery" is perhaps a better name)
|
|
890
|
|
891 ;; This works by setting `mouse-grabbed-buffer' to the minibuffer,
|
|
892 ;; defining button2 in the minibuffer keymap to
|
|
893 ;; `minibuffer-smart-select-highlighted-completion', and setting the
|
|
894 ;; mode-motion-hook of the minibuffer to `minibuffer-mouse-tracker'.
|
|
895 ;; By setting `mouse-grabbed-buffer', the minibuffer's keymap and
|
|
896 ;; mode-motion-hook apply (for mouse motion and presses) no matter
|
|
897 ;; what buffer the mouse is over. Then, `minibuffer-mouse-tracker'
|
|
898 ;; examines the text under the mouse looking for something that looks
|
|
899 ;; like a completion, and causes it to be highlighted, and
|
|
900 ;; `minibuffer-smart-select-highlighted-completion' looks for a
|
|
901 ;; flagged completion under the mouse and inserts it. This has the
|
|
902 ;; following advantages:
|
|
903 ;;
|
|
904 ;; -- filenames and such in any buffer can be inserted by clicking,
|
|
905 ;; not just completions
|
|
906 ;;
|
|
907 ;; but the following disadvantages:
|
|
908 ;;
|
|
909 ;; -- unless you're aware of the "filename in any buffer" feature,
|
|
910 ;; the fact that strings in arbitrary buffers get highlighted appears
|
|
911 ;; as a bug
|
|
912 ;; -- mouse motion can cause ange-ftp actions -- bad bad bad.
|
|
913 ;;
|
|
914 ;; There's some hackery in minibuffer-mouse-tracker to try to avoid the
|
|
915 ;; ange-ftp stuff, but it doesn't work.
|
|
916 ;;
|
|
917
|
|
918 (defvar minibuffer-smart-completion-tracking-behavior nil
|
|
919 "If non-nil, look for completions under mouse in all buffers.
|
|
920 This allows you to click on something that looks like a completion
|
|
921 and have it selected, regardless of what buffer it is in.
|
|
922
|
|
923 This is not enabled by default because
|
|
924
|
|
925 -- The \"mysterious\" highlighting in normal buffers is confusing to
|
|
926 people not expecting it, and looks like a bug
|
|
927 -- If ange-ftp is enabled, this tracking sometimes causes ange-ftp
|
|
928 action as a result of mouse motion, which is *bad bad bad*.
|
|
929 Hopefully this bug will be fixed at some point.")
|
|
930
|
|
931 (defun minibuffer-smart-mouse-tracker (event)
|
|
932 ;; Used as the mode-motion-hook of the minibuffer window, which is the
|
|
933 ;; value of `mouse-grabbed-buffer' while the minibuffer is active. If
|
|
934 ;; the word under the mouse is a valid minibuffer completion, then it
|
|
935 ;; is highlighted.
|
|
936 ;;
|
|
937 ;; We do some special voodoo when we're reading a pathname, because
|
|
938 ;; the way filename completion works is funny. Possibly there's some
|
|
939 ;; more general way this could be dealt with...
|
|
940 ;;
|
|
941 ;; We do some further voodoo when reading a pathname that is an
|
|
942 ;; ange-ftp or efs path, because causing FTP activity as a result of
|
|
943 ;; mouse motion is a really bad time.
|
|
944 ;;
|
|
945 (and minibuffer-smart-completion-tracking-behavior
|
|
946 (event-point event)
|
|
947 ;; avoid conflict with display-completion-list extents
|
|
948 (not (extent-at (event-point event)
|
|
949 (event-buffer event)
|
|
950 'list-mode-item))
|
|
951 (let ((filename-kludge-p (eq minibuffer-completion-table
|
|
952 'read-file-name-internal)))
|
|
953 (mode-motion-highlight-internal
|
|
954 event
|
|
955 #'(lambda () (default-mouse-track-beginning-of-word
|
|
956 (if filename-kludge-p 'nonwhite t)))
|
|
957 #'(lambda ()
|
|
958 (let ((p (point))
|
|
959 (string ""))
|
|
960 (default-mouse-track-end-of-word
|
|
961 (if filename-kludge-p 'nonwhite t))
|
|
962 (if (and (/= p (point)) minibuffer-completion-table)
|
|
963 (setq string (buffer-substring p (point))))
|
|
964 (if (string-match "\\`[ \t\n]*\\'" string)
|
|
965 (goto-char p)
|
|
966 (if filename-kludge-p
|
|
967 (setq string (minibuffer-smart-select-kludge-filename
|
|
968 string)))
|
|
969 ;; try-completion bogusly returns a string even when
|
|
970 ;; that string is complete if that string is also a
|
|
971 ;; prefix for other completions. This means that we
|
|
972 ;; can't just do the obvious thing, (eq t
|
|
973 ;; (try-completion ...)).
|
|
974 (let (comp)
|
|
975 (if (and filename-kludge-p
|
|
976 ;; #### evil evil evil evil
|
|
977 (or (and (fboundp 'ange-ftp-ftp-path)
|
|
978 (ange-ftp-ftp-path string))
|
|
979 (and (fboundp 'efs-ftp-path)
|
|
980 (efs-ftp-path string))))
|
|
981 (setq comp t)
|
|
982 (setq comp
|
|
983 (try-completion string
|
|
984 minibuffer-completion-table
|
|
985 minibuffer-completion-predicate)))
|
|
986 (or (eq comp t)
|
|
987 (and (equal comp string)
|
|
988 (or (null minibuffer-completion-predicate)
|
|
989 (stringp
|
|
990 minibuffer-completion-predicate) ; ???
|
|
991 (funcall minibuffer-completion-predicate
|
|
992 (if (vectorp
|
|
993 minibuffer-completion-table)
|
|
994 (intern-soft
|
|
995 string
|
|
996 minibuffer-completion-table)
|
|
997 string))))
|
|
998 (goto-char p))))))))))
|
|
999
|
|
1000 (defun minibuffer-smart-select-kludge-filename (string)
|
|
1001 (save-excursion
|
|
1002 (set-buffer mouse-grabbed-buffer) ; the minibuf
|
2
|
1003 (let ((kludge-string (concat (buffer-string) string)))
|
0
|
1004 (if (or (and (fboundp 'ange-ftp-ftp-path)
|
|
1005 (ange-ftp-ftp-path kludge-string))
|
|
1006 (and (fboundp 'efs-ftp-path) (efs-ftp-path kludge-string)))
|
|
1007 ;; #### evil evil evil, but more so.
|
|
1008 string
|
|
1009 (append-expand-filename (buffer-string) string)))))
|
|
1010
|
|
1011 (defun minibuffer-smart-select-highlighted-completion (event)
|
|
1012 "Select the highlighted text under the mouse as a minibuffer response.
|
|
1013 When the minibuffer is being used to prompt the user for a completion,
|
|
1014 any valid completions which are visible on the frame will highlight
|
|
1015 when the mouse moves over them. Clicking \\<minibuffer-local-map>\
|
|
1016 \\[minibuffer-smart-select-highlighted-completion] will select the
|
|
1017 highlighted completion under the mouse.
|
|
1018
|
2
|
1019 If the mouse is clicked while not over a highlighted completion,
|
0
|
1020 then the global binding of \\[minibuffer-smart-select-highlighted-completion] \
|
|
1021 will be executed instead. In this\nway you can get at the normal global \
|
|
1022 behavior of \\[minibuffer-smart-select-highlighted-completion] as well as
|
|
1023 the special minibuffer behavior."
|
|
1024 (interactive "e")
|
|
1025 (if minibuffer-smart-completion-tracking-behavior
|
|
1026 (minibuffer-smart-select-highlighted-completion-1 event t)
|
|
1027 (let ((command (lookup-key global-map
|
|
1028 (vector current-mouse-event))))
|
|
1029 (if command (call-interactively command)))))
|
|
1030
|
|
1031 (defun minibuffer-smart-select-highlighted-completion-1 (event global-p)
|
|
1032 (let* ((filename-kludge-p (eq minibuffer-completion-table
|
|
1033 'read-file-name-internal))
|
|
1034 completion
|
|
1035 command-p
|
|
1036 (evpoint (event-point event))
|
|
1037 (evextent (and evpoint (extent-at evpoint (event-buffer event)
|
|
1038 'list-mode-item))))
|
|
1039 (if evextent
|
|
1040 ;; avoid conflict with display-completion-list extents.
|
|
1041 ;; if we find one, do that behavior instead.
|
|
1042 (list-mode-item-selected-1 evextent event)
|
|
1043 (save-excursion
|
|
1044 (let* ((buffer (window-buffer (event-window event)))
|
|
1045 (p (event-point event))
|
|
1046 (extent (and p (extent-at p buffer 'mouse-face))))
|
|
1047 (set-buffer buffer)
|
|
1048 (if (not (and (extent-live-p extent)
|
|
1049 (eq (extent-object extent) (current-buffer))
|
|
1050 (not (extent-detached-p extent))))
|
|
1051 (setq command-p t)
|
|
1052 ;; ...else user has selected a highlighted completion.
|
|
1053 (setq completion
|
|
1054 (buffer-substring (extent-start-position extent)
|
|
1055 (extent-end-position extent)))
|
|
1056 (if filename-kludge-p
|
|
1057 (setq completion (minibuffer-smart-select-kludge-filename
|
|
1058 completion)))
|
|
1059 ;; remove the extent so that it's not hanging around in
|
|
1060 ;; *Completions*
|
|
1061 (detach-extent extent)
|
|
1062 (set-buffer mouse-grabbed-buffer)
|
|
1063 (erase-buffer)
|
|
1064 (insert completion))))
|
|
1065 ;; we need to execute the command or do the throw outside of the
|
|
1066 ;; save-excursion.
|
|
1067 (cond ((and command-p global-p)
|
|
1068 (let ((command (lookup-key global-map
|
|
1069 (vector current-mouse-event))))
|
|
1070 (if command
|
|
1071 (call-interactively command)
|
|
1072 (if minibuffer-completion-table
|
|
1073 (error
|
|
1074 "Highlighted words are valid completions. You may select one.")
|
|
1075 (error "no completions")))))
|
|
1076 ((not command-p)
|
|
1077 ;; things get confused if the minibuffer is terminated while
|
|
1078 ;; not selected.
|
|
1079 (select-window (minibuffer-window))
|
|
1080 (if (and filename-kludge-p (file-directory-p completion))
|
|
1081 ;; if the user clicked middle on a directory name, display the
|
|
1082 ;; files in that directory.
|
|
1083 (progn
|
|
1084 (goto-char (point-max))
|
|
1085 (minibuffer-completion-help))
|
|
1086 ;; otherwise, terminate input
|
|
1087 (throw 'exit nil)))))))
|
|
1088
|
|
1089 (defun minibuffer-smart-maybe-select-highlighted-completion
|
|
1090 (event &optional click-count)
|
|
1091 "Like minibuffer-smart-select-highlighted-completion but does nothing if
|
|
1092 there is no completion (as opposed to executing the global binding). Useful
|
|
1093 as the value of `mouse-track-click-hook'."
|
|
1094 (interactive "e")
|
|
1095 (minibuffer-smart-select-highlighted-completion-1 event nil))
|
|
1096
|
|
1097 (define-key minibuffer-local-map 'button2
|
|
1098 'minibuffer-smart-select-highlighted-completion)
|
|
1099
|
|
1100
|
|
1101 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1102 ;;;; Minibuffer History ;;;;
|
|
1103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1104
|
|
1105 (defvar minibuffer-history '()
|
|
1106 "Default minibuffer history list.
|
|
1107 This is used for all minibuffer input except when an alternate history
|
|
1108 list is specified.")
|
|
1109
|
|
1110 ;; Some other history lists:
|
|
1111 ;;
|
|
1112 (defvar minibuffer-history-search-history '())
|
|
1113 (defvar function-history '())
|
|
1114 (defvar variable-history '())
|
|
1115 (defvar buffer-history '())
|
|
1116 (defvar shell-command-history '())
|
|
1117 (defvar file-name-history '())
|
|
1118
|
|
1119 (defvar read-expression-history nil)
|
|
1120
|
|
1121 (defvar minibuffer-history-sexp-flag nil ;weird FSF Emacs kludge
|
|
1122 "Non-nil when doing history operations on `command-history'.
|
|
1123 More generally, indicates that the history list being acted on
|
|
1124 contains expressions rather than strings.")
|
|
1125
|
|
1126 (defun previous-matching-history-element (regexp n)
|
|
1127 "Find the previous history element that matches REGEXP.
|
|
1128 \(Previous history elements refer to earlier actions.)
|
|
1129 With prefix argument N, search for Nth previous match.
|
|
1130 If N is negative, find the next or Nth next match."
|
|
1131 (interactive
|
|
1132 (let ((enable-recursive-minibuffers t)
|
|
1133 (minibuffer-history-sexp-flag nil))
|
|
1134 (if (eq 't (symbol-value minibuffer-history-variable))
|
|
1135 (error "history is not being recorded in this context"))
|
|
1136 (list (read-from-minibuffer "Previous element matching (regexp): "
|
|
1137 (car minibuffer-history-search-history)
|
|
1138 minibuffer-local-map
|
|
1139 nil
|
|
1140 'minibuffer-history-search-history)
|
|
1141 (prefix-numeric-value current-prefix-arg))))
|
|
1142 (let ((history (symbol-value minibuffer-history-variable))
|
|
1143 prevpos
|
|
1144 (pos minibuffer-history-position))
|
|
1145 (if (eq history t)
|
|
1146 (error "history is not being recorded in this context"))
|
|
1147 (while (/= n 0)
|
|
1148 (setq prevpos pos)
|
|
1149 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
|
|
1150 (if (= pos prevpos)
|
|
1151 (if (= pos 1) ;; rewritten for I18N3 snarfing
|
|
1152 (error "No later matching history item")
|
|
1153 (error "No earlier matching history item")))
|
|
1154 (if (string-match regexp
|
|
1155 (if minibuffer-history-sexp-flag
|
|
1156 (let ((print-level nil))
|
|
1157 (prin1-to-string (nth (1- pos) history)))
|
|
1158 (nth (1- pos) history)))
|
|
1159 (setq n (+ n (if (< n 0) 1 -1)))))
|
|
1160 (setq minibuffer-history-position pos)
|
|
1161 (erase-buffer)
|
|
1162 (let ((elt (nth (1- pos) history)))
|
|
1163 (insert (if minibuffer-history-sexp-flag
|
|
1164 (let ((print-level nil))
|
|
1165 (prin1-to-string elt))
|
|
1166 elt)))
|
|
1167 (goto-char (point-min)))
|
|
1168 (if (or (eq (car (car command-history)) 'previous-matching-history-element)
|
|
1169 (eq (car (car command-history)) 'next-matching-history-element))
|
|
1170 (setq command-history (cdr command-history))))
|
|
1171
|
|
1172 (defun next-matching-history-element (regexp n)
|
|
1173 "Find the next history element that matches REGEXP.
|
|
1174 \(The next history element refers to a more recent action.)
|
|
1175 With prefix argument N, search for Nth next match.
|
|
1176 If N is negative, find the previous or Nth previous match."
|
|
1177 (interactive
|
|
1178 (let ((enable-recursive-minibuffers t)
|
|
1179 (minibuffer-history-sexp-flag nil))
|
|
1180 (if (eq t (symbol-value minibuffer-history-variable))
|
|
1181 (error "history is not being recorded in this context"))
|
|
1182 (list (read-from-minibuffer "Next element matching (regexp): "
|
|
1183 (car minibuffer-history-search-history)
|
|
1184 minibuffer-local-map
|
|
1185 nil
|
|
1186 'minibuffer-history-search-history)
|
|
1187 (prefix-numeric-value current-prefix-arg))))
|
|
1188 (previous-matching-history-element regexp (- n)))
|
|
1189
|
|
1190 (defun next-history-element (n)
|
|
1191 "Insert the next element of the minibuffer history into the minibuffer."
|
|
1192 (interactive "p")
|
|
1193 (if (eq 't (symbol-value minibuffer-history-variable))
|
|
1194 (error "history is not being recorded in this context"))
|
|
1195 (or (zerop n)
|
|
1196 (let ((narg (min (max 1 (- minibuffer-history-position n))
|
|
1197 (length (symbol-value minibuffer-history-variable)))))
|
|
1198 (if (or (zerop narg)
|
|
1199 (= minibuffer-history-position narg))
|
|
1200 (error (if (>= n 0) ;; rewritten for I18N3 snarfing
|
|
1201 (format "No following item in %s"
|
|
1202 minibuffer-history-variable)
|
|
1203 (format "No preceding item in %s"
|
|
1204 minibuffer-history-variable)))
|
|
1205 (erase-buffer)
|
|
1206 (setq minibuffer-history-position narg)
|
|
1207 (let ((elt (nth (1- minibuffer-history-position)
|
|
1208 (symbol-value minibuffer-history-variable))))
|
|
1209 (insert
|
70
|
1210 (if (and minibuffer-history-sexp-flag
|
|
1211 ;; total kludge
|
|
1212 (not (stringp elt)))
|
0
|
1213 (let ((print-level nil))
|
|
1214 (condition-case nil
|
|
1215 (let ((print-readably t)
|
|
1216 (print-escape-newlines t))
|
|
1217 (prin1-to-string elt))
|
|
1218 (error (prin1-to-string elt))))
|
|
1219 elt)))
|
|
1220 ;; FSF has point-min here.
|
|
1221 (goto-char (point-max))))))
|
|
1222
|
|
1223 (defun previous-history-element (n)
|
|
1224 "Inserts the previous element of the minibuffer history into the minibuffer."
|
|
1225 (interactive "p")
|
|
1226 (next-history-element (- n)))
|
|
1227
|
|
1228 (defun next-complete-history-element (n)
|
|
1229 "Get next element of history which is a completion of minibuffer contents."
|
|
1230 (interactive "p")
|
|
1231 (let ((point-at-start (point)))
|
|
1232 (next-matching-history-element
|
|
1233 (concat "^" (regexp-quote (buffer-substring (point-min) (point)))) n)
|
|
1234 ;; next-matching-history-element always puts us at (point-min).
|
|
1235 ;; Move to the position we were at before changing the buffer contents.
|
|
1236 ;; This is still sensical, because the text before point has not changed.
|
|
1237 (goto-char point-at-start)))
|
|
1238
|
|
1239 (defun previous-complete-history-element (n)
|
|
1240 "Get previous element of history which is a completion of minibuffer contents."
|
|
1241 (interactive "p")
|
|
1242 (next-complete-history-element (- n)))
|
|
1243
|
|
1244
|
|
1245 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1246 ;;;; reading various things from a minibuffer ;;;;
|
|
1247 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1248
|
|
1249 (defun read-expression (prompt &optional initial-contents history)
|
|
1250 "Return a Lisp object read using the minibuffer.
|
|
1251 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
|
|
1252 is a string to insert in the minibuffer before reading.
|
|
1253 Third arg HISTORY, if non-nil, specifies a history list."
|
|
1254 (let ((minibuffer-history-sexp-flag t)
|
|
1255 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion.
|
|
1256 (minibuffer-completion-table nil))
|
|
1257 (read-from-minibuffer prompt
|
|
1258 initial-contents
|
|
1259 read-expression-map
|
|
1260 t
|
|
1261 (or history 'read-expression-history)
|
|
1262 lisp-mode-abbrev-table)))
|
|
1263
|
|
1264 (defun read-string (prompt &optional initial-contents history)
|
|
1265 "Return a string from the minibuffer, prompting with string PROMPT.
|
|
1266 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
|
|
1267 in the minibuffer before reading.
|
|
1268 Third arg HISTORY, if non-nil, specifies a history list."
|
|
1269 (let ((minibuffer-completion-table nil))
|
|
1270 (read-from-minibuffer prompt
|
|
1271 initial-contents
|
|
1272 minibuffer-local-map
|
|
1273 nil history)))
|
|
1274
|
|
1275 (defun eval-minibuffer (prompt &optional initial-contents history)
|
|
1276 "Return value of Lisp expression read using the minibuffer.
|
|
1277 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
|
|
1278 is a string to insert in the minibuffer before reading.
|
|
1279 Third arg HISTORY, if non-nil, specifies a history list."
|
|
1280 (eval (read-expression prompt initial-contents history)))
|
|
1281
|
|
1282 ;;;#### Screw this crock!!
|
|
1283 ;(defun read-no-blanks-input (prompt &optional initial-contents)
|
|
1284 ; "Read a string from the terminal, not allowing blanks.
|
|
1285 ;Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
|
|
1286 ;is a string to insert in the minibuffer before reading."
|
|
1287 ; (let ((minibuffer-completion-table nil))
|
|
1288 ; (read-from-minibuffer prompt
|
|
1289 ; initial-contents
|
|
1290 ; minibuffer-local-ns-map
|
|
1291 ; nil)))
|
|
1292
|
|
1293 ;; The name `command-history' is already taken
|
|
1294 (defvar read-command-history '())
|
|
1295
|
|
1296 (defun read-command (prompt)
|
|
1297 "Read the name of a command and return as a symbol.
|
|
1298 Prompts with PROMPT."
|
|
1299 (intern (completing-read prompt obarray 'commandp t nil
|
|
1300 ;; 'command-history is not right here: that's a
|
|
1301 ;; list of evalable forms, not a history list.
|
|
1302 'read-command-history
|
|
1303 )))
|
|
1304
|
|
1305 (defun read-function (prompt)
|
|
1306 "Read the name of a function and return as a symbol.
|
|
1307 Prompts with PROMPT."
|
|
1308 (intern (completing-read prompt obarray 'fboundp t nil
|
|
1309 'function-history)))
|
|
1310
|
|
1311 (defun read-variable (prompt)
|
|
1312 "Read the name of a user variable and return it as a symbol.
|
|
1313 Prompts with PROMPT.
|
|
1314 A user variable is one whose documentation starts with a `*' character."
|
|
1315 (intern (completing-read prompt obarray 'user-variable-p t nil
|
|
1316 'variable-history)))
|
|
1317
|
|
1318 (defun read-buffer (prompt &optional default require-match)
|
|
1319 "Read the name of a buffer and return as a string.
|
|
1320 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user
|
|
1321 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil,
|
|
1322 only existing buffer names are allowed."
|
|
1323 (let ((prompt (if default
|
|
1324 (format "%s(default %s) "
|
|
1325 (gettext prompt) (if (bufferp default)
|
|
1326 (buffer-name default)
|
|
1327 default))
|
|
1328 prompt))
|
|
1329 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b))
|
|
1330 (buffer-list)))
|
|
1331 result)
|
|
1332 (while (progn
|
|
1333 (setq result (completing-read prompt alist nil require-match
|
|
1334 nil 'buffer-history))
|
|
1335 (cond ((not (equal result ""))
|
|
1336 nil)
|
|
1337 ((not require-match)
|
|
1338 (setq result default)
|
|
1339 nil)
|
|
1340 ((not default)
|
|
1341 t)
|
|
1342 ((not (get-buffer default))
|
|
1343 t)
|
|
1344 (t
|
|
1345 (setq result default)
|
|
1346 nil))))
|
|
1347 (if (bufferp result)
|
|
1348 (buffer-name result)
|
|
1349 result)))
|
|
1350
|
|
1351 (defun read-number (prompt &optional integers-only)
|
|
1352 "Reads a number from the minibuffer."
|
|
1353 (let ((pred (if integers-only 'integerp 'numberp))
|
|
1354 num)
|
|
1355 (while (not (funcall pred num))
|
|
1356 (setq num (condition-case ()
|
|
1357 (let ((minibuffer-completion-table nil))
|
|
1358 (read-from-minibuffer
|
|
1359 prompt (if num (prin1-to-string num)) nil t
|
|
1360 t)) ;no history
|
|
1361 (invalid-read-syntax nil)
|
|
1362 (end-of-file nil)))
|
|
1363 (or (funcall pred num) (beep)))
|
|
1364 num))
|
|
1365
|
|
1366 (defun read-shell-command (prompt &optional initial-input history)
|
|
1367 "Just like read-string, but uses read-shell-command-map:
|
|
1368 \\{read-shell-command-map}"
|
|
1369 (let ((minibuffer-completion-table nil))
|
|
1370 (read-from-minibuffer prompt initial-input read-shell-command-map
|
|
1371 nil (or history 'shell-command-history))))
|
|
1372
|
|
1373
|
|
1374 ;;; This read-file-name stuff probably belongs in files.el
|
|
1375
|
|
1376 ;; Quote "$" as "$$" to get it past substitute-in-file-name
|
|
1377 (defun un-substitute-in-file-name (string)
|
|
1378 (let ((regexp "\\$")
|
|
1379 (olen (length string))
|
|
1380 new
|
|
1381 n o ch)
|
|
1382 (cond ((eq system-type 'vax-vms)
|
|
1383 string)
|
|
1384 ((not (string-match regexp string))
|
|
1385 string)
|
|
1386 (t
|
|
1387 (setq n 1)
|
|
1388 (while (string-match regexp string (match-end 0))
|
|
1389 (setq n (1+ n)))
|
|
1390 (setq new (make-string (+ olen n) ?$))
|
|
1391 (setq n 0 o 0)
|
|
1392 (while (< o olen)
|
|
1393 (setq ch (aref string o))
|
|
1394 (aset new n ch)
|
|
1395 (setq o (1+ o) n (1+ n))
|
|
1396 (if (eq ch ?$)
|
|
1397 ;; already aset by make-string initial-value
|
|
1398 (setq n (1+ n))))
|
|
1399 new))))
|
|
1400
|
|
1401 (defun read-file-name-2 (history prompt dir default
|
|
1402 must-match initial-contents
|
|
1403 completer)
|
|
1404 (if (not dir)
|
|
1405 (setq dir default-directory))
|
|
1406 (setq dir (abbreviate-file-name dir t))
|
|
1407 (let* ((insert (cond ((and (not insert-default-directory)
|
|
1408 (not initial-contents))
|
|
1409 "")
|
|
1410 (initial-contents
|
|
1411 (cons (un-substitute-in-file-name
|
|
1412 (concat dir initial-contents))
|
|
1413 (length dir)))
|
|
1414 (t
|
|
1415 (un-substitute-in-file-name dir))))
|
|
1416 (val (let ((completion-ignore-case (or completion-ignore-case
|
|
1417 (eq system-type 'vax-vms))))
|
|
1418 ;; Hateful, broken, case-sensitive un*x
|
|
1419 ;;; (completing-read prompt
|
|
1420 ;;; completer
|
|
1421 ;;; dir
|
|
1422 ;;; must-match
|
|
1423 ;;; insert
|
|
1424 ;;; history)
|
|
1425 ;; #### - this is essentially the guts of completing read.
|
|
1426 ;; There should be an elegant way to pass a pair of keymaps to
|
|
1427 ;; completing read, but this will do for now. All sins are
|
|
1428 ;; relative. --Stig
|
|
1429 (let ((minibuffer-completion-table completer)
|
|
1430 (minibuffer-completion-predicate dir)
|
|
1431 (minibuffer-completion-confirm (if (eq must-match 't)
|
|
1432 nil t))
|
|
1433 (last-exact-completion nil))
|
|
1434 (read-from-minibuffer prompt
|
|
1435 insert
|
|
1436 (if (not must-match)
|
|
1437 read-file-name-map
|
|
1438 read-file-name-must-match-map)
|
|
1439 nil
|
|
1440 history)))
|
|
1441 ))
|
|
1442 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar"
|
|
1443 ;;; (let ((hist (cond ((not history) 'minibuffer-history)
|
|
1444 ;;; ((consp history) (car history))
|
|
1445 ;;; (t history))))
|
|
1446 ;;; (if (and val
|
|
1447 ;;; hist
|
|
1448 ;;; (not (eq hist 't))
|
|
1449 ;;; (boundp hist)
|
|
1450 ;;; (equal (car-safe (symbol-value hist)) val))
|
|
1451 ;;; (let ((e (condition-case nil
|
|
1452 ;;; (expand-file-name val)
|
|
1453 ;;; (error nil))))
|
|
1454 ;;; (if (and e (not (equal e val)))
|
|
1455 ;;; (set hist (cons e (cdr (symbol-value hist))))))))
|
|
1456
|
|
1457 (cond ((not val)
|
|
1458 (error "No file name specified"))
|
|
1459 ((and default
|
|
1460 (equal val (if (consp insert) (car insert) insert)))
|
|
1461 default)
|
|
1462 (t
|
|
1463 (substitute-in-file-name val)))))
|
|
1464
|
|
1465 ;; #### this function should use minibuffer-completion-table
|
|
1466 ;; or something. But that is sloooooow.
|
|
1467 ;; #### all this shit needs better documentation!!!!!!!!
|
|
1468 (defun read-file-name-activate-callback (event extent dir-p)
|
|
1469 ;; used as the activate-callback of the filename list items
|
|
1470 ;; in the completion buffer, in place of default-choose-completion.
|
|
1471 ;; if a regular file was selected, we call default-choose-completion
|
|
1472 ;; (which just inserts the string in the minibuffer and calls
|
|
1473 ;; exit-minibuffer). If a directory was selected, we display
|
|
1474 ;; the contents of the directory.
|
|
1475 (let* ((file (extent-string extent))
|
|
1476 (completion-buf (extent-object extent))
|
|
1477 (minibuf (symbol-value-in-buffer 'completion-reference-buffer
|
|
1478 completion-buf))
|
|
1479 (in-dir (file-name-directory (buffer-substring nil nil minibuf)))
|
|
1480 (full (expand-file-name file in-dir)))
|
|
1481 (if (not (file-directory-p full))
|
|
1482 (default-choose-completion event extent minibuf)
|
|
1483 (erase-buffer minibuf)
|
|
1484 (insert-string (file-name-as-directory
|
|
1485 (abbreviate-file-name full t)) minibuf)
|
|
1486 (reset-buffer completion-buf)
|
|
1487 (let ((standard-output completion-buf))
|
|
1488 (display-completion-list
|
|
1489 (delete "." (directory-files full nil nil nil (if dir-p 'directory)))
|
|
1490 :user-data dir-p
|
|
1491 :reference-buffer minibuf
|
|
1492 :activate-callback 'read-file-name-activate-callback)
|
|
1493 (goto-char (point-min) completion-buf)))))
|
|
1494
|
|
1495 (defun read-file-name-1 (history prompt dir default
|
|
1496 must-match initial-contents
|
|
1497 completer)
|
|
1498 (if (should-use-dialog-box-p)
|
|
1499 ;; this calls read-file-name-2
|
|
1500 (mouse-read-file-name-1 history prompt dir default must-match
|
|
1501 initial-contents completer)
|
|
1502 (let ((rfhookfun
|
|
1503 (lambda ()
|
|
1504 (set
|
|
1505 (make-local-variable
|
|
1506 'completion-display-completion-list-function)
|
|
1507 #'(lambda (completions)
|
|
1508 (display-completion-list
|
|
1509 completions
|
|
1510 :user-data (not (eq completer 'read-file-name-internal))
|
|
1511 :activate-callback
|
|
1512 'read-file-name-activate-callback)))
|
|
1513 ;; kludge!
|
|
1514 (remove-hook 'minibuffer-setup-hook rfhookfun)
|
|
1515 )))
|
|
1516 (unwind-protect
|
|
1517 (progn
|
|
1518 (add-hook 'minibuffer-setup-hook rfhookfun)
|
|
1519 (read-file-name-2 history prompt dir default must-match
|
|
1520 initial-contents completer))
|
|
1521 (remove-hook 'minibuffer-setup-hook rfhookfun)))))
|
|
1522
|
|
1523 (defun read-file-name (prompt
|
|
1524 &optional dir default must-match initial-contents
|
|
1525 history)
|
|
1526 "Read file name, prompting with PROMPT and completing in directory DIR.
|
|
1527 This will prompt with a dialog box if appropriate, according to
|
|
1528 `should-use-dialog-box-p'.
|
|
1529 Value is not expanded---you must call `expand-file-name' yourself.
|
|
1530 Value is subject to interpreted by substitute-in-file-name however.
|
|
1531 Default name to DEFAULT if user enters a null string.
|
|
1532 (If DEFAULT is omitted, the visited file name is used,
|
|
1533 except that if INITIAL-CONTENTS is specified, that combined with DIR is
|
|
1534 used.)
|
|
1535 Fourth arg MUST-MATCH non-nil means require existing file's name.
|
|
1536 Non-nil and non-t means also require confirmation after completion.
|
|
1537 Fifth arg INITIAL-CONTENTS specifies text to start with.
|
|
1538 Sixth arg HISTORY specifies the history list to use. Default is
|
|
1539 `file-name-history'.
|
|
1540 DIR defaults to current buffer's directory default."
|
|
1541 (read-file-name-1
|
|
1542 (or history 'file-name-history)
|
|
1543 prompt dir (or default
|
|
1544 (if initial-contents (expand-file-name initial-contents dir)
|
|
1545 buffer-file-name))
|
|
1546 must-match initial-contents
|
|
1547 ;; A separate function (not an anonymous lambda-expression)
|
|
1548 ;; and passed as a symbol because of disgusting kludges in various
|
|
1549 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...)
|
|
1550 'read-file-name-internal))
|
|
1551
|
|
1552 (defun read-directory-name (prompt
|
|
1553 &optional dir default must-match initial-contents)
|
|
1554 "Read directory name, prompting with PROMPT and completing in directory DIR.
|
|
1555 This will prompt with a dialog box if appropriate, according to
|
|
1556 `should-use-dialog-box-p'.
|
|
1557 Value is not expanded---you must call `expand-file-name' yourself.
|
|
1558 Value is subject to interpreted by substitute-in-file-name however.
|
|
1559 Default name to DEFAULT if user enters a null string.
|
|
1560 (If DEFAULT is omitted, the current buffer's default directory is used.)
|
|
1561 Fourth arg MUST-MATCH non-nil means require existing directory's name.
|
|
1562 Non-nil and non-t means also require confirmation after completion.
|
|
1563 Fifth arg INITIAL-CONTENTS specifies text to start with.
|
|
1564 Sixth arg HISTORY specifies the history list to use. Default is
|
|
1565 `file-name-history'.
|
|
1566 DIR defaults to current buffer's directory default."
|
|
1567 (read-file-name-1
|
|
1568 'file-name-history
|
|
1569 prompt dir (or default default-directory) must-match initial-contents
|
|
1570 'read-directory-name-internal))
|
|
1571
|
|
1572
|
|
1573 ;; Environment-variable completion hack
|
|
1574 (defun read-file-name-internal-1 (string dir action completer)
|
|
1575 (if (not (string-match
|
|
1576 "\\([^$]\\|\\`\\)\\(\\$\\$\\)*\\$\\([A-Za-z0-9_]*\\|{[^}]*\\)\\'"
|
|
1577 string))
|
|
1578 ;; Not doing environment-variable completion hack
|
|
1579 (let* ((orig (if (equal string "") nil string))
|
|
1580 (sstring (if orig (substitute-in-file-name string) string))
|
|
1581 (specdir (if orig (file-name-directory sstring) nil)))
|
|
1582 (funcall completer
|
|
1583 action
|
|
1584 orig
|
|
1585 sstring
|
|
1586 specdir
|
|
1587 (if specdir (expand-file-name specdir dir) dir)
|
|
1588 (if orig (file-name-nondirectory sstring) string)))
|
|
1589 ;; An odd number of trailing $'s
|
|
1590 (let* ((start (match-beginning 3))
|
|
1591 (env (substring string
|
|
1592 (cond ((= start (length string))
|
|
1593 ;; "...$"
|
|
1594 start)
|
|
1595 ((= (aref string start) ?{)
|
|
1596 ;; "...${..."
|
|
1597 (1+ start))
|
|
1598 (t
|
|
1599 start))))
|
|
1600 (head (substring string 0 (1- start)))
|
|
1601 (alist #'(lambda ()
|
|
1602 (mapcar #'(lambda (x)
|
|
1603 (cons (substring x 0 (string-match "=" x))
|
|
1604 'nil))
|
|
1605 process-environment))))
|
|
1606
|
|
1607 (cond ((eq action 'lambda)
|
|
1608 nil)
|
|
1609 ((eq action 't)
|
|
1610 ;; all completions
|
|
1611 (mapcar #'(lambda (p)
|
|
1612 (if (and (> (length p) 0)
|
|
1613 ;;#### Unix-specific
|
|
1614 ;;#### -- need absolute-pathname-p
|
|
1615 (/= (aref p 0) ?/))
|
|
1616 (concat "$" p)
|
|
1617 (concat head "$" p)))
|
|
1618 (all-completions env (funcall alist))))
|
|
1619 (t ;; 'nil
|
|
1620 ;; complete
|
|
1621 (let* ((e (funcall alist))
|
|
1622 (val (try-completion env e)))
|
|
1623 (cond ((stringp val)
|
|
1624 (if (string-match "[^A-Za-z0-9_]" val)
|
|
1625 (concat head
|
|
1626 "${" val
|
|
1627 ;; completed uniquely?
|
|
1628 (if (eq (try-completion val e) 't)
|
|
1629 "}" ""))
|
|
1630 (concat head "$" val)))
|
|
1631 ((eql val 't)
|
|
1632 (concat head
|
|
1633 (un-substitute-in-file-name (getenv env))))
|
|
1634 (t nil))))))))
|
|
1635
|
|
1636
|
|
1637 (defun read-file-name-internal (string dir action)
|
|
1638 (read-file-name-internal-1
|
|
1639 string dir action
|
|
1640 #'(lambda (action orig string specdir dir name)
|
|
1641 (cond ((eq action 'lambda)
|
|
1642 (if (not orig)
|
|
1643 nil
|
|
1644 (let ((sstring (condition-case nil
|
|
1645 (expand-file-name string)
|
|
1646 (error nil))))
|
|
1647 (if (not sstring)
|
|
1648 ;; Some pathname syntax error in string
|
|
1649 nil
|
|
1650 (file-exists-p sstring)))))
|
|
1651 ((eq action 't)
|
|
1652 ;; all completions
|
|
1653 (mapcar #'un-substitute-in-file-name
|
|
1654 (file-name-all-completions name dir)))
|
|
1655 (t;; 'nil
|
|
1656 ;; complete
|
|
1657 (let* ((d (or dir default-directory))
|
|
1658 (val (file-name-completion name d)))
|
|
1659 (if (and (eq val 't)
|
|
1660 (not (null completion-ignored-extensions)))
|
|
1661 ;;#### (file-name-completion "foo") returns 't
|
|
1662 ;; when both "foo" and "foo~" exist and the latter
|
|
1663 ;; is "pruned" by completion-ignored-extensions.
|
|
1664 ;; I think this is a bug in file-name-completion.
|
|
1665 (setq val (let ((completion-ignored-extensions '()))
|
|
1666 (file-name-completion name d))))
|
|
1667 (if (stringp val)
|
|
1668 (un-substitute-in-file-name (if specdir
|
|
1669 (concat specdir val)
|
|
1670 val))
|
|
1671 (let ((tem (un-substitute-in-file-name string)))
|
|
1672 (if (not (equal tem orig))
|
|
1673 ;; substitute-in-file-name did something
|
|
1674 tem
|
|
1675 val)))))))))
|
|
1676
|
|
1677 (defun read-directory-name-internal (string dir action)
|
|
1678 (read-file-name-internal-1
|
|
1679 string dir action
|
|
1680 #'(lambda (action orig string specdir dir name)
|
|
1681 (let* ((dirs #'(lambda (fn)
|
|
1682 (let ((l (if (equal name "")
|
|
1683 (directory-files
|
|
1684 dir
|
|
1685 nil
|
|
1686 ""
|
|
1687 nil
|
|
1688 'directories)
|
|
1689 (directory-files
|
|
1690 dir
|
|
1691 nil
|
|
1692 (concat "\\`" (regexp-quote name))
|
|
1693 nil
|
|
1694 'directories))))
|
|
1695 (mapcar fn
|
|
1696 (cond ((eq system-type 'vax-vms)
|
|
1697 l)
|
|
1698 (t
|
|
1699 ;; Wretched unix
|
|
1700 (delete "." l))))))))
|
|
1701 (cond ((eq action 'lambda)
|
|
1702 ;; complete?
|
|
1703 (if (not orig)
|
|
1704 nil
|
70
|
1705 (and (file-directory-p string)
|
|
1706 ;; So "foo" is ambiguous between "foo/" and "foobar/"
|
|
1707 (equal string (file-name-as-directory string)))))
|
0
|
1708 ((eq action 't)
|
|
1709 ;; all completions
|
|
1710 (funcall dirs #'(lambda (n)
|
|
1711 (un-substitute-in-file-name
|
|
1712 (file-name-as-directory n)))))
|
|
1713 (t
|
|
1714 ;; complete
|
|
1715 (let ((val (try-completion
|
|
1716 name
|
|
1717 (funcall dirs
|
|
1718 #'(lambda (n)
|
|
1719 (list (file-name-as-directory
|
|
1720 n)))))))
|
|
1721 (if (stringp val)
|
|
1722 (un-substitute-in-file-name (if specdir
|
|
1723 (concat specdir val)
|
|
1724 val))
|
|
1725 (let ((tem (un-substitute-in-file-name string)))
|
|
1726 (if (not (equal tem orig))
|
|
1727 ;; substitute-in-file-name did something
|
|
1728 tem
|
|
1729 val))))))))))
|
|
1730
|
|
1731 (defun append-expand-filename (file-string string)
|
|
1732 "Append STRING to FILE-STRING differently depending on whether STRING
|
|
1733 is a username (~string), an environment variable ($string),
|
|
1734 or a filename (/string). The resultant string is returned with the
|
|
1735 environment variable or username expanded and resolved to indicate
|
|
1736 whether it is a file(/result) or a directory (/result/)."
|
|
1737 (let ((file
|
|
1738 (cond ((string-match "\\([~$]\\)\\([^~$/]*\\)$" file-string)
|
|
1739 (cond ((string= (substring file-string
|
|
1740 (match-beginning 1)
|
|
1741 (match-end 1)) "~")
|
|
1742 (concat (substring file-string 0 (match-end 1))
|
|
1743 string))
|
|
1744 (t (substitute-in-file-name
|
|
1745 (concat (substring file-string 0 (match-end 1))
|
|
1746 string)))))
|
|
1747 (t (concat (file-name-directory
|
|
1748 (substitute-in-file-name file-string)) string))))
|
|
1749 result)
|
|
1750
|
|
1751 (cond ((stringp (setq result (and (file-exists-p (expand-file-name file))
|
|
1752 (read-file-name-internal
|
|
1753 (condition-case nil
|
|
1754 (expand-file-name file)
|
|
1755 (error file))
|
|
1756 "" nil))))
|
|
1757 result)
|
|
1758 (t file))))
|
|
1759
|
|
1760 (defun mouse-file-display-completion-list (window dir minibuf user-data)
|
|
1761 (let ((standard-output (window-buffer window)))
|
70
|
1762 (display-completion-list
|
|
1763 (directory-files dir nil nil nil t)
|
|
1764 :window-width (* 2 (window-width window))
|
|
1765 :activate-callback
|
|
1766 'mouse-read-file-name-activate-callback
|
|
1767 :user-data user-data
|
|
1768 :reference-buffer minibuf
|
|
1769 :help-string "")))
|
0
|
1770
|
|
1771 (defun mouse-directory-display-completion-list (window dir minibuf user-data)
|
|
1772 (let ((standard-output (window-buffer window)))
|
70
|
1773 (display-completion-list
|
|
1774 (delete "." (directory-files dir nil nil nil 1))
|
|
1775 :window-width (window-width window)
|
|
1776 :activate-callback
|
|
1777 'mouse-read-file-name-activate-callback
|
|
1778 :user-data user-data
|
|
1779 :reference-buffer minibuf
|
|
1780 :help-string "")))
|
0
|
1781
|
|
1782 (defun mouse-read-file-name-activate-callback (event extent user-data)
|
|
1783 (let* ((file (extent-string extent))
|
|
1784 (minibuf (symbol-value-in-buffer 'completion-reference-buffer
|
|
1785 (extent-object extent)))
|
|
1786 (in-dir (buffer-substring nil nil minibuf))
|
|
1787 (full (expand-file-name file in-dir))
|
|
1788 (filebuf (nth 0 user-data))
|
|
1789 (dirbuff (nth 1 user-data))
|
|
1790 (filewin (nth 2 user-data))
|
|
1791 (dirwin (nth 3 user-data)))
|
|
1792 (if (file-regular-p full)
|
|
1793 (default-choose-completion event extent minibuf)
|
|
1794 (erase-buffer minibuf)
|
|
1795 (insert-string (file-name-as-directory
|
|
1796 (abbreviate-file-name full t)) minibuf)
|
|
1797 (reset-buffer filebuf)
|
|
1798 (if (not dirbuff)
|
|
1799 (mouse-directory-display-completion-list filewin full minibuf
|
|
1800 user-data)
|
|
1801 (mouse-file-display-completion-list filewin full minibuf user-data)
|
|
1802 (reset-buffer dirbuff)
|
|
1803 (mouse-directory-display-completion-list dirwin full minibuf
|
|
1804 user-data)))))
|
|
1805
|
|
1806 ;; this is rather cheesified but gets the job done.
|
|
1807 (defun mouse-read-file-name-1 (history prompt dir default
|
|
1808 must-match initial-contents
|
|
1809 completer)
|
|
1810 (let* ((file-p (eq 'read-file-name-internal completer))
|
|
1811 (filebuf (get-buffer-create "*Completions*"))
|
|
1812 (dirbuff (and file-p (generate-new-buffer " *mouse-read-file*")))
|
|
1813 (butbuff (generate-new-buffer " *mouse-read-file*"))
|
|
1814 (frame (make-dialog-frame))
|
|
1815 filewin dirwin
|
|
1816 user-data)
|
|
1817 (unwind-protect
|
|
1818 (progn
|
|
1819 (reset-buffer filebuf)
|
|
1820 (select-frame frame)
|
|
1821 (let ((window-min-height 1))
|
|
1822 ;; #### should be 2 not 3, but that causes
|
|
1823 ;; "window too small to split" errors for some
|
|
1824 ;; people (but not for me ...) There's a more
|
|
1825 ;; fundamental bug somewhere.
|
|
1826 (split-window nil (- (frame-height frame) 3)))
|
|
1827 (if file-p
|
|
1828 (progn
|
|
1829 (split-window-horizontally 16)
|
|
1830 (setq filewin (frame-rightmost-window frame)
|
|
1831 dirwin (frame-leftmost-window frame))
|
|
1832 (set-window-buffer filewin filebuf)
|
|
1833 (set-window-buffer dirwin dirbuff))
|
|
1834 (setq filewin (frame-highest-window frame))
|
|
1835 (set-window-buffer filewin filebuf))
|
|
1836 (setq user-data (list filebuf dirbuff filewin dirwin))
|
|
1837 (set-window-buffer (frame-lowest-window frame) butbuff)
|
|
1838 (set-buffer butbuff)
|
|
1839 (set-specifier scrollbar-width 0 butbuff)
|
|
1840 (insert " ")
|
|
1841 (insert-gui-button (make-gui-button "OK"
|
|
1842 (lambda (foo)
|
|
1843 (exit-minibuffer))))
|
|
1844 (insert " ")
|
|
1845 (insert-gui-button (make-gui-button "Cancel"
|
|
1846 (lambda (foo)
|
|
1847 (abort-recursive-edit))))
|
|
1848 (let ((rfhookfun
|
|
1849 (lambda ()
|
|
1850 (if (not file-p)
|
|
1851 (mouse-directory-display-completion-list
|
|
1852 filewin dir (current-buffer) user-data)
|
|
1853 (mouse-file-display-completion-list filewin dir
|
|
1854 (current-buffer)
|
|
1855 user-data)
|
|
1856 (mouse-directory-display-completion-list dirwin dir
|
|
1857 (current-buffer)
|
|
1858 user-data))
|
|
1859 (set
|
|
1860 (make-local-variable
|
|
1861 'completion-display-completion-list-function)
|
|
1862 #'(lambda (completions)
|
|
1863 (display-completion-list
|
|
1864 completions
|
|
1865 :help-string ""
|
|
1866 :activate-callback
|
|
1867 'mouse-read-file-name-activate-callback
|
|
1868 :user-data user-data)))
|
|
1869 ;; kludge!
|
|
1870 (remove-hook 'minibuffer-setup-hook rfhookfun)
|
|
1871 ))
|
|
1872 (rfcshookfun
|
|
1873 ;; kludge!
|
|
1874 ;; #### I really need to flesh out the object
|
|
1875 ;; hierarchy better to avoid these kludges.
|
|
1876 (lambda ()
|
|
1877 (save-excursion
|
|
1878 (set-buffer standard-output)
|
|
1879 (setq truncate-lines t)))))
|
|
1880 (unwind-protect
|
|
1881 (progn
|
|
1882 (add-hook 'minibuffer-setup-hook rfhookfun)
|
|
1883 (add-hook 'completion-setup-hook rfcshookfun)
|
|
1884 (read-file-name-2 history prompt dir default
|
|
1885 must-match initial-contents
|
|
1886 completer))
|
|
1887 (remove-hook 'minibuffer-setup-hook rfhookfun)
|
|
1888 (remove-hook 'completion-setup-hook rfcshookfun))))
|
|
1889 (delete-frame frame)
|
|
1890 (kill-buffer filebuf)
|
|
1891 (kill-buffer butbuff)
|
|
1892 (and dirbuff (kill-buffer dirbuff)))))
|
|
1893
|
|
1894 (defun read-face (prompt &optional must-match)
|
|
1895 "Read the name of a face from the minibuffer and return it as a symbol."
|
|
1896 (intern (completing-read prompt obarray 'find-face must-match)))
|
|
1897
|
|
1898 ;; #### - wrong place for this variable and function? At some point, we'll
|
|
1899 ;; have ansi color on ttys and so this ought to be here, but the x-specific
|
|
1900 ;; completion stuff should probably move.
|
|
1901
|
|
1902 ;; Ben wanted all of the possibilities from the `configure' script used
|
|
1903 ;; here, but I think this is way too many. I already trimmed the R4 variants
|
|
1904 ;; and a few obvious losers from the list. --Stig
|
|
1905 (defvar x-library-search-path '("/usr/X11R6/lib/X11/"
|
|
1906 "/usr/X11R5/lib/X11/"
|
|
1907 "/usr/lib/X11R6/X11/"
|
|
1908 "/usr/lib/X11R5/X11/"
|
|
1909 "/usr/local/X11R6/lib/X11/"
|
|
1910 "/usr/local/X11R5/lib/X11/"
|
|
1911 "/usr/local/lib/X11R6/X11/"
|
|
1912 "/usr/local/lib/X11R5/X11/"
|
|
1913 "/usr/X11/lib/X11/"
|
|
1914 "/usr/lib/X11/"
|
|
1915 "/usr/local/lib/X11/"
|
|
1916 "/usr/X386/lib/X11/"
|
|
1917 "/usr/x386/lib/X11/"
|
|
1918 "/usr/XFree86/lib/X11/"
|
|
1919 "/usr/unsupported/lib/X11/"
|
|
1920 "/usr/athena/lib/X11/"
|
|
1921 "/usr/local/x11r5/lib/X11/"
|
|
1922 "/usr/lpp/Xamples/lib/X11/"
|
|
1923 "/usr/openwin/lib/X11/"
|
|
1924 "/usr/openwin/share/lib/X11/")
|
|
1925 "Search path used by `read-color' to find rgb.txt.")
|
|
1926
|
|
1927 (defvar read-color-completion-table)
|
|
1928
|
|
1929 (defun read-color-completion-table ()
|
|
1930 (if (boundp 'read-color-completion-table)
|
|
1931 read-color-completion-table
|
|
1932 (let ((rgb-file (locate-file "rgb.txt" x-library-search-path))
|
|
1933 clist color p)
|
|
1934 (if (not rgb-file)
|
|
1935 ;; prevents multiple searches for rgb.txt if we can't find it
|
|
1936 (setq read-color-completion-table nil)
|
|
1937 (save-excursion
|
|
1938 (set-buffer (get-buffer-create " *colors*"))
|
|
1939 (reset-buffer (current-buffer))
|
|
1940 (insert-file-contents rgb-file)
|
|
1941 (while (not (eobp))
|
|
1942 ;; skip over comments
|
|
1943 (while (looking-at "^!")
|
|
1944 (end-of-line)
|
|
1945 (forward-char 1))
|
|
1946 (skip-chars-forward "0-9 \t")
|
|
1947 (setq p (point))
|
|
1948 (end-of-line)
|
|
1949 (setq color (buffer-substring p (point))
|
|
1950 clist (cons (list color) clist))
|
|
1951 ;; Ugh. If we want to be able to complete the lowercase form
|
|
1952 ;; of the color name, we need to add it twice! Yuck.
|
|
1953 (let ((dcase (downcase color)))
|
|
1954 (or (string= dcase color)
|
|
1955 (setq clist (cons (list dcase) clist))))
|
|
1956 (forward-char 1))
|
|
1957 (kill-buffer (current-buffer))))
|
|
1958 (setq read-color-completion-table clist)
|
|
1959 read-color-completion-table)))
|
|
1960
|
|
1961 (defun read-color (prompt &optional must-match initial-contents)
|
|
1962 "Read the name of a color from the minibuffer.
|
|
1963 Uses `x-library-search-path' to find rgb.txt in order to build a completion
|
|
1964 table."
|
|
1965 (completing-read prompt (read-color-completion-table) nil
|
|
1966 (and (read-color-completion-table) must-match)
|
|
1967 initial-contents))
|
|
1968
|
|
1969
|
|
1970 ;; #### The doc string for read-non-nil-coding system gets lost if we
|
|
1971 ;; only include these if the mule feature is present. Strangely,
|
|
1972 ;; read-coding-system doesn't.
|
|
1973
|
|
1974 ;;(if (featurep 'mule)
|
|
1975
|
|
1976 (defun read-coding-system (prompt)
|
|
1977 "Read a coding-system (or nil) from the minibuffer.
|
|
1978 Prompting with string PROMPT."
|
|
1979 (intern (completing-read prompt obarray 'find-coding-system t)))
|
|
1980
|
|
1981 (defun read-non-nil-coding-system (prompt)
|
|
1982 "Read a non-nil coding-system from the minibuffer.
|
|
1983 Prompt with string PROMPT."
|
|
1984 (let ((retval (intern "")))
|
|
1985 (while (= 0 (length (symbol-name retval)))
|
|
1986 (setq retval (intern (completing-read prompt obarray
|
|
1987 'find-coding-system
|
|
1988 t))))
|
|
1989 retval))
|
|
1990
|
|
1991 ;;) ;; end of (featurep 'mule)
|
|
1992
|
|
1993
|
|
1994
|
|
1995 (defvar force-dialog-box-use nil
|
|
1996 "If non-nil, always use a dialog box for asking questions, if possible.
|
|
1997 You should *bind* this, not set it. This is useful if you're doing
|
|
1998 something mousy but which wasn't actually invoked using the mouse.")
|
|
1999
|
|
2000 ;; We include this here rather than dialog.el so it is defined
|
|
2001 ;; even when dialog boxes are not present.
|
|
2002 (defun should-use-dialog-box-p ()
|
|
2003 "If non-nil, questions should be asked with a dialog box instead of the
|
|
2004 minibuffer. This looks at `last-command-event' to see if it was a mouse
|
|
2005 event, and checks whether dialog-support exists and the current device
|
70
|
2006 supports dialog boxes."
|
0
|
2007 (and (featurep 'dialog)
|
|
2008 (device-on-window-system-p)
|
|
2009 (or force-dialog-box-use
|
|
2010 (button-press-event-p last-command-event)
|
|
2011 (button-release-event-p last-command-event)
|
|
2012 (misc-user-event-p last-command-event))))
|