annotate lisp/minibuf.el @ 209:41ff10fd062f r20-4b3

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