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