annotate lisp/prim/minibuf.el @ 177:6075d714658b r20-3b15

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