annotate lisp/minibuf.el @ 306:9ea74add5d37 r21-0b51

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