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