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