annotate lisp/minibuf.el @ 5384:3889ef128488

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