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