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