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