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