1 ;;; minibuf.el --- Minibuffer functions for XEmacs
3 ;; Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Tinker Systems
5 ;; Copyright (C) 1995, 1996 Ben Wing
7 ;; Author: Richard Mlynarik
9 ;; Maintainer: XEmacs Development Team
10 ;; Keywords: internal, dumped
12 ;; This file is part of XEmacs.
14 ;; XEmacs is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; XEmacs is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with XEmacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;;; Synched up with: all the minibuffer history stuff is synched with
30 ;;; 19.30. Not sure about the rest.
34 ;; This file is dumped with XEmacs.
36 ;; Written by Richard Mlynarik 2-Oct-92
38 ;; 06/11/1997 - Use char-(after|before) instead of
39 ;; (following|preceding)-char. -slb
43 (defgroup minibuffer nil
44 "Controling the behavior of the minibuffer."
48 (defcustom insert-default-directory t
49 "*Non-nil means when reading a filename start with default dir in minibuffer."
53 (defcustom minibuffer-history-uniquify t
54 "*Non-nil means when adding an item to a minibuffer history, remove
55 previous occurances of the same item from the history list first,
56 rather than just consing the new element onto the front of the list."
60 (defvar minibuffer-completion-table nil
61 "Alist or obarray used for completion in the minibuffer.
62 This becomes the ALIST argument to `try-completion' and `all-completions'.
64 The value may alternatively be a function, which is given three arguments:
65 STRING, the current buffer contents;
66 PREDICATE, the predicate for filtering possible matches;
67 CODE, which says what kind of things to do.
68 CODE can be nil, t or `lambda'.
69 nil means to return the best completion of STRING, nil if there is none,
70 or t if it is already a unique completion.
71 t means to return a list of all possible completions of STRING.
72 `lambda' means to return t if STRING is a valid completion as it stands.")
74 (defvar minibuffer-completion-predicate nil
75 "Within call to `completing-read', this holds the PREDICATE argument.")
77 (defvar minibuffer-completion-confirm nil
78 "Non-nil => demand confirmation of completion before exiting minibuffer.")
80 (defvar minibuffer-confirm-incomplete nil
81 "If true, then in contexts where completing-read allows answers which
82 are not valid completions, an extra RET must be typed to confirm the
83 response. This is helpful for catching typos, etc.")
85 (defcustom completion-auto-help t
86 "*Non-nil means automatically provide help for invalid completion input."
90 (defcustom enable-recursive-minibuffers nil
91 "*Non-nil means to allow minibuffer commands while in the minibuffer.
92 More precisely, this variable makes a difference when the minibuffer window
93 is the selected window. If you are in some other window, minibuffer commands
94 are allowed even if a minibuffer is active."
98 (defcustom minibuffer-max-depth 1
99 ;; See comment in #'minibuffer-max-depth-exceeded
100 "*Global maximum number of minibuffers allowed;
101 compare to enable-recursive-minibuffers, which is only consulted when the
102 minibuffer is reinvoked while it is the selected window."
103 :type '(choice integer
104 (const :tag "Indefinite" nil))
107 ;; Moved to C. The minibuffer prompt must be setup before this is run
108 ;; and that can only be done from the C side.
109 ;(defvar minibuffer-setup-hook nil
110 ; "Normal hook run just after entry to minibuffer.")
112 (defvar minibuffer-exit-hook nil
113 "Normal hook run just after exit from minibuffer.")
115 (defvar minibuffer-help-form nil
116 "Value that `help-form' takes on inside the minibuffer.")
118 (defvar minibuffer-default nil
119 "Default value for minibuffer input.")
121 (defvar minibuffer-local-map
122 (let ((map (make-sparse-keymap 'minibuffer-local-map)))
124 "Default keymap to use when reading from the minibuffer.")
126 (defvar minibuffer-local-completion-map
127 (let ((map (make-sparse-keymap 'minibuffer-local-completion-map)))
128 (set-keymap-parents map (list minibuffer-local-map))
130 "Local keymap for minibuffer input with completion.")
132 (defvar minibuffer-local-must-match-map
133 (let ((map (make-sparse-keymap 'minibuffer-must-match-map)))
134 (set-keymap-parents map (list minibuffer-local-completion-map))
136 "Local keymap for minibuffer input with completion, for exact match.")
138 ;; (define-key minibuffer-local-map "\C-g" 'abort-recursive-edit)
139 (define-key minibuffer-local-map "\C-g" 'minibuffer-keyboard-quit) ;; moved here from pending-del.el
140 (define-key minibuffer-local-map "\r" 'exit-minibuffer)
141 (define-key minibuffer-local-map "\n" 'exit-minibuffer)
143 ;; Historical crock. Unused by anything but user code, if even that
144 ;(defvar minibuffer-local-ns-map
145 ; (let ((map (make-sparse-keymap 'minibuffer-local-ns-map)))
146 ; (set-keymap-parents map (list minibuffer-local-map))
148 ; "Local keymap for the minibuffer when spaces are not allowed.")
149 ;(define-key minibuffer-local-ns-map [space] 'exit-minibuffer)
150 ;(define-key minibuffer-local-ns-map [tab] 'exit-minibuffer)
151 ;(define-key minibuffer-local-ns-map [?\?] 'self-insert-and-exit)
153 (define-key minibuffer-local-completion-map "\t" 'minibuffer-complete)
154 (define-key minibuffer-local-completion-map " " 'minibuffer-complete-word)
155 (define-key minibuffer-local-completion-map "?" 'minibuffer-completion-help)
156 (define-key minibuffer-local-must-match-map "\r" 'minibuffer-complete-and-exit)
157 (define-key minibuffer-local-must-match-map "\n" 'minibuffer-complete-and-exit)
159 (define-key minibuffer-local-map "\M-n" 'next-history-element)
160 (define-key minibuffer-local-map "\M-p" 'previous-history-element)
161 (define-key minibuffer-local-map '[next] "\M-n")
162 (define-key minibuffer-local-map '[prior] "\M-p")
163 (define-key minibuffer-local-map "\M-r" 'previous-matching-history-element)
164 (define-key minibuffer-local-map "\M-s" 'next-matching-history-element)
165 (define-key minibuffer-local-must-match-map [next]
166 'next-complete-history-element)
167 (define-key minibuffer-local-must-match-map [prior]
168 'previous-complete-history-element)
170 ;; This is an experiment--make up and down arrows do history.
171 (define-key minibuffer-local-map [up] 'previous-history-element)
172 (define-key minibuffer-local-map [down] 'next-history-element)
173 (define-key minibuffer-local-completion-map [up] 'previous-history-element)
174 (define-key minibuffer-local-completion-map [down] 'next-history-element)
175 (define-key minibuffer-local-must-match-map [up] 'previous-history-element)
176 (define-key minibuffer-local-must-match-map [down] 'next-history-element)
178 (defvar read-expression-map (let ((map (make-sparse-keymap
179 'read-expression-map)))
180 (set-keymap-parents map
181 (list minibuffer-local-map))
182 (define-key map "\M-\t" 'lisp-complete-symbol)
184 "Minibuffer keymap used for reading Lisp expressions.")
186 (defvar read-shell-command-map
187 (let ((map (make-sparse-keymap 'read-shell-command-map)))
188 (set-keymap-parents map (list minibuffer-local-map))
189 (define-key map "\t" 'comint-dynamic-complete)
190 (define-key map "\M-\t" 'comint-dynamic-complete)
191 (define-key map "\M-?" 'comint-dynamic-list-completions)
193 "Minibuffer keymap used by shell-command and related commands.")
195 (defcustom use-dialog-box t
196 "*Variable controlling usage of the dialog box.
197 If nil, the dialog box will never be used, even in response to mouse events."
201 (defcustom minibuffer-electric-file-name-behavior t
202 "*If non-nil, slash and tilde in certain places cause immediate deletion.
203 These are the same places where this behavior would occur later on anyway,
204 in `substitute-in-file-name'."
208 ;; originally by Stig@hackvan.com
209 (defun minibuffer-electric-separator ()
211 (let ((c last-command-char))
212 (and minibuffer-electric-file-name-behavior
213 (eq c directory-sep-char)
214 (eq c (char-before (point)))
216 (goto-char (point-min))
217 (and (looking-at "/.+:~?[^/]*/.+")
218 (re-search-forward "^/.+:~?[^/]*" nil t)
220 (delete-region (point) (point-max))
223 (goto-char (point-min))
224 (and (looking-at ".+://[^/]*/.+")
225 (re-search-forward "^.+:/" nil t)
227 (delete-region (point) (point-max))
229 ;; permit `//hostname/path/to/file'
230 (not (eq (point) (1+ (point-min))))
231 ;; permit `http://url/goes/here'
232 (or (not (eq ?: (char-after (- (point) 2))))
233 (eq ?/ (char-after (point-min))))
234 (delete-region (point-min) (point)))
237 (defun minibuffer-electric-tilde ()
239 (and minibuffer-electric-file-name-behavior
240 (eq directory-sep-char (char-before (point)))
241 ;; permit URL's with //, for e.g. http://hostname/~user
242 (not (save-excursion (search-backward "//" nil t)))
243 (delete-region (point-min) (point)))
247 (defvar read-file-name-map
248 (let ((map (make-sparse-keymap 'read-file-name-map)))
249 (set-keymap-parents map (list minibuffer-local-completion-map))
250 (define-key map (vector directory-sep-char) 'minibuffer-electric-separator)
251 (define-key map "~" 'minibuffer-electric-tilde)
255 (defvar read-file-name-must-match-map
256 (let ((map (make-sparse-keymap 'read-file-name-map)))
257 (set-keymap-parents map (list minibuffer-local-must-match-map))
258 (define-key map (vector directory-sep-char) 'minibuffer-electric-separator)
259 (define-key map "~" 'minibuffer-electric-tilde)
263 (defun minibuffer-keyboard-quit ()
264 "Abort recursive edit.
265 If `zmacs-regions' is true, and the zmacs region is active in this buffer,
266 then this key deactivates the region without beeping."
268 (if (and (region-active-p)
269 (eq (current-buffer) (zmacs-region-buffer)))
270 ;; pseudo-zmacs compatibility: don't beep if this ^G is simply
271 ;; deactivating the region. If it is inactive, beep.
273 (abort-recursive-edit)))
275 ;;;; Guts of minibuffer invocation
277 ;;#### The only things remaining in C are
278 ;; "Vminibuf_prompt" and the display junk
279 ;; "minibuf_prompt_width" and "minibuf_prompt_pix_width"
280 ;; Also "active_frame", though I suspect I could already
281 ;; hack that in Lisp if I could make any sense of the
282 ;; complete mess of frame/frame code in XEmacs.
283 ;; Vminibuf_prompt could easily be made Lisp-bindable.
284 ;; I suspect that minibuf_prompt*_width are actually recomputed
285 ;; by redisplay as needed -- or could be arranged to be so --
286 ;; and that there could be need for read-minibuffer-internal to
287 ;; save and restore them.
288 ;;#### The only other thing which read-from-minibuffer-internal does
289 ;; which we can't presently do in Lisp is move the frame cursor
290 ;; to the start of the minibuffer line as it returns. This is
291 ;; a rather nice touch and should be preserved -- probably by
292 ;; providing some Lisp-level mechanism (extension to cursor-in-echo-area ?)
296 ;; Like reset_buffer in FSF's buffer.c
297 ;; (Except that kill-all-local-variables doesn't nuke 'permanent-local
298 ;; variables -- we preserve them, reset_buffer doesn't.)
299 (defun reset-buffer (buffer)
300 (with-current-buffer buffer
301 ;(if (fboundp 'unlock-buffer) (unlock-buffer))
302 (kill-all-local-variables)
303 (setq buffer-read-only nil)
304 ;; don't let read only text yanked into the minibuffer
305 ;; permanently wedge it.
306 (make-local-variable 'inhibit-read-only)
307 (setq inhibit-read-only t)
309 ;(setq default-directory nil)
310 (setq buffer-file-name nil)
311 (setq buffer-file-truename nil)
312 (set-buffer-modified-p nil)
313 (setq buffer-backed-up nil)
314 (setq buffer-auto-save-file-name nil)
315 (set-buffer-dedicated-frame buffer nil)
318 (defvar minibuffer-history-variable 'minibuffer-history
319 "History list symbol to add minibuffer values to.
320 Each minibuffer output is added with
321 (set minibuffer-history-variable
322 (cons STRING (symbol-value minibuffer-history-variable)))")
323 (defvar minibuffer-history-position)
326 (defvar initial-minibuffer-history-position)
327 (defvar current-minibuffer-contents)
328 (defvar current-minibuffer-point)
330 (defcustom minibuffer-history-minimum-string-length nil
331 "*If this variable is non-nil, a string will not be added to the
332 minibuffer history if its length is less than that value."
333 :type '(choice (const :tag "Any" nil)
337 (define-error 'input-error "Keyboard input error")
339 (put 'input-error 'display-error
340 #'(lambda (error-object stream)
341 (princ (cadr error-object) stream)))
343 (defun read-from-minibuffer (prompt &optional initial-contents
348 "Read a string from the minibuffer, prompting with string PROMPT.
349 If optional second arg INITIAL-CONTENTS is non-nil, it is a string
350 to be inserted into the minibuffer before reading input.
351 If INITIAL-CONTENTS is (STRING . POSITION), the initial input
352 is STRING, but point is placed POSITION characters into the string.
353 Third arg KEYMAP is a keymap to use while reading;
354 if omitted or nil, the default is `minibuffer-local-map'.
355 If fourth arg READ is non-nil, then interpret the result as a lisp object
356 and return that object:
357 in other words, do `(car (read-from-string INPUT-STRING))'
358 Fifth arg HISTORY, if non-nil, specifies a history list
359 and optionally the initial position in the list.
360 It can be a symbol, which is the history list variable to use,
361 or it can be a cons cell (HISTVAR . HISTPOS).
362 In that case, HISTVAR is the history list variable to use,
363 and HISTPOS is the initial position (the position in the list
364 which INITIAL-CONTENTS corresponds to).
365 If HISTORY is `t', no history will be recorded.
366 Positions are counted starting from 1 at the beginning of the list.
367 Sixth arg ABBREV-TABLE, if non-nil, becomes the value of `local-abbrev-table'
370 See also the variable completion-highlight-first-word-only for control over
372 (if (and (not enable-recursive-minibuffers)
373 (> (minibuffer-depth) 0)
374 (eq (selected-window) (minibuffer-window)))
375 (error "Command attempted to use minibuffer while in minibuffer"))
377 (if (and minibuffer-max-depth
378 (> minibuffer-max-depth 0)
379 (>= (minibuffer-depth) minibuffer-max-depth))
380 (minibuffer-max-depth-exceeded))
382 ;; catch this error before the poor user has typed something...
384 (if (symbolp history)
386 (error "History list %S is unbound" history))
387 (or (boundp (car history))
388 (error "History list %S is unbound" (car history)))))
392 ;; XEmacs in -batch mode calls minibuffer: print the prompt.
393 (message "%s" (gettext prompt))
396 ;;#### Should this even be falling though to the code below?
397 ;;#### How does this stuff work now, anyway?
399 (let* ((dir default-directory)
400 (owindow (selected-window))
401 (oframe (selected-frame))
402 (window (minibuffer-window))
403 (buffer (if (eq (minibuffer-depth) 0)
404 (window-buffer window)
405 (get-buffer-create (format " *Minibuf-%d"
406 (minibuffer-depth)))))
407 (frame (window-frame window))
408 (mconfig (if (eq frame (selected-frame))
409 nil (current-window-configuration frame)))
410 (oconfig (current-window-configuration))
411 ;; dynamic scope sucks sucks sucks sucks sucks sucks.
412 ;; `M-x doctor' makes history a local variable, and thus
413 ;; our binding above is buffer-local and doesn't apply
414 ;; once we switch buffers!!!! We demand better scope!
418 (set-buffer (reset-buffer buffer))
419 (setq default-directory dir)
420 (make-local-variable 'print-escape-newlines)
421 (setq print-escape-newlines t)
422 (make-local-variable 'current-minibuffer-contents)
423 (make-local-variable 'current-minibuffer-point)
424 (make-local-variable 'initial-minibuffer-history-position)
425 (setq current-minibuffer-contents ""
426 current-minibuffer-point 1)
427 (if (not minibuffer-smart-completion-tracking-behavior)
429 (make-local-variable 'mode-motion-hook)
432 (setq mode-motion-hook 'minibuffer-smart-mouse-tracker))
433 (make-local-variable 'mouse-track-click-hook)
434 (add-hook 'mouse-track-click-hook
435 'minibuffer-smart-maybe-select-highlighted-completion))
436 (set-window-buffer window buffer)
437 (select-window window)
438 (set-window-hscroll window 0)
439 (buffer-enable-undo buffer)
442 (if (consp initial-contents)
444 (insert (car initial-contents))
445 (goto-char (1+ (cdr initial-contents)))
446 (setq current-minibuffer-contents (car initial-contents)
447 current-minibuffer-point (cdr initial-contents)))
448 (insert initial-contents)
449 (setq current-minibuffer-contents initial-contents
450 current-minibuffer-point (point))))
451 (use-local-map (help-keymap-with-help-key
452 (or keymap minibuffer-local-map)
453 minibuffer-help-form))
454 (let ((mouse-grabbed-buffer
455 (and minibuffer-smart-completion-tracking-behavior
457 (current-prefix-arg current-prefix-arg)
458 ;; (help-form minibuffer-help-form)
459 (minibuffer-history-variable (cond ((not _history_)
465 (minibuffer-history-position (cond ((consp _history_)
469 (minibuffer-scroll-window owindow))
470 (setq initial-minibuffer-history-position
471 minibuffer-history-position)
473 (setq local-abbrev-table abbrev-table
475 ;; This is now run from read-minibuffer-internal
476 ;(if minibuffer-setup-hook
477 ; (run-hooks 'minibuffer-setup-hook))
481 (if (> (recursion-depth) (minibuffer-depth))
482 (let ((standard-output t)
484 (read-minibuffer-internal prompt))
485 (read-minibuffer-internal prompt))))
486 ;; Translate an "abort" (throw 'exit 't)
490 (let* ((val (progn (set-buffer buffer)
491 (if minibuffer-exit-hook
492 (run-hooks 'minibuffer-exit-hook))
498 (let ((v (read-from-string val)))
499 (if (< (cdr v) (length val))
501 (or (string-match "[ \t\n]*\\'" val (cdr v))
502 (error "Trailing garbage following expression"))))
504 ;; total total kludge
505 (if (stringp v) (setq v (list 'quote v)))
509 '(input-error "End of input before end of expression")))
510 (error (setq err e))))
511 ;; Add the value to the appropriate history list unless
512 ;; it's already the most recent element, or it's only
513 ;; two characters long.
514 (if (and (symbolp minibuffer-history-variable)
515 (boundp minibuffer-history-variable))
516 (let ((list (symbol-value minibuffer-history-variable)))
519 (and list (equal histval (car list)))
521 minibuffer-history-minimum-string-length
523 minibuffer-history-minimum-string-length))
524 (set minibuffer-history-variable
525 (if minibuffer-history-uniquify
526 (cons histval (remove histval list))
527 (cons histval list))))))
528 (if err (signal (car err) (cdr err)))
530 ;; stupid display code requires this for some reason
532 (buffer-disable-undo buffer)
533 (setq buffer-read-only nil)
536 ;; restore frame configurations
537 (if (and mconfig (frame-live-p oframe)
538 (eq frame (selected-frame)))
539 ;; if we changed frames (due to surrogate minibuffer),
540 ;; and we're still on the new frame, go back to the old one.
541 (select-frame oframe))
542 (if mconfig (set-window-configuration mconfig))
543 (set-window-configuration oconfig))))
546 (defun minibuffer-max-depth-exceeded ()
548 ;; This signals an error if an Nth minibuffer is invoked while N-1 are
549 ;; already active, whether the minibuffer window is selected or not.
550 ;; Since, under X, it's easy to jump out of the minibuffer (by doing M-x,
551 ;; getting distracted, and clicking elsewhere) many many novice users have
552 ;; had the problem of having multiple minibuffers build up, even to the
553 ;; point of exceeding max-lisp-eval-depth. Since the variable
554 ;; enable-recursive-minibuffers historically/crockishly is only consulted
555 ;; when the minibuffer is currently active (like typing M-x M-x) it doesn't
556 ;; help in this situation.
558 ;; This routine also offers to edit .emacs for you to get rid of this
559 ;; complaint, like `disabled' commands do, since it's likely that non-novice
560 ;; users will be annoyed by this change, so we give them an easy way to get
561 ;; rid of it forever.
563 (beep t 'minibuffer-limit-exceeded)
565 "Minibuffer already active: abort it with `^]', enable new one with `n': ")
566 (let ((char (let ((cursor-in-echo-area t)) ; #### doesn't always work??
571 ((y-or-n-p "Enable recursive minibuffers for other sessions too? ")
572 ;; This is completely disgusting, but it's basically what novice.el
573 ;; does. This kind of thing should be generalized.
574 (setq minibuffer-max-depth nil)
578 (substitute-in-file-name custom-file)))
579 (goto-char (point-min))
580 (if (re-search-forward
581 "^(setq minibuffer-max-depth \\([0-9]+\\|'?nil\\|'?()\\))\n"
583 (delete-region (match-beginning 0 ) (match-end 0))
584 ;; Must have been disabled by default.
585 (goto-char (point-max)))
586 (insert"\n(setq minibuffer-max-depth nil)\n")
588 (message "Multiple minibuffers enabled")
591 (abort-recursive-edit))
593 (error "Minibuffer already active")))))
596 ;;;; Guts of minibuffer completion
599 ;; Used by minibuffer-do-completion
600 (defvar last-exact-completion)
602 (defun temp-minibuffer-message (m)
603 (let ((savemax (point-max)))
605 (goto-char (point-max))
608 (let ((inhibit-quit t))
610 (delete-region savemax (point-max))
611 ;; If the user types a ^G while we're in sit-for, then quit-flag
612 ;; gets set. In this case, we want that ^G to be interpreted
613 ;; as a normal character, and act just like typeahead.
614 (if (and quit-flag (not unread-command-event))
615 (setq unread-command-event (character-to-event (quit-char))
619 ;; Determines whether buffer-string is an exact completion
620 (defun exact-minibuffer-completion-p (buffer-string)
621 (cond ((not minibuffer-completion-table)
624 ((vectorp minibuffer-completion-table)
625 (let ((tem (intern-soft buffer-string
626 minibuffer-completion-table)))
628 (and (string-equal buffer-string "nil")
629 ;; intern-soft loses for 'nil
631 (mapatoms #'(lambda (s)
636 minibuffer-completion-table)
638 (if minibuffer-completion-predicate
639 (funcall minibuffer-completion-predicate
643 ((and (consp minibuffer-completion-table)
644 ;;#### Emacs-Lisp truly sucks!
645 ;; lambda, autoload, etc
646 (not (symbolp (car minibuffer-completion-table))))
647 (if (not completion-ignore-case)
648 (assoc buffer-string minibuffer-completion-table)
649 (let ((s (upcase buffer-string))
650 (tail minibuffer-completion-table)
653 (setq tem (car (car tail)))
654 (if (or (equal tem buffer-string)
656 (if tem (equal (upcase tem) s)))
659 (setq tail (cdr tail))))
662 (funcall minibuffer-completion-table
664 minibuffer-completion-predicate
668 ;; 0 'none no possible completion
669 ;; 1 'unique was already an exact and unique completion
670 ;; 3 'exact was already an exact (but nonunique) completion
671 ;; NOT USED 'completed-exact-unique completed to an exact and completion
672 ;; 4 'completed-exact completed to an exact (but nonunique) completion
673 ;; 5 'completed some completion happened
674 ;; 6 'uncompleted no completion happened
675 (defun minibuffer-do-completion-1 (buffer-string completion)
676 (cond ((not completion)
679 ;; exact and unique match
682 ;; It did find a match. Do we match some possibility exactly now?
683 (let ((completedp (not (string-equal completion buffer-string))))
686 ;; Some completion happened
689 (setq buffer-string completion)))
690 (if (exact-minibuffer-completion-p buffer-string)
691 ;; An exact completion was possible
693 ;; Since no callers need to know the difference, don't bother
694 ;; with this (potentially expensive) discrimination.
695 ;; (if (eq (try-completion completion
696 ;; minibuffer-completion-table
697 ;; minibuffer-completion-predicate)
699 ;; 'completed-exact-unique
703 ;; Not an exact match
709 (defun minibuffer-do-completion (buffer-string)
710 (let* ((completion (try-completion buffer-string
711 minibuffer-completion-table
712 minibuffer-completion-predicate))
713 (status (minibuffer-do-completion-1 buffer-string completion))
714 (last last-exact-completion))
715 (setq last-exact-completion nil)
716 (cond ((eq status 'none)
718 (ding nil 'no-completion)
719 (temp-minibuffer-message " [No match]"))
723 ;; It did find a match. Do we match some possibility exactly now?
724 (if (not (string-equal completion buffer-string))
726 ;; Some completion happened
729 (setq buffer-string completion)))
730 (cond ((eq status 'exact)
731 ;; If the last exact completion and this one were
732 ;; the same, it means we've already given a
733 ;; "Complete but not unique" message and that the
734 ;; user's hit TAB again, so now we give help.
735 (setq last-exact-completion completion)
736 (if (equal buffer-string last)
737 (minibuffer-completion-help)))
738 ((eq status 'uncompleted)
739 (if completion-auto-help
740 (minibuffer-completion-help)
741 (temp-minibuffer-message " [Next char not unique]")))
749 (defun completing-read (prompt table
750 &optional predicate require-match
751 initial-contents history default)
752 "Read a string in the minibuffer, with completion.
753 Args: PROMPT, TABLE, PREDICATE, REQUIRE-MATCH, INITIAL-CONTENTS, HISTORY.
754 PROMPT is a string to prompt with; normally it ends in a colon and a space.
755 TABLE is an alist whose elements' cars are strings, or an obarray.
756 PREDICATE limits completion to a subset of TABLE.
757 See `try-completion' for more details on completion, TABLE, and PREDICATE.
758 If REQUIRE-MATCH is non-nil, the user is not allowed to exit unless
759 the input is (or completes to) an element of TABLE or is null.
760 If it is also not t, Return does not exit if it does non-null completion.
761 If INITIAL-CONTENTS is non-nil, insert it in the minibuffer initially.
762 If it is (STRING . POSITION), the initial input
763 is STRING, but point is placed POSITION characters into the string.
764 HISTORY, if non-nil, specifies a history list
765 and optionally the initial position in the list.
766 It can be a symbol, which is the history list variable to use,
767 or it can be a cons cell (HISTVAR . HISTPOS).
768 In that case, HISTVAR is the history list variable to use,
769 and HISTPOS is the initial position (the position in the list
770 which INITIAL-CONTENTS corresponds to).
771 If HISTORY is `t', no history will be recorded.
772 Positions are counted starting from 1 at the beginning of the list.
773 DEFAULT, if non-nil, is the default value.
774 Completion ignores case if the ambient value of
775 `completion-ignore-case' is non-nil."
776 (let ((minibuffer-completion-table table)
777 (minibuffer-completion-predicate predicate)
778 (minibuffer-completion-confirm (if (eq require-match 't) nil t))
779 (last-exact-completion nil)
781 (setq ret (read-from-minibuffer prompt
783 (if (not require-match)
784 minibuffer-local-completion-map
785 minibuffer-local-must-match-map)
788 (if (and (string= ret "")
794 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
795 ;;;; Minibuffer completion commands ;;;;
796 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
799 (defun minibuffer-complete ()
800 "Complete the minibuffer contents as far as possible.
801 Return nil if there is no valid completion, else t.
802 If no characters can be completed, display a list of possible completions.
803 If you repeat this command after it displayed such a list,
804 scroll the window of possible completions."
806 ;; If the previous command was not this, then mark the completion
808 (or (eq last-command this-command)
809 (setq minibuffer-scroll-window nil))
810 (let ((window minibuffer-scroll-window))
811 (if (and window (windowp window) (window-buffer window)
812 (buffer-name (window-buffer window)))
813 ;; If there's a fresh completion window with a live buffer
814 ;; and this command is repeated, scroll that window.
815 (let ((obuf (current-buffer)))
818 (set-buffer (window-buffer window))
819 (if (pos-visible-in-window-p (point-max) window)
820 ;; If end is in view, scroll up to the beginning.
821 (set-window-start window (point-min))
822 ;; Else scroll down one frame.
823 (scroll-other-window)))
826 (let ((status (minibuffer-do-completion (buffer-string))))
827 (if (eq status 'none)
830 (cond ((eq status 'unique)
831 (temp-minibuffer-message
832 " [Sole completion]"))
834 (temp-minibuffer-message
835 " [Complete, but not unique]")))
839 (defun minibuffer-complete-and-exit ()
840 "Complete the minibuffer contents, and maybe exit.
841 Exit if the name is valid with no completion needed.
842 If name was completed to a valid match,
843 a repetition of this command will exit."
845 (if (= (point-min) (point-max))
846 ;; Crockishly allow user to specify null string
848 (let ((buffer-string (buffer-string)))
849 ;; Short-cut -- don't call minibuffer-do-completion if we already
850 ;; have an (possibly nonunique) exact completion.
851 (if (exact-minibuffer-completion-p buffer-string)
853 (let ((status (minibuffer-do-completion buffer-string)))
854 (if (or (eq status 'unique)
856 (if (or (eq status 'completed-exact)
857 (eq status 'completed-exact-unique))
858 (if minibuffer-completion-confirm
859 (progn (temp-minibuffer-message " [Confirm]")
862 (throw 'exit nil)))))
865 (defun self-insert-and-exit ()
866 "Terminate minibuffer input."
868 (self-insert-command 1)
871 (defun exit-minibuffer ()
872 "Terminate this minibuffer argument.
873 If minibuffer-confirm-incomplete is true, and we are in a completing-read
874 of some kind, and the contents of the minibuffer is not an existing
875 completion, requires an additional RET before the minibuffer will be exited
876 \(assuming that RET was the character that invoked this command:
877 the character in question must be typed again)."
879 (if (not minibuffer-confirm-incomplete)
881 (let ((buffer-string (buffer-string)))
882 (if (exact-minibuffer-completion-p buffer-string)
884 (let ((completion (if (not minibuffer-completion-table)
886 (try-completion buffer-string
887 minibuffer-completion-table
888 minibuffer-completion-predicate))))
889 (if (or (eq completion 't)
890 ;; Crockishly allow user to specify null string
891 (string-equal buffer-string ""))
893 (if completion ;; rewritten for I18N3 snarfing
894 (temp-minibuffer-message " [incomplete; confirm]")
895 (temp-minibuffer-message " [no completions; confirm]"))
896 (let ((event (let ((inhibit-quit t))
899 (setq quit-flag nil)))))
900 (cond ((equal event last-command-event)
902 ((equal (quit-char) (event-to-character event))
905 (dispatch-event event)))))
907 ;;;; minibuffer-complete-word
910 ;;;#### I think I have done this correctly; it certainly is simpler
911 ;;;#### than what the C code seemed to be trying to do.
912 (defun minibuffer-complete-word ()
913 "Complete the minibuffer contents at most a single word.
914 After one word is completed as much as possible, a space or hyphen
915 is added, provided that matches some possible completion.
916 Return nil if there is no valid completion, else t."
918 (let* ((buffer-string (buffer-string))
919 (completion (try-completion buffer-string
920 minibuffer-completion-table
921 minibuffer-completion-predicate))
922 (status (minibuffer-do-completion-1 buffer-string completion)))
923 (cond ((eq status 'none)
924 (ding nil 'no-completion)
925 (temp-minibuffer-message " [No match]")
928 ;; New message, only in this new Lisp code
929 (temp-minibuffer-message " [Sole completion]")
932 (cond ((or (eq status 'uncompleted)
934 (let ((foo #'(lambda (s)
937 (concat buffer-string s)
938 minibuffer-completion-table
939 minibuffer-completion-predicate)
941 (goto-char (point-max))
946 (char last-command-char))
947 ;; Try to complete by adding a word-delimiter
948 (or (and (characterp char) (> char 0)
949 (funcall foo (char-to-string char)))
950 (and (not (eq char ?\ ))
952 (and (not (eq char ?\-))
955 (if completion-auto-help
956 (minibuffer-completion-help)
957 ;; New message, only in this new Lisp code
958 ;; rewritten for I18N3 snarfing
959 (if (eq status 'exact)
960 (temp-minibuffer-message
961 " [Complete, but not unique]")
962 (temp-minibuffer-message " [Ambiguous]")))
967 ;; First word-break in stuff found by completion
968 (goto-char (point-min))
969 (let ((len (length buffer-string))
971 (if (and (< len (length completion))
976 (upcase (aref buffer-string n))
977 (upcase (aref completion n)))
982 (goto-char (point-min))
984 (re-search-forward "\\W" nil t)))
985 (delete-region (point) (point-max))
986 (goto-char (point-max))))
990 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
991 ;;;; "Smart minibuffer" hackery ;;;;
992 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
994 ;;; ("Kludgy minibuffer hackery" is perhaps a better name)
996 ;; This works by setting `mouse-grabbed-buffer' to the minibuffer,
997 ;; defining button2 in the minibuffer keymap to
998 ;; `minibuffer-smart-select-highlighted-completion', and setting the
999 ;; mode-motion-hook of the minibuffer to `minibuffer-mouse-tracker'.
1000 ;; By setting `mouse-grabbed-buffer', the minibuffer's keymap and
1001 ;; mode-motion-hook apply (for mouse motion and presses) no matter
1002 ;; what buffer the mouse is over. Then, `minibuffer-mouse-tracker'
1003 ;; examines the text under the mouse looking for something that looks
1004 ;; like a completion, and causes it to be highlighted, and
1005 ;; `minibuffer-smart-select-highlighted-completion' looks for a
1006 ;; flagged completion under the mouse and inserts it. This has the
1007 ;; following advantages:
1009 ;; -- filenames and such in any buffer can be inserted by clicking,
1010 ;; not just completions
1012 ;; but the following disadvantages:
1014 ;; -- unless you're aware of the "filename in any buffer" feature,
1015 ;; the fact that strings in arbitrary buffers get highlighted appears
1017 ;; -- mouse motion can cause ange-ftp actions -- bad bad bad.
1019 ;; There's some hackery in minibuffer-mouse-tracker to try to avoid the
1020 ;; ange-ftp stuff, but it doesn't work.
1023 (defcustom minibuffer-smart-completion-tracking-behavior nil
1024 "*If non-nil, look for completions under mouse in all buffers.
1025 This allows you to click on something that looks like a completion
1026 and have it selected, regardless of what buffer it is in.
1028 This is not enabled by default because
1030 -- The \"mysterious\" highlighting in normal buffers is confusing to
1031 people not expecting it, and looks like a bug
1032 -- If ange-ftp is enabled, this tracking sometimes causes ange-ftp
1033 action as a result of mouse motion, which is *bad bad bad*.
1034 Hopefully this bug will be fixed at some point."
1038 (defun minibuffer-smart-mouse-tracker (event)
1039 ;; Used as the mode-motion-hook of the minibuffer window, which is the
1040 ;; value of `mouse-grabbed-buffer' while the minibuffer is active. If
1041 ;; the word under the mouse is a valid minibuffer completion, then it
1044 ;; We do some special voodoo when we're reading a pathname, because
1045 ;; the way filename completion works is funny. Possibly there's some
1046 ;; more general way this could be dealt with...
1048 ;; We do some further voodoo when reading a pathname that is an
1049 ;; ange-ftp or efs path, because causing FTP activity as a result of
1050 ;; mouse motion is a really bad time.
1052 (and minibuffer-smart-completion-tracking-behavior
1054 ;; avoid conflict with display-completion-list extents
1055 (not (extent-at (event-point event)
1056 (event-buffer event)
1058 (let ((filename-kludge-p (eq minibuffer-completion-table
1059 'read-file-name-internal)))
1060 (mode-motion-highlight-internal
1062 #'(lambda () (default-mouse-track-beginning-of-word
1063 (if filename-kludge-p 'nonwhite t)))
1067 (default-mouse-track-end-of-word
1068 (if filename-kludge-p 'nonwhite t))
1069 (if (and (/= p (point)) minibuffer-completion-table)
1070 (setq string (buffer-substring p (point))))
1071 (if (string-match "\\`[ \t\n]*\\'" string)
1073 (if filename-kludge-p
1074 (setq string (minibuffer-smart-select-kludge-filename
1076 ;; try-completion bogusly returns a string even when
1077 ;; that string is complete if that string is also a
1078 ;; prefix for other completions. This means that we
1079 ;; can't just do the obvious thing, (eq t
1080 ;; (try-completion ...)).
1082 (if (and filename-kludge-p
1083 ;; #### evil evil evil evil
1084 (or (and (fboundp 'ange-ftp-ftp-path)
1085 (ange-ftp-ftp-path string))
1086 (and (fboundp 'efs-ftp-path)
1087 (efs-ftp-path string))))
1090 (try-completion string
1091 minibuffer-completion-table
1092 minibuffer-completion-predicate)))
1094 (and (equal comp string)
1095 (or (null minibuffer-completion-predicate)
1097 minibuffer-completion-predicate) ; ???
1098 (funcall minibuffer-completion-predicate
1100 minibuffer-completion-table)
1103 minibuffer-completion-table)
1105 (goto-char p))))))))))
1107 (defun minibuffer-smart-select-kludge-filename (string)
1109 (set-buffer mouse-grabbed-buffer) ; the minibuf
1110 (let ((kludge-string (concat (buffer-string) string)))
1111 (if (or (and (fboundp 'ange-ftp-ftp-path)
1112 (ange-ftp-ftp-path kludge-string))
1113 (and (fboundp 'efs-ftp-path) (efs-ftp-path kludge-string)))
1114 ;; #### evil evil evil, but more so.
1116 (append-expand-filename (buffer-string) string)))))
1118 (defun minibuffer-smart-select-highlighted-completion (event)
1119 "Select the highlighted text under the mouse as a minibuffer response.
1120 When the minibuffer is being used to prompt the user for a completion,
1121 any valid completions which are visible on the frame will highlight
1122 when the mouse moves over them. Clicking \\<minibuffer-local-map>\
1123 \\[minibuffer-smart-select-highlighted-completion] will select the
1124 highlighted completion under the mouse.
1126 If the mouse is clicked while not over a highlighted completion,
1127 then the global binding of \\[minibuffer-smart-select-highlighted-completion] \
1128 will be executed instead. In this\nway you can get at the normal global \
1129 behavior of \\[minibuffer-smart-select-highlighted-completion] as well as
1130 the special minibuffer behavior."
1132 (if minibuffer-smart-completion-tracking-behavior
1133 (minibuffer-smart-select-highlighted-completion-1 event t)
1134 (let ((command (lookup-key global-map
1135 (vector current-mouse-event))))
1136 (if command (call-interactively command)))))
1138 (defun minibuffer-smart-select-highlighted-completion-1 (event global-p)
1139 (let* ((filename-kludge-p (eq minibuffer-completion-table
1140 'read-file-name-internal))
1143 (evpoint (event-point event))
1144 (evextent (and evpoint (extent-at evpoint (event-buffer event)
1147 ;; avoid conflict with display-completion-list extents.
1148 ;; if we find one, do that behavior instead.
1149 (list-mode-item-selected-1 evextent event)
1151 (let* ((buffer (window-buffer (event-window event)))
1152 (p (event-point event))
1153 (extent (and p (extent-at p buffer 'mouse-face))))
1155 (if (not (and (extent-live-p extent)
1156 (eq (extent-object extent) (current-buffer))
1157 (not (extent-detached-p extent))))
1159 ;; ...else user has selected a highlighted completion.
1161 (buffer-substring (extent-start-position extent)
1162 (extent-end-position extent)))
1163 (if filename-kludge-p
1164 (setq completion (minibuffer-smart-select-kludge-filename
1166 ;; remove the extent so that it's not hanging around in
1168 (detach-extent extent)
1169 (set-buffer mouse-grabbed-buffer)
1171 (insert completion))))
1172 ;; we need to execute the command or do the throw outside of the
1174 (cond ((and command-p global-p)
1175 (let ((command (lookup-key global-map
1176 (vector current-mouse-event))))
1178 (call-interactively command)
1179 (if minibuffer-completion-table
1181 "Highlighted words are valid completions. You may select one.")
1182 (error "no completions")))))
1184 ;; things get confused if the minibuffer is terminated while
1186 (select-window (minibuffer-window))
1187 (if (and filename-kludge-p (file-directory-p completion))
1188 ;; if the user clicked middle on a directory name, display the
1189 ;; files in that directory.
1191 (goto-char (point-max))
1192 (minibuffer-completion-help))
1193 ;; otherwise, terminate input
1194 (throw 'exit nil)))))))
1196 (defun minibuffer-smart-maybe-select-highlighted-completion
1197 (event &optional click-count)
1198 "Like minibuffer-smart-select-highlighted-completion but does nothing if
1199 there is no completion (as opposed to executing the global binding). Useful
1200 as the value of `mouse-track-click-hook'."
1202 (minibuffer-smart-select-highlighted-completion-1 event nil))
1204 (define-key minibuffer-local-map 'button2
1205 'minibuffer-smart-select-highlighted-completion)
1208 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1209 ;;;; Minibuffer History ;;;;
1210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1212 (defvar minibuffer-history '()
1213 "Default minibuffer history list.
1214 This is used for all minibuffer input except when an alternate history
1215 list is specified.")
1217 ;; Some other history lists:
1219 (defvar minibuffer-history-search-history '())
1220 (defvar function-history '())
1221 (defvar variable-history '())
1222 (defvar buffer-history '())
1223 (defvar shell-command-history '())
1224 (defvar file-name-history '())
1226 (defvar read-expression-history nil)
1228 (defvar minibuffer-history-sexp-flag nil ;weird FSF Emacs kludge
1229 "Non-nil when doing history operations on `command-history'.
1230 More generally, indicates that the history list being acted on
1231 contains expressions rather than strings.")
1233 (defun previous-matching-history-element (regexp n)
1234 "Find the previous history element that matches REGEXP.
1235 \(Previous history elements refer to earlier actions.)
1236 With prefix argument N, search for Nth previous match.
1237 If N is negative, find the next or Nth next match."
1239 (let ((enable-recursive-minibuffers t)
1240 (minibuffer-history-sexp-flag nil))
1241 (if (eq 't (symbol-value minibuffer-history-variable))
1242 (error "History is not being recorded in this context"))
1243 (list (read-from-minibuffer "Previous element matching (regexp): "
1244 (car minibuffer-history-search-history)
1245 minibuffer-local-map
1247 'minibuffer-history-search-history)
1248 (prefix-numeric-value current-prefix-arg))))
1249 (let ((history (symbol-value minibuffer-history-variable))
1251 (pos minibuffer-history-position))
1253 (error "History is not being recorded in this context"))
1256 (setq pos (min (max 1 (+ pos (if (< n 0) -1 1))) (length history)))
1258 (if (= pos 1) ;; rewritten for I18N3 snarfing
1259 (error "No later matching history item")
1260 (error "No earlier matching history item")))
1261 (if (string-match regexp
1262 (if minibuffer-history-sexp-flag
1263 (let ((print-level nil))
1264 (prin1-to-string (nth (1- pos) history)))
1265 (nth (1- pos) history)))
1266 (setq n (+ n (if (< n 0) 1 -1)))))
1267 (setq minibuffer-history-position pos)
1268 (setq current-minibuffer-contents (buffer-string)
1269 current-minibuffer-point (point))
1271 (let ((elt (nth (1- pos) history)))
1272 (insert (if minibuffer-history-sexp-flag
1273 (let ((print-level nil))
1274 (prin1-to-string elt))
1276 (goto-char (point-min)))
1277 (if (or (eq (car (car command-history)) 'previous-matching-history-element)
1278 (eq (car (car command-history)) 'next-matching-history-element))
1279 (setq command-history (cdr command-history))))
1281 (defun next-matching-history-element (regexp n)
1282 "Find the next history element that matches REGEXP.
1283 \(The next history element refers to a more recent action.)
1284 With prefix argument N, search for Nth next match.
1285 If N is negative, find the previous or Nth previous match."
1287 (let ((enable-recursive-minibuffers t)
1288 (minibuffer-history-sexp-flag nil))
1289 (if (eq t (symbol-value minibuffer-history-variable))
1290 (error "History is not being recorded in this context"))
1291 (list (read-from-minibuffer "Next element matching (regexp): "
1292 (car minibuffer-history-search-history)
1293 minibuffer-local-map
1295 'minibuffer-history-search-history)
1296 (prefix-numeric-value current-prefix-arg))))
1297 (previous-matching-history-element regexp (- n)))
1299 (defun next-history-element (n)
1300 "Insert the next element of the minibuffer history into the minibuffer."
1302 (if (eq 't (symbol-value minibuffer-history-variable))
1303 (error "History is not being recorded in this context"))
1305 (when (eq minibuffer-history-position
1306 initial-minibuffer-history-position)
1307 (setq current-minibuffer-contents (buffer-string)
1308 current-minibuffer-point (point)))
1309 (let ((narg (- minibuffer-history-position n))
1310 (minimum (if minibuffer-default -1 0)))
1311 (cond ((< narg minimum)
1312 (error "No following item in %s" minibuffer-history-variable))
1313 ((> narg (length (symbol-value minibuffer-history-variable)))
1314 (error "No preceding item in %s" minibuffer-history-variable)))
1316 (setq minibuffer-history-position narg)
1317 (if (eq narg initial-minibuffer-history-position)
1319 (insert current-minibuffer-contents)
1320 (goto-char current-minibuffer-point))
1321 (let ((elt (if (>= narg 0)
1322 (nth (1- minibuffer-history-position)
1323 (symbol-value minibuffer-history-variable))
1324 minibuffer-default)))
1326 (if (not (stringp elt))
1327 (let ((print-level nil))
1329 (let ((print-readably t)
1330 (print-escape-newlines t))
1331 (prin1-to-string elt))
1332 (error (prin1-to-string elt))))
1334 ;; FSF has point-min here.
1335 (goto-char (point-max))))))
1337 (defun previous-history-element (n)
1338 "Insert the previous element of the minibuffer history into the minibuffer."
1340 (next-history-element (- n)))
1342 (defun next-complete-history-element (n)
1343 "Get next element of history which is a completion of minibuffer contents."
1345 (let ((point-at-start (point)))
1346 (next-matching-history-element
1347 (concat "^" (regexp-quote (buffer-substring (point-min) (point)))) n)
1348 ;; next-matching-history-element always puts us at (point-min).
1349 ;; Move to the position we were at before changing the buffer contents.
1350 ;; This is still sensical, because the text before point has not changed.
1351 (goto-char point-at-start)))
1353 (defun previous-complete-history-element (n)
1354 "Get previous element of history which is a completion of minibuffer contents."
1356 (next-complete-history-element (- n)))
1359 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1360 ;;;; reading various things from a minibuffer ;;;;
1361 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1363 (defun read-expression (prompt &optional initial-contents history)
1364 "Return a Lisp object read using the minibuffer.
1365 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
1366 is a string to insert in the minibuffer before reading.
1367 Third arg HISTORY, if non-nil, specifies a history list."
1368 (let ((minibuffer-history-sexp-flag t)
1369 ;; Semi-kludge to get around M-x C-x o M-ESC trying to do completion.
1370 (minibuffer-completion-table nil))
1371 (read-from-minibuffer prompt
1375 (or history 'read-expression-history)
1376 lisp-mode-abbrev-table)))
1378 (defun read-string (prompt &optional initial-contents history)
1379 "Return a string from the minibuffer, prompting with string PROMPT.
1380 If non-nil, optional second arg INITIAL-CONTENTS is a string to insert
1381 in the minibuffer before reading.
1382 Third arg HISTORY, if non-nil, specifies a history list."
1383 (let ((minibuffer-completion-table nil))
1384 (read-from-minibuffer prompt
1386 minibuffer-local-map
1389 (defun eval-minibuffer (prompt &optional initial-contents history)
1390 "Return value of Lisp expression read using the minibuffer.
1391 Prompt with PROMPT. If non-nil, optional second arg INITIAL-CONTENTS
1392 is a string to insert in the minibuffer before reading.
1393 Third arg HISTORY, if non-nil, specifies a history list."
1394 (eval (read-expression prompt initial-contents history)))
1396 ;; The name `command-history' is already taken
1397 (defvar read-command-history '())
1399 (defun read-command (prompt)
1400 "Read the name of a command and return as a symbol.
1401 Prompts with PROMPT."
1402 (intern (completing-read prompt obarray 'commandp t nil
1403 ;; 'command-history is not right here: that's a
1404 ;; list of evalable forms, not a history list.
1405 'read-command-history
1408 (defun read-function (prompt)
1409 "Read the name of a function and return as a symbol.
1410 Prompts with PROMPT."
1411 (intern (completing-read prompt obarray 'fboundp t nil
1412 'function-history)))
1414 (defun read-variable (prompt)
1415 "Read the name of a user variable and return it as a symbol.
1416 Prompts with PROMPT.
1417 A user variable is one whose documentation starts with a `*' character."
1418 (intern (completing-read prompt obarray 'user-variable-p t nil
1419 'variable-history)))
1421 (defun read-buffer (prompt &optional default require-match)
1422 "Read the name of a buffer and return as a string.
1423 Prompts with PROMPT. Optional second arg DEFAULT is value to return if user
1424 enters an empty line. If optional third arg REQUIRE-MATCH is non-nil,
1425 only existing buffer names are allowed."
1426 (let ((prompt (if default
1427 (format "%s(default %s) "
1428 (gettext prompt) (if (bufferp default)
1429 (buffer-name default)
1432 (alist (mapcar #'(lambda (b) (cons (buffer-name b) b))
1436 (setq result (completing-read prompt alist nil require-match
1437 nil 'buffer-history))
1438 (cond ((not (equal result ""))
1440 ((not require-match)
1441 (setq result default)
1445 ((not (get-buffer default))
1448 (setq result default)
1450 (if (bufferp result)
1451 (buffer-name result)
1454 (defun read-number (prompt &optional integers-only)
1455 "Read a number from the minibuffer."
1456 (let ((pred (if integers-only 'integerp 'numberp))
1458 (while (not (funcall pred num))
1459 (setq num (condition-case ()
1460 (let ((minibuffer-completion-table nil))
1461 (read-from-minibuffer
1462 prompt (if num (prin1-to-string num)) nil t
1465 (invalid-read-syntax nil)
1467 (or (funcall pred num) (beep)))
1470 (defun read-shell-command (prompt &optional initial-input history)
1471 "Just like read-string, but uses read-shell-command-map:
1472 \\{read-shell-command-map}"
1473 (let ((minibuffer-completion-table nil))
1474 (read-from-minibuffer prompt initial-input read-shell-command-map
1475 nil (or history 'shell-command-history))))
1478 ;;; This read-file-name stuff probably belongs in files.el
1480 ;; Quote "$" as "$$" to get it past substitute-in-file-name
1481 (defun un-substitute-in-file-name (string)
1482 (let ((regexp "\\$")
1483 (olen (length string))
1486 (if (not (string-match regexp string))
1489 (while (string-match regexp string (match-end 0))
1491 (setq new (make-string (+ olen n) ?$))
1494 (setq ch (aref string o))
1496 (setq o (1+ o) n (1+ n))
1498 ;; already aset by make-string initial-value
1502 (defun read-file-name-2 (history prompt dir default
1503 must-match initial-contents
1506 (setq dir default-directory))
1507 (setq dir (abbreviate-file-name dir t))
1508 (let* ((insert (cond ((and (not insert-default-directory)
1509 (not initial-contents))
1512 (cons (un-substitute-in-file-name
1513 (concat dir initial-contents))
1516 (un-substitute-in-file-name dir))))
1518 ;; Hateful, broken, case-sensitive un*x
1519 ;;; (completing-read prompt
1525 ;; #### - this is essentially the guts of completing read.
1526 ;; There should be an elegant way to pass a pair of keymaps to
1527 ;; completing read, but this will do for now. All sins are
1529 (let ((minibuffer-completion-table completer)
1530 (minibuffer-completion-predicate dir)
1531 (minibuffer-completion-confirm (if (eq must-match 't)
1533 (last-exact-completion nil))
1534 (read-from-minibuffer prompt
1536 (if (not must-match)
1538 read-file-name-must-match-map)
1542 ;;; ;; Kludge! Put "/foo/bar" on history rather than "/default//foo/bar"
1543 ;;; (let ((hist (cond ((not history) 'minibuffer-history)
1544 ;;; ((consp history) (car history))
1548 ;;; (not (eq hist 't))
1550 ;;; (equal (car-safe (symbol-value hist)) val))
1551 ;;; (let ((e (condition-case nil
1552 ;;; (expand-file-name val)
1554 ;;; (if (and e (not (equal e val)))
1555 ;;; (set hist (cons e (cdr (symbol-value hist))))))))
1558 (error "No file name specified"))
1560 (equal val (if (consp insert) (car insert) insert)))
1563 (substitute-in-file-name val)))))
1565 ;; #### this function should use minibuffer-completion-table
1566 ;; or something. But that is sloooooow.
1567 ;; #### all this shit needs better documentation!!!!!!!!
1568 (defun read-file-name-activate-callback (event extent dir-p)
1569 ;; used as the activate-callback of the filename list items
1570 ;; in the completion buffer, in place of default-choose-completion.
1571 ;; if a regular file was selected, we call default-choose-completion
1572 ;; (which just inserts the string in the minibuffer and calls
1573 ;; exit-minibuffer). If a directory was selected, we display
1574 ;; the contents of the directory.
1575 (let* ((file (extent-string extent))
1576 (completion-buf (extent-object extent))
1577 (minibuf (symbol-value-in-buffer 'completion-reference-buffer
1579 (in-dir (file-name-directory (buffer-substring nil nil minibuf)))
1580 (full (expand-file-name file in-dir)))
1581 (if (not (file-directory-p full))
1582 (default-choose-completion event extent minibuf)
1583 (erase-buffer minibuf)
1584 (insert-string (file-name-as-directory
1585 (abbreviate-file-name full t)) minibuf)
1586 (reset-buffer completion-buf)
1587 (let ((standard-output completion-buf))
1588 (display-completion-list
1589 (delete "." (directory-files full nil nil nil (if dir-p 'directory)))
1591 :reference-buffer minibuf
1592 :activate-callback 'read-file-name-activate-callback)
1593 (goto-char (point-min) completion-buf)))))
1595 (defun read-file-name-1 (history prompt dir default
1596 must-match initial-contents
1598 (if (should-use-dialog-box-p)
1599 ;; this calls read-file-name-2
1600 (mouse-read-file-name-1 history prompt dir default must-match
1601 initial-contents completer)
1604 ;; #### SCREAM! Create a `file-system-ignore-case'
1605 ;; function, so this kind of stuff is generalized!
1606 (and (eq system-type 'windows-nt)
1607 (set (make-local-variable 'completion-ignore-case) t))
1609 (make-local-variable
1610 'completion-display-completion-list-function)
1611 #'(lambda (completions)
1612 (display-completion-list
1614 :user-data (not (eq completer 'read-file-name-internal))
1616 'read-file-name-activate-callback)))
1618 (remove-hook 'minibuffer-setup-hook rfhookfun)
1622 (add-hook 'minibuffer-setup-hook rfhookfun)
1623 (read-file-name-2 history prompt dir default must-match
1624 initial-contents completer))
1625 (remove-hook 'minibuffer-setup-hook rfhookfun)))))
1627 (defun read-file-name (prompt
1628 &optional dir default must-match initial-contents
1630 "Read file name, prompting with PROMPT and completing in directory DIR.
1631 This will prompt with a dialog box if appropriate, according to
1632 `should-use-dialog-box-p'.
1633 Value is not expanded---you must call `expand-file-name' yourself.
1634 Value is subject to interpreted by substitute-in-file-name however.
1635 Default name to DEFAULT if user enters a null string.
1636 (If DEFAULT is omitted, the visited file name is used,
1637 except that if INITIAL-CONTENTS is specified, that combined with DIR is
1639 Fourth arg MUST-MATCH non-nil means require existing file's name.
1640 Non-nil and non-t means also require confirmation after completion.
1641 Fifth arg INITIAL-CONTENTS specifies text to start with.
1642 Sixth arg HISTORY specifies the history list to use. Default is
1643 `file-name-history'.
1644 DIR defaults to current buffer's directory default."
1646 (or history 'file-name-history)
1647 prompt dir (or default
1648 (if initial-contents (expand-file-name initial-contents dir)
1650 must-match initial-contents
1651 ;; A separate function (not an anonymous lambda-expression)
1652 ;; and passed as a symbol because of disgusting kludges in various
1653 ;; places which do stuff like (let ((filename-kludge-p (eq minibuffer-completion-table 'read-file-name-internal))) ...)
1654 'read-file-name-internal))
1656 (defun read-directory-name (prompt
1657 &optional dir default must-match initial-contents
1659 "Read directory name, prompting with PROMPT and completing in directory DIR.
1660 This will prompt with a dialog box if appropriate, according to
1661 `should-use-dialog-box-p'.
1662 Value is not expanded---you must call `expand-file-name' yourself.
1663 Value is subject to interpreted by substitute-in-file-name however.
1664 Default name to DEFAULT if user enters a null string.
1665 (If DEFAULT is omitted, the current buffer's default directory is used.)
1666 Fourth arg MUST-MATCH non-nil means require existing directory's name.
1667 Non-nil and non-t means also require confirmation after completion.
1668 Fifth arg INITIAL-CONTENTS specifies text to start with.
1669 Sixth arg HISTORY specifies the history list to use. Default is
1670 `file-name-history'.
1671 DIR defaults to current buffer's directory default."
1673 (or history 'file-name-history)
1674 prompt dir (or default default-directory) must-match initial-contents
1675 'read-directory-name-internal))
1678 ;; Environment-variable and ~username completion hack
1679 (defun read-file-name-internal-1 (string dir action completer)
1680 (if (not (string-match
1681 "\\([^$]\\|\\`\\)\\(\\$\\$\\)*\\$\\([A-Za-z0-9_]*\\|{[^}]*\\)\\'"
1683 ;; Not doing environment-variable completion hack
1684 (let* ((orig (if (equal string "") nil string))
1685 (sstring (if orig (substitute-in-file-name string) string))
1686 (specdir (if orig (file-name-directory sstring) nil))
1687 (name (if orig (file-name-nondirectory sstring) string))
1688 (direct (if specdir (expand-file-name specdir dir) dir)))
1689 ;; ~username completion
1690 (if (and (fboundp 'user-name-completion-1)
1691 (string-match "^[~]" name))
1692 (let ((user (substring name 1)))
1693 (cond ((eq action 'lambda)
1694 (file-directory-p name))
1697 (mapcar #'(lambda (p) (concat "~" p))
1698 (user-name-all-completions user)))
1701 (let* ((val+uniq (user-name-completion-1 user))
1702 (val (car val+uniq))
1703 (uniq (cdr val+uniq)))
1704 (cond ((stringp val)
1706 (file-name-as-directory (concat "~" val))
1709 (file-name-as-directory name))
1718 ;; An odd number of trailing $'s
1719 (let* ((start (match-beginning 3))
1720 (env (substring string
1721 (cond ((= start (length string))
1724 ((= (aref string start) ?{)
1729 (head (substring string 0 (1- start)))
1731 (mapcar #'(lambda (x)
1732 (cons (substring x 0 (string-match "=" x))
1734 process-environment))))
1736 (cond ((eq action 'lambda)
1740 (mapcar #'(lambda (p)
1741 (if (and (> (length p) 0)
1742 ;;#### Unix-specific
1743 ;;#### -- need absolute-pathname-p
1746 (concat head "$" p)))
1747 (all-completions env (funcall alist))))
1750 (let* ((e (funcall alist))
1751 (val (try-completion env e)))
1752 (cond ((stringp val)
1753 (if (string-match "[^A-Za-z0-9_]" val)
1756 ;; completed uniquely?
1757 (if (eq (try-completion val e) 't)
1759 (concat head "$" val)))
1762 (un-substitute-in-file-name (getenv env))))
1766 (defun read-file-name-internal (string dir action)
1767 (read-file-name-internal-1
1769 #'(lambda (action orig string specdir dir name)
1770 (cond ((eq action 'lambda)
1773 (let ((sstring (condition-case nil
1774 (expand-file-name string)
1777 ;; Some pathname syntax error in string
1779 (file-exists-p sstring)))))
1782 (mapcar #'un-substitute-in-file-name
1783 (file-name-all-completions name dir)))
1786 (let* ((d (or dir default-directory))
1787 (val (file-name-completion name d)))
1788 (if (and (eq val 't)
1789 (not (null completion-ignored-extensions)))
1790 ;;#### (file-name-completion "foo") returns 't
1791 ;; when both "foo" and "foo~" exist and the latter
1792 ;; is "pruned" by completion-ignored-extensions.
1793 ;; I think this is a bug in file-name-completion.
1794 (setq val (let ((completion-ignored-extensions '()))
1795 (file-name-completion name d))))
1797 (un-substitute-in-file-name (if specdir
1798 (concat specdir val)
1800 (let ((tem (un-substitute-in-file-name string)))
1801 (if (not (equal tem orig))
1802 ;; substitute-in-file-name did something
1806 (defun read-directory-name-internal (string dir action)
1807 (read-file-name-internal-1
1809 #'(lambda (action orig string specdir dir name)
1810 (let* ((dirs #'(lambda (fn)
1811 (let ((l (if (equal name "")
1821 (concat "\\`" (regexp-quote name))
1827 (cond ((eq action 'lambda)
1831 (file-directory-p string)))
1834 (funcall dirs #'(lambda (n)
1835 (un-substitute-in-file-name
1836 (file-name-as-directory n)))))
1839 (let ((val (try-completion
1843 (list (file-name-as-directory
1846 (un-substitute-in-file-name (if specdir
1847 (concat specdir val)
1849 (let ((tem (un-substitute-in-file-name string)))
1850 (if (not (equal tem orig))
1851 ;; substitute-in-file-name did something
1855 (defun append-expand-filename (file-string string)
1856 "Append STRING to FILE-STRING differently depending on whether STRING
1857 is a username (~string), an environment variable ($string),
1858 or a filename (/string). The resultant string is returned with the
1859 environment variable or username expanded and resolved to indicate
1860 whether it is a file(/result) or a directory (/result/)."
1862 (cond ((string-match "\\([~$]\\)\\([^~$/]*\\)$" file-string)
1863 (cond ((string= (substring file-string
1866 (concat (substring file-string 0 (match-end 1))
1868 (t (substitute-in-file-name
1869 (concat (substring file-string 0 (match-end 1))
1871 (t (concat (file-name-directory
1872 (substitute-in-file-name file-string)) string))))
1875 (cond ((stringp (setq result (and (file-exists-p (expand-file-name file))
1876 (read-file-name-internal
1878 (expand-file-name file)
1884 (defun mouse-file-display-completion-list (window dir minibuf user-data)
1885 (let ((standard-output (window-buffer window)))
1887 (display-completion-list
1888 (directory-files dir nil nil nil t)
1889 :window-width (* 2 (window-width window))
1891 'mouse-read-file-name-activate-callback
1892 :user-data user-data
1893 :reference-buffer minibuf
1897 (defun mouse-directory-display-completion-list (window dir minibuf user-data)
1898 (let ((standard-output (window-buffer window)))
1900 (display-completion-list
1901 (delete "." (directory-files dir nil nil nil 1))
1902 :window-width (window-width window)
1904 'mouse-read-file-name-activate-callback
1905 :user-data user-data
1906 :reference-buffer minibuf
1910 (defun mouse-read-file-name-activate-callback (event extent user-data)
1911 (let* ((file (extent-string extent))
1912 (minibuf (symbol-value-in-buffer 'completion-reference-buffer
1913 (extent-object extent)))
1914 (in-dir (buffer-substring nil nil minibuf))
1915 (full (expand-file-name file in-dir))
1916 (filebuf (nth 0 user-data))
1917 (dirbuff (nth 1 user-data))
1918 (filewin (nth 2 user-data))
1919 (dirwin (nth 3 user-data)))
1920 (if (file-regular-p full)
1921 (default-choose-completion event extent minibuf)
1922 (erase-buffer minibuf)
1923 (insert-string (file-name-as-directory
1924 (abbreviate-file-name full t)) minibuf)
1925 (reset-buffer filebuf)
1927 (mouse-directory-display-completion-list filewin full minibuf
1929 (mouse-file-display-completion-list filewin full minibuf user-data)
1930 (reset-buffer dirbuff)
1931 (mouse-directory-display-completion-list dirwin full minibuf
1934 ;; this is rather cheesified but gets the job done.
1935 (defun mouse-read-file-name-1 (history prompt dir default
1936 must-match initial-contents
1938 (let* ((file-p (eq 'read-file-name-internal completer))
1939 (filebuf (get-buffer-create "*Completions*"))
1940 (dirbuff (and file-p (generate-new-buffer " *mouse-read-file*")))
1941 (butbuff (generate-new-buffer " *mouse-read-file*"))
1942 (frame (make-dialog-frame))
1947 (reset-buffer filebuf)
1948 (select-frame frame)
1949 (let ((window-min-height 1))
1950 ;; #### should be 2 not 3, but that causes
1951 ;; "window too small to split" errors for some
1952 ;; people (but not for me ...) There's a more
1953 ;; fundamental bug somewhere.
1954 (split-window nil (- (frame-height frame) 3)))
1957 (split-window-horizontally 16)
1958 (setq filewin (frame-rightmost-window frame)
1959 dirwin (frame-leftmost-window frame))
1960 (set-window-buffer filewin filebuf)
1961 (set-window-buffer dirwin dirbuff))
1962 (setq filewin (frame-highest-window frame))
1963 (set-window-buffer filewin filebuf))
1964 (setq user-data (list filebuf dirbuff filewin dirwin))
1965 (set-window-buffer (frame-lowest-window frame) butbuff)
1966 (set-buffer butbuff)
1968 (setq default-directory dir))
1969 (when (featurep 'scrollbar)
1970 (set-specifier scrollbar-width 0 butbuff))
1972 (insert-gui-button (make-gui-button "OK"
1974 (exit-minibuffer))))
1976 (insert-gui-button (make-gui-button "Cancel"
1978 (abort-recursive-edit))))
1982 (mouse-directory-display-completion-list
1983 filewin dir (current-buffer) user-data)
1984 (mouse-file-display-completion-list filewin dir
1987 (mouse-directory-display-completion-list dirwin dir
1991 (make-local-variable
1992 'completion-display-completion-list-function)
1993 #'(lambda (completions)
1994 (display-completion-list
1998 'mouse-read-file-name-activate-callback
1999 :user-data user-data)))
2001 (remove-hook 'minibuffer-setup-hook rfhookfun)
2005 ;; #### I really need to flesh out the object
2006 ;; hierarchy better to avoid these kludges.
2009 (set-buffer standard-output)
2010 (setq truncate-lines t)))))
2013 (add-hook 'minibuffer-setup-hook rfhookfun)
2014 (add-hook 'completion-setup-hook rfcshookfun)
2015 (read-file-name-2 history prompt dir default
2016 must-match initial-contents
2018 (remove-hook 'minibuffer-setup-hook rfhookfun)
2019 (remove-hook 'completion-setup-hook rfcshookfun))))
2020 (delete-frame frame)
2021 (kill-buffer filebuf)
2022 (kill-buffer butbuff)
2023 (and dirbuff (kill-buffer dirbuff)))))
2025 (defun read-face (prompt &optional must-match)
2026 "Read the name of a face from the minibuffer and return it as a symbol."
2027 (intern (completing-read prompt obarray 'find-face must-match)))
2029 ;; #### - wrong place for this variable? Exactly. We probably want
2030 ;; `color-list' to be a console method, so `tty-color-list' becomes
2031 ;; obsolete, and `read-color-completion-table' conses (mapcar #'list
2032 ;; (color-list)), optionally caching the results.
2034 ;; Ben wanted all of the possibilities from the `configure' script used
2035 ;; here, but I think this is way too many. I already trimmed the R4 variants
2036 ;; and a few obvious losers from the list. --Stig
2037 (defvar x-library-search-path '("/usr/X11R6/lib/X11/"
2038 "/usr/X11R5/lib/X11/"
2039 "/usr/lib/X11R6/X11/"
2040 "/usr/lib/X11R5/X11/"
2041 "/usr/local/X11R6/lib/X11/"
2042 "/usr/local/X11R5/lib/X11/"
2043 "/usr/local/lib/X11R6/X11/"
2044 "/usr/local/lib/X11R5/X11/"
2047 "/usr/local/lib/X11/"
2048 "/usr/X386/lib/X11/"
2049 "/usr/x386/lib/X11/"
2050 "/usr/XFree86/lib/X11/"
2051 "/usr/unsupported/lib/X11/"
2052 "/usr/athena/lib/X11/"
2053 "/usr/local/x11r5/lib/X11/"
2054 "/usr/lpp/Xamples/lib/X11/"
2055 "/usr/openwin/lib/X11/"
2056 "/usr/openwin/share/lib/X11/")
2057 "Search path used by `read-color' to find rgb.txt.")
2059 (defvar x-read-color-completion-table)
2061 (defun read-color-completion-table ()
2063 ;; #### Evil device-type dependency
2065 (if (boundp 'x-read-color-completion-table)
2066 x-read-color-completion-table
2067 (let ((rgb-file (locate-file "rgb.txt" x-library-search-path))
2070 ;; prevents multiple searches for rgb.txt if we can't find it
2071 (setq x-read-color-completion-table nil)
2072 (with-current-buffer (get-buffer-create " *colors*")
2073 (reset-buffer (current-buffer))
2074 (insert-file-contents rgb-file)
2076 ;; skip over comments
2077 (while (looking-at "^!")
2080 (skip-chars-forward "0-9 \t")
2083 (setq color (buffer-substring p (point))
2084 clist (cons (list color) clist))
2085 ;; Ugh. If we want to be able to complete the lowercase form
2086 ;; of the color name, we need to add it twice! Yuck.
2087 (let ((dcase (downcase color)))
2088 (or (string= dcase color)
2089 (push (list dcase) clist)))
2091 (kill-buffer (current-buffer))))
2092 (setq x-read-color-completion-table clist)
2093 x-read-color-completion-table)))
2095 (mapcar #'list (mswindows-color-list)))
2097 (mapcar #'list (tty-color-list)))))
2099 (defun read-color (prompt &optional must-match initial-contents)
2100 "Read the name of a color from the minibuffer.
2101 On X devices, this uses `x-library-search-path' to find rgb.txt in order
2102 to build a completion table.
2103 On TTY devices, this uses `tty-color-list'.
2104 On mswindows devices, this uses `mswindows-color-list'."
2105 (let ((table (read-color-completion-table)))
2106 (completing-read prompt table nil (and table must-match)
2110 ;; #### The doc string for read-non-nil-coding system gets lost if we
2111 ;; only include these if the mule feature is present. Strangely,
2112 ;; read-coding-system doesn't.
2114 ;;(if (featurep 'mule)
2116 (defun read-coding-system (prompt &optional default-coding-system)
2117 "Read a coding-system (or nil) from the minibuffer.
2118 Prompting with string PROMPT.
2119 If the user enters null input, return second argument DEFAULT-CODING-SYSTEM.
2120 DEFAULT-CODING-SYSTEM can be a string, symbol, or coding-system object."
2121 (intern (completing-read prompt obarray 'find-coding-system t nil nil
2122 (cond ((symbolp default-coding-system)
2123 (symbol-name default-coding-system))
2124 ((coding-system-p default-coding-system)
2125 (symbol-name (coding-system-name default-coding-system)))
2127 default-coding-system)))))
2129 (defun read-non-nil-coding-system (prompt)
2130 "Read a non-nil coding-system from the minibuffer.
2131 Prompt with string PROMPT."
2132 (let ((retval (intern "")))
2133 (while (= 0 (length (symbol-name retval)))
2134 (setq retval (intern (completing-read prompt obarray
2139 ;;) ;; end of (featurep 'mule)
2143 (defcustom force-dialog-box-use nil
2144 "*If non-nil, always use a dialog box for asking questions, if possible.
2145 You should *bind* this, not set it. This is useful if you're doing
2146 something mousy but which wasn't actually invoked using the mouse."
2150 ;; We include this here rather than dialog.el so it is defined
2151 ;; even when dialog boxes are not present.
2152 (defun should-use-dialog-box-p ()
2153 "If non-nil, questions should be asked with a dialog box instead of the
2154 minibuffer. This looks at `last-command-event' to see if it was a mouse
2155 event, and checks whether dialog-support exists and the current device
2156 supports dialog boxes.
2158 The dialog box is totally disabled if the variable `use-dialog-box'
2160 (and (featurep 'dialog)
2161 (device-on-window-system-p)
2163 (or force-dialog-box-use
2164 (button-press-event-p last-command-event)
2165 (button-release-event-p last-command-event)
2166 (misc-user-event-p last-command-event))))
2168 ;;; minibuf.el ends here