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