annotate lisp/minibuf.el @ 227:0e522484dd2a r20-5b12

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