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