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