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