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