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