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