annotate lisp/minibuf.el @ 388:aabb7f5b1c81 r21-2-9

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