Mercurial > hg > xemacs-beta
annotate lisp/cmdloop.el @ 5249:d4fae3ebf26a
Add `save-some-buffers-action-alist'.
2010-08-20 Mike Sperber <mike@xemacs.org>
* files.el (save-some-buffers-action-alist): Add.
(save-some-buffers-1): Use (synching with (GPLv2) FSF Emacs.
| author | Mike Sperber <sperber@deinprogramm.de> |
|---|---|
| date | Fri, 20 Aug 2010 13:04:54 +0200 |
| parents | 9fa29ec759e3 |
| children | d27c1ee1943b 308d34e9f07d |
| rev | line source |
|---|---|
| 428 | 1 ;;; cmdloop.el --- support functions for the top-level command loop. |
| 2 | |
| 3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc. | |
| 1333 | 4 ;; Copyright (C) 2001, 2002, 2003 Ben Wing. |
| 428 | 5 |
| 6 ;; Author: Richard Mlynarik | |
| 7 ;; Date: 8-Jul-92 | |
| 8 ;; Maintainer: XEmacs Development Team | |
| 9 ;; Keywords: internal, dumped | |
| 10 | |
| 11 ;; This file is part of XEmacs. | |
| 12 | |
| 13 ;; XEmacs is free software; you can redistribute it and/or modify it | |
| 14 ;; under the terms of the GNU General Public License as published by | |
| 15 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 16 ;; any later version. | |
| 17 | |
| 18 ;; XEmacs is distributed in the hope that it will be useful, but | |
| 19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 21 ;; General Public License for more details. | |
| 22 | |
| 23 ;; You should have received a copy of the GNU General Public License | |
| 24 ;; along with XEmacs; see the file COPYING. If not, write to the | |
| 25 ;; Free Software Foundation, 59 Temple Place - Suite 330, | |
| 26 ;; Boston, MA 02111-1307, USA. | |
| 27 | |
| 28 ;;; Synched up with: FSF 19.30. (Some of the stuff below is in FSF's subr.el.) | |
| 1333 | 29 ;;; Some parts synched with FSF 21.2. |
| 428 | 30 |
| 31 ;;; Commentary: | |
| 32 | |
| 33 ;; This file is dumped with XEmacs. | |
| 34 | |
| 35 ;;; Code: | |
| 36 | |
| 37 (defun recursion-depth () | |
| 38 "Return the current depth in recursive edits." | |
| 39 (+ command-loop-level (minibuffer-depth))) | |
| 40 | |
| 41 (defun top-level () | |
| 42 "Exit all recursive editing levels." | |
| 43 (interactive) | |
| 44 (throw 'top-level nil)) | |
| 45 | |
| 46 (defun exit-recursive-edit () | |
| 47 "Exit from the innermost recursive edit or minibuffer." | |
| 48 (interactive) | |
| 49 (if (> (recursion-depth) 0) | |
| 50 (throw 'exit nil)) | |
| 51 (error "No recursive edit is in progress")) | |
| 52 | |
| 53 (defun abort-recursive-edit () | |
| 54 "Abort the command that requested this recursive edit or minibuffer input." | |
| 55 (interactive) | |
| 56 (if (> (recursion-depth) 0) | |
| 57 (throw 'exit t)) | |
| 58 (error "No recursive edit is in progress")) | |
| 59 | |
| 60 ;; (defun keyboard-quit () | |
| 61 ;; "Signal a `quit' condition." | |
| 62 ;; (interactive) | |
| 63 ;; (deactivate-mark) | |
| 64 ;; (signal 'quit nil)) | |
| 65 | |
| 66 ;; moved here from pending-del. | |
| 67 (defun keyboard-quit () | |
| 68 "Signal a `quit' condition. | |
| 69 If this character is typed while lisp code is executing, it will be treated | |
| 70 as an interrupt. | |
| 71 If this character is typed at top-level, this simply beeps. | |
| 72 If `zmacs-regions' is true, and the zmacs region is active in this buffer, | |
| 73 then this key deactivates the region without beeping or signalling." | |
| 74 (interactive) | |
| 2611 | 75 (if (region-active-p) |
| 428 | 76 ;; pseudo-zmacs compatibility: don't beep if this ^G is simply |
| 77 ;; deactivating the region. If it is inactive, beep. | |
| 78 nil | |
| 79 (signal 'quit nil))) | |
| 80 | |
| 81 (defvar buffer-quit-function nil | |
| 82 "Function to call to \"quit\" the current buffer, or nil if none. | |
| 83 \\[keyboard-escape-quit] calls this function when its more local actions | |
| 84 \(such as cancelling a prefix argument, minibuffer or region) do not apply.") | |
| 85 | |
| 86 (defun keyboard-escape-quit () | |
| 87 "Exit the current \"mode\" (in a generalized sense of the word). | |
| 88 This command can exit an interactive command such as `query-replace', | |
| 89 can clear out a prefix argument or a region, | |
| 90 can get out of the minibuffer or other recursive edit, | |
| 91 cancel the use of the current buffer (for special-purpose buffers), | |
| 92 or go back to just one window (by deleting all but the selected window)." | |
| 93 (interactive) | |
| 94 (cond ((eq last-command 'mode-exited) nil) | |
| 95 ((> (minibuffer-depth) 0) | |
| 96 (abort-recursive-edit)) | |
| 97 (current-prefix-arg | |
| 98 nil) | |
| 99 ((region-active-p) | |
| 100 (zmacs-deactivate-region)) | |
| 101 ((> (recursion-depth) 0) | |
| 102 (exit-recursive-edit)) | |
| 103 (buffer-quit-function | |
| 104 (funcall buffer-quit-function)) | |
| 105 ((not (one-window-p t)) | |
| 106 (delete-other-windows)) | |
| 107 ((string-match "^ \\*" (buffer-name (current-buffer))) | |
| 108 (bury-buffer)))) | |
| 109 | |
| 110 ;; `cancel-mode-internal' is a function of a misc-user event, which is | |
| 111 ;; queued when window system directs XEmacs frame to cancel any modal | |
| 112 ;; behavior it exposes, like mouse pointer grabbing. | |
| 113 ;; | |
| 114 ;; This function does nothing at the top level, but the code which | |
| 115 ;; runs modal event loops, such as selection drag loop in `mouse-track', | |
| 116 ;; check if misc-user function symbol is `cancel-mode-internal', and | |
| 117 ;; takes necessary cleanup actions. | |
| 118 (defun cancel-mode-internal (object) | |
| 119 (setq zmacs-region-stays t)) | |
| 120 | |
| 121 ;; Someone wrote: "This should really be a ring of last errors." | |
| 122 ;; | |
| 123 ;; But why bother? This stuff is not all that necessary now that we | |
| 124 ;; have message log, anyway. | |
| 125 (defvar last-error nil | |
| 126 "Object describing the last signaled error.") | |
| 127 | |
| 128 (defcustom errors-deactivate-region nil | |
| 129 "*Non-nil means that errors will cause the region to be deactivated." | |
| 130 :type 'boolean | |
| 131 :group 'editing-basics) | |
| 132 | |
| 133 (defun command-error (error-object) | |
| 771 | 134 ;; if you want a backtrace before exiting, set stack-trace-on-error. |
| 135 (let* ((inhibit-quit t) | |
| 442 | 136 (debug-on-error nil) |
| 137 (etype (car-safe error-object))) | |
| 428 | 138 (setq quit-flag nil) |
| 139 (setq standard-output t) | |
| 140 (setq standard-input t) | |
| 141 (setq executing-kbd-macro nil) | |
| 142 (and errors-deactivate-region | |
| 143 (zmacs-deactivate-region)) | |
| 144 (discard-input) | |
| 145 | |
| 146 (setq last-error error-object) | |
| 147 | |
| 148 (message nil) | |
| 149 (ding nil (cond ((eq etype 'undefined-keystroke-sequence) | |
| 150 (if (and (vectorp (nth 1 error-object)) | |
| 151 (/= 0 (length (nth 1 error-object))) | |
| 152 (button-event-p (aref (nth 1 error-object) 0))) | |
| 153 'undefined-click | |
| 154 'undefined-key)) | |
| 155 ((eq etype 'quit) | |
| 156 'quit) | |
| 157 ((memq etype '(end-of-buffer beginning-of-buffer)) | |
| 158 'buffer-bound) | |
| 159 ((eq etype 'buffer-read-only) | |
| 160 'read-only) | |
| 161 (t 'command-error))) | |
| 162 (display-error error-object t) | |
| 163 | |
| 164 (if (noninteractive) | |
| 165 (progn | |
| 1445 | 166 (message "\n%s exiting.\n" emacs-program-name) |
| 428 | 167 (kill-emacs -1))) |
| 168 t)) | |
| 169 | |
| 170 (defun describe-last-error () | |
| 171 "Redisplay the last error-message. See the variable `last-error'." | |
| 172 (interactive) | |
| 173 (if last-error | |
| 174 (with-displaying-help-buffer | |
| 175 (lambda () | |
| 176 (princ "Last error was:\n" standard-output) | |
| 177 (display-error last-error standard-output))) | |
| 178 (message "No error yet"))) | |
| 179 | |
| 180 | |
| 181 ;;#### Must be done later in the loadup sequence | |
| 182 ;(define-key (symbol-function 'help-command) "e" 'describe-last-error) | |
| 183 | |
| 184 | |
| 185 (defun truncate-command-history-for-gc () | |
| 3698 | 186 ;; We should try to avoid accessing any bindings to speak of in this |
| 187 ;; function; as this hook is called asynchronously, the search for | |
| 188 ;; those bindings might search local bindings from essentially | |
| 189 ;; arbitrary functions. We force the body of the function to run at | |
| 190 ;; command-loop level, where the danger of local bindings is much | |
| 191 ;; reduced; the code can still do its job because the command history | |
| 192 ;; and values list will not grow before then anyway. | |
| 193 ;; | |
| 194 ;; Nothing is done in batch mode, both because it is a waste of time | |
| 195 ;; (there is no command loop!) and because this any GCs during dumping | |
| 196 ;; will invoke this code, and if it were to enqueue an eval event, | |
| 197 ;; the portable dumper would try to dump it and fail. | |
| 198 (if (not (noninteractive)) | |
| 199 (enqueue-eval-event | |
| 200 (lambda (arg) | |
| 201 (let ((tail (nthcdr 30 command-history))) | |
| 202 (if tail (setcdr tail nil))) | |
| 203 (let ((tail (nthcdr 30 values))) | |
| 204 (if tail (setcdr tail nil)))) | |
| 205 nil))) | |
| 428 | 206 |
| 207 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc) | |
| 208 | |
| 209 | |
| 210 ;;;; Object-oriented programming at its finest | |
| 211 | |
| 212 ;; Now in src/print.c; used by Ferror_message_string and others | |
| 213 ;(defun display-error (error-object stream) ;(defgeneric report-condition ...) | |
| 214 ; "Display `error-object' on `stream' in a user-friendly way." | |
| 215 ; (funcall (or (let ((type (car-safe error-object))) | |
| 216 ; (catch 'error | |
| 217 ; (and (consp error-object) | |
| 218 ; (symbolp type) | |
| 219 ; ;;(stringp (get type 'error-message)) | |
| 220 ; (consp (get type 'error-conditions)) | |
| 221 ; (let ((tail (cdr error-object))) | |
| 222 ; (while (not (null tail)) | |
| 223 ; (if (consp tail) | |
| 224 ; (setq tail (cdr tail)) | |
| 225 ; (throw 'error nil))) | |
| 226 ; t) | |
| 227 ; ;; (check-type condition condition) | |
| 228 ; (get type 'error-conditions) | |
| 229 ; ;; Search class hierarchy | |
| 230 ; (let ((tail (get type 'error-conditions))) | |
| 231 ; (while (not (null tail)) | |
| 232 ; (cond ((not (and (consp tail) | |
| 233 ; (symbolp (car tail)))) | |
| 234 ; (throw 'error nil)) | |
| 235 ; ((get (car tail) 'display-error) | |
| 236 ; (throw 'error (get (car tail) | |
| 237 ; 'display-error))) | |
| 238 ; (t | |
| 239 ; (setq tail (cdr tail))))) | |
| 240 ; ;; Default method | |
| 241 ; #'(lambda (error-object stream) | |
| 242 ; (let ((type (car error-object)) | |
| 243 ; (tail (cdr error-object)) | |
| 244 ; (first t) | |
| 245 ; (print-message-label 'error)) | |
| 246 ; (if (eq type 'error) | |
| 247 ; (progn (princ (car tail) stream) | |
| 248 ; (setq tail (cdr tail))) | |
| 249 ; (princ (or (gettext (get type 'error-message)) type) | |
| 250 ; stream)) | |
| 251 ; (while tail | |
| 252 ; (princ (if first ": " ", ") stream) | |
| 253 ; (prin1 (car tail) stream) | |
| 254 ; (setq tail (cdr tail) | |
| 255 ; first nil)))))))) | |
| 256 ; #'(lambda (error-object stream) | |
| 257 ; (princ (gettext "Peculiar error ") stream) | |
| 258 ; (prin1 error-object stream))) | |
| 259 ; error-object stream)) | |
| 260 | |
| 261 (put 'file-error 'display-error | |
| 262 #'(lambda (error-object stream) | |
| 1346 | 263 (let ((type (car error-object)) |
| 264 (tail (cdr error-object)) | |
| 265 (first t) | |
| 266 (print-message-label 'error)) | |
| 267 (if (eq type 'file-error) | |
| 268 (progn (princ (car tail) stream) | |
| 269 (setq tail (cdr tail))) | |
| 270 (princ (or (gettext (get type 'error-message)) type) | |
| 271 stream)) | |
| 272 (while tail | |
| 273 (princ (if first ": " ", ") stream) | |
| 274 (prin1 (car tail) stream) | |
| 275 (setq tail (cdr tail) | |
| 276 first nil))))) | |
| 428 | 277 |
| 278 (put 'undefined-keystroke-sequence 'display-error | |
| 279 #'(lambda (error-object stream) | |
| 280 (princ (key-description (car (cdr error-object))) stream) | |
| 281 ;; #### I18N3: doesn't localize properly. | |
| 282 (princ (gettext " not defined.") stream) ; doo dah, doo dah. | |
| 283 )) | |
| 284 | |
| 285 | |
| 286 (defcustom teach-extended-commands-p t | |
| 287 "*If true, then `\\[execute-extended-command]' will teach you keybindings. | |
| 288 Any time you execute a command with \\[execute-extended-command] which has a | |
| 289 shorter keybinding, you will be shown the alternate binding before the | |
| 290 command executes. There is a short pause after displaying the binding, | |
| 291 before executing it; the length can be controlled by | |
| 292 `teach-extended-commands-timeout'." | |
| 293 :type 'boolean | |
| 294 :group 'keyboard) | |
| 295 | |
| 296 (defcustom teach-extended-commands-timeout 4 | |
| 297 "*How long to pause after displaying a keybinding before executing. | |
| 298 The value is measured in seconds. This only applies if | |
| 299 `teach-extended-commands-p' is true." | |
| 300 :type 'number | |
| 301 :group 'keyboard) | |
| 302 | |
| 303 ;That damn RMS went off and implemented something differently, after | |
|
5208
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
304 ;we had already implemented it. |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
305 (defcustom suggest-key-bindings t |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
306 "*FSFmacs equivalent of `teach-extended-commands-p'. |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
307 Provided for compatibility only. |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
308 Non-nil means show the equivalent key-binding when M-x command has one. |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
309 The value can be a length of time to show the message for, in seconds. |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
310 |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
311 If the value is non-nil and not a number, we wait the number of seconds |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
312 specified by `teach-extended-commands-timeout'." |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
313 :type '(choice |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
314 (const :tag "off" nil) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
315 (integer :tag "time" 2) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
316 (other :tag "on"))) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
317 |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
318 (dontusethis-set-symbol-value-handler |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
319 'suggest-key-bindings |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
320 'set-value |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
321 #'(lambda (sym args fun harg handler) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
322 (setq args (car args)) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
323 (if (null args) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
324 (setq teach-extended-commands-p nil) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
325 (setq teach-extended-commands-p t |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
326 teach-extended-commands-timeout |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
327 (or (and (integerp args) args) |
|
9fa29ec759e3
Implement suggest-key-bindings in terms of teach-extended-commands-p
Aidan Kehoe <kehoea@parhasard.net>
parents:
4806
diff
changeset
|
328 (and args teach-extended-commands-timeout)))))) |
| 428 | 329 |
| 330 (defun execute-extended-command (prefix-arg) | |
| 331 "Read a command name from the minibuffer using 'completing-read'. | |
| 332 Then call the specified command using 'command-execute' and return its | |
| 333 return value. If the command asks for a prefix argument, supply the | |
| 334 value of the current raw prefix argument, or the value of PREFIX-ARG | |
| 335 when called from Lisp." | |
| 336 (interactive "P") | |
| 337 ;; Note: This doesn't hack "this-command-keys" | |
| 338 (let ((prefix-arg prefix-arg)) | |
| 339 (setq this-command (read-command | |
| 340 ;; Note: this has the hard-wired | |
| 341 ;; "C-u" and "M-x" string bug in common | |
| 613 | 342 ;; with all Emacs's. |
| 428 | 343 ;; (i.e. it prints C-u and M-x regardless of |
| 344 ;; whether some other keys were actually bound | |
| 345 ;; to `execute-extended-command' and | |
| 346 ;; `universal-argument'. | |
| 347 (cond ((eq prefix-arg '-) | |
| 348 "- M-x ") | |
| 349 ((equal prefix-arg '(4)) | |
| 350 "C-u M-x ") | |
| 351 ((integerp prefix-arg) | |
| 352 (format "%d M-x " prefix-arg)) | |
| 353 ((and (consp prefix-arg) | |
| 354 (integerp (car prefix-arg))) | |
| 355 (format "%d M-x " (car prefix-arg))) | |
| 356 (t | |
| 357 "M-x "))))) | |
| 358 | |
| 359 (if (and teach-extended-commands-p | |
| 360 (interactive-p)) | |
| 361 ;; Remember the keys, run the command, and show the keys (if | |
|
4806
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
362 ;; any). The symbol-macrolet avoids some lexical-scope lossage. |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
363 (symbol-macrolet |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
364 ((execute-command-keys #:execute-command-keys) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
365 (execute-command-name #:execute-command-name)) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
366 (let ((execute-command-keys (where-is-internal this-command)) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
367 (execute-command-name this-command)) ; the name can change |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
368 (command-execute this-command t) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
369 (when execute-command-keys |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
370 ;; Normally the region is adjusted in post_command_hook; |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
371 ;; however, it is not called until after we finish. It |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
372 ;; looks ugly for the region to get updated after the |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
373 ;; delays, so we do it now. The code below is a Lispified |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
374 ;; copy of code in event-stream.c:post_command_hook(). |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
375 (if (and (not zmacs-region-stays) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
376 (or (not (eq (selected-window) (minibuffer-window))) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
377 (eq (zmacs-region-buffer) (current-buffer)))) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
378 (zmacs-deactivate-region) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
379 (zmacs-update-region)) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
380 ;; Wait for a while, so the user can see a message printed, |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
381 ;; if any. |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
382 (when (sit-for 1) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
383 (display-message |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
384 'no-log |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
385 (format (if (cdr execute-command-keys) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
386 "Command `%s' is bound to keys: %s" |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
387 "Command `%s' is bound to key: %s") |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
388 execute-command-name |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
389 (sorted-key-descriptions execute-command-keys))) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
390 (sit-for teach-extended-commands-timeout) |
|
fd36a980d701
Use uninterned symbols in various information-hiding contexts.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4222
diff
changeset
|
391 (clear-message 'no-log))))) |
| 428 | 392 ;; Else, just run the command. |
| 393 (command-execute this-command t))) | |
| 394 | |
| 395 | |
| 396 ;;; C code calls this; the underscores in the variable names are to avoid | |
| 397 ;;; cluttering the specbind namespace (lexical scope! lexical scope!) | |
| 398 ;;; Putting this in Lisp instead of C slows kbd macros by 50%. | |
| 399 ;(defun command-execute (_command &optional _record-flag) | |
| 400 ; "Execute CMD as an editor command. | |
| 401 ;CMD must be a symbol that satisfies the `commandp' predicate. | |
| 402 ;Optional second arg RECORD-FLAG non-nil | |
| 403 ;means unconditionally put this command in `command-history'. | |
| 404 ;Otherwise, that is done only if an arg is read using the minibuffer." | |
| 405 ; (let ((_prefix prefix-arg) | |
| 406 ; (_cmd (indirect-function _command))) | |
| 407 ; (setq prefix-arg nil | |
| 408 ; this-command _command | |
| 409 ; current-prefix-arg _prefix | |
| 410 ; zmacs-region-stays nil) | |
| 411 ; ;; #### debug_on_next_call = 0; | |
| 412 ; (cond ((and (symbolp _command) | |
| 413 ; (get _command 'disabled)) | |
| 414 ; (run-hooks disabled-command-hook)) | |
| 415 ; ((or (stringp _cmd) (vectorp _cmd)) | |
| 416 ; ;; If requested, place the macro in the command history. | |
| 417 ; ;; For other sorts of commands, call-interactively takes | |
| 418 ; ;; care of this. | |
| 419 ; (if _record-flag | |
| 420 ; (setq command-history | |
| 421 ; (cons (list 'execute-kbd-macro _cmd _prefix) | |
| 422 ; command-history))) | |
| 423 ; (execute-kbd-macro _cmd _prefix)) | |
| 424 ; (t | |
| 425 ; (call-interactively _command _record-flag))))) | |
| 426 | |
| 427 (defun y-or-n-p-minibuf (prompt) | |
| 428 "Ask user a \"y or n\" question. Return t if answer is \"y\". | |
| 429 Takes one argument, which is the string to display to ask the question. | |
| 430 It should end in a space; `y-or-n-p' adds `(y or n) ' to it. | |
| 431 No confirmation of the answer is requested; a single character is enough. | |
| 432 Also accepts Space to mean yes, or Delete to mean no." | |
| 433 (save-excursion | |
| 434 (let* ((pre "") | |
| 435 (yn (gettext "(y or n) ")) | |
| 436 ;; we need to translate the prompt ourselves because of the | |
| 437 ;; strange way we handle it. | |
| 438 (prompt (gettext prompt)) | |
| 439 event) | |
| 440 (while (stringp yn) | |
| 441 (if (let ((cursor-in-echo-area t) | |
| 442 (inhibit-quit t)) | |
| 443 (message "%s%s%s" pre prompt yn) | |
| 444 (setq event (next-command-event event)) | |
| 445 (condition-case nil | |
| 446 (prog1 | |
| 447 (or quit-flag (eq 'keyboard-quit (key-binding event))) | |
| 448 (setq quit-flag nil)) | |
| 449 (wrong-type-argument t))) | |
| 450 (progn | |
| 451 (message "%s%s%s%s" pre prompt yn (single-key-description event)) | |
| 452 (setq quit-flag nil) | |
| 453 (signal 'quit '()))) | |
| 454 (let* ((keys (events-to-keys (vector event))) | |
| 455 (def (lookup-key query-replace-map keys))) | |
| 456 (cond ((eq def 'skip) | |
| 457 (message "%s%sNo" prompt yn) | |
| 458 (setq yn nil)) | |
| 459 ((eq def 'act) | |
| 460 (message "%s%sYes" prompt yn) | |
| 461 (setq yn t)) | |
| 462 ((eq def 'recenter) | |
| 463 (recenter)) | |
| 464 ((or (eq def 'quit) (eq def 'exit-prefix)) | |
| 465 (signal 'quit '())) | |
| 466 ((button-release-event-p event) ; ignore them | |
| 467 nil) | |
| 468 (t | |
| 469 (message "%s%s%s%s" pre prompt yn | |
| 470 (single-key-description event)) | |
| 471 (ding nil 'y-or-n-p) | |
| 472 (discard-input) | |
| 473 (if (= (length pre) 0) | |
| 474 (setq pre (gettext "Please answer y or n. "))))))) | |
| 475 yn))) | |
| 476 | |
| 477 (defun yes-or-no-p-minibuf (prompt) | |
| 478 "Ask user a yes-or-no question. Return t if answer is yes. | |
| 479 Takes one argument, which is the string to display to ask the question. | |
| 480 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it. | |
| 481 The user must confirm the answer with RET, | |
| 482 and can edit it until it has been confirmed." | |
| 483 (save-excursion | |
| 484 (let ((p (concat (gettext prompt) (gettext "(yes or no) "))) | |
| 485 (ans "")) | |
| 486 (while (stringp ans) | |
| 487 (setq ans (downcase (read-string p nil t))) ;no history | |
| 488 (cond ((string-equal ans (gettext "yes")) | |
| 489 (setq ans t)) | |
| 490 ((string-equal ans (gettext "no")) | |
| 491 (setq ans nil)) | |
| 492 (t | |
| 493 (ding nil 'yes-or-no-p) | |
| 494 (discard-input) | |
| 495 (message "Please answer yes or no.") | |
| 496 (sleep-for 2)))) | |
| 497 ans))) | |
| 498 | |
| 442 | 499 (defun yes-or-no-p (prompt) |
| 500 "Ask user a yes-or-no question. Return t if answer is yes. | |
| 501 The question is asked with a dialog box or the minibuffer, as appropriate. | |
| 502 Takes one argument, which is the string to display to ask the question. | |
| 503 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it. | |
| 504 The user must confirm the answer with RET, | |
| 505 and can edit it until it as been confirmed." | |
| 506 (if (should-use-dialog-box-p) | |
| 4222 | 507 ;; and-fboundp is redundant, since yes-or-no-p-dialog-box is only |
| 508 ;; bound if (featurep 'dialog). But it eliminates a compile-time | |
| 509 ;; warning. | |
| 510 (and-fboundp #'yes-or-no-p-dialog-box (yes-or-no-p-dialog-box prompt)) | |
| 442 | 511 (yes-or-no-p-minibuf prompt))) |
| 512 | |
| 513 (defun y-or-n-p (prompt) | |
| 514 "Ask user a \"y or n\" question. Return t if answer is \"y\". | |
| 515 Takes one argument, which is the string to display to ask the question. | |
| 516 The question is asked with a dialog box or the minibuffer, as appropriate. | |
| 517 It should end in a space; `y-or-n-p' adds `(y or n) ' to it. | |
| 518 No confirmation of the answer is requested; a single character is enough. | |
| 519 Also accepts Space to mean yes, or Delete to mean no." | |
| 520 (if (should-use-dialog-box-p) | |
| 521 (yes-or-no-p-dialog-box prompt) | |
| 522 (y-or-n-p-minibuf prompt))) | |
| 523 | |
| 428 | 524 |
| 525 | |
| 526 (defun read-char () | |
| 527 "Read a character from the command input (keyboard or macro). | |
| 528 If a mouse click or non-ASCII character is detected, an error is | |
| 529 signalled. The character typed is returned as an ASCII value. This | |
| 530 is most likely the wrong thing for you to be using: consider using | |
| 531 the `next-command-event' function instead." | |
| 532 (save-excursion | |
| 533 (let ((event (next-command-event))) | |
| 534 (or inhibit-quit | |
| 535 (and (event-matches-key-specifier-p event (quit-char)) | |
| 536 (signal 'quit nil))) | |
| 537 (prog1 (or (event-to-character event) | |
| 538 ;; Kludge. If the event we read was a mouse-release, | |
| 539 ;; discard it and read the next one. | |
| 540 (if (button-release-event-p event) | |
| 541 (event-to-character (next-command-event event))) | |
| 542 (error "Key read has no ASCII equivalent %S" event)) | |
| 543 ;; this is not necessary, but is marginally more efficient than GC. | |
| 544 (deallocate-event event))))) | |
| 545 | |
| 546 (defun read-char-exclusive () | |
| 547 "Read a character from the command input (keyboard or macro). | |
| 548 If a mouse click or non-ASCII character is detected, it is discarded. | |
| 549 The character typed is returned as an ASCII value. This is most likely | |
| 550 the wrong thing for you to be using: consider using the | |
| 551 `next-command-event' function instead." | |
| 552 (let (event ch) | |
| 553 (while (progn | |
| 554 (setq event (next-command-event)) | |
| 555 (or inhibit-quit | |
| 556 (and (event-matches-key-specifier-p event (quit-char)) | |
| 557 (signal 'quit nil))) | |
| 558 (setq ch (event-to-character event)) | |
| 559 (deallocate-event event) | |
| 560 (null ch))) | |
| 561 ch)) | |
| 562 | |
| 1333 | 563 ;;;; Input and display facilities. |
| 564 | |
| 565 ;; BEGIN SYNCHED WITH FSF 21.2. | |
| 566 | |
| 567 (defvar read-quoted-char-radix 8 | |
| 568 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'. | |
| 569 Legitimate radix values are 8, 10 and 16.") | |
| 570 | |
| 571 (custom-declare-variable-early | |
| 572 'read-quoted-char-radix 8 | |
| 573 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'. | |
| 574 Legitimate radix values are 8, 10 and 16." | |
| 575 :type '(choice (const 8) (const 10) (const 16)) | |
| 576 :group 'editing-basics) | |
| 577 | |
| 428 | 578 (defun read-quoted-char (&optional prompt) |
| 3341 | 579 ;; XEmacs change; description of the character code input |
| 1333 | 580 "Like `read-char', but do not allow quitting. |
| 3341 | 581 |
| 582 Also, if the first character read is a digit of base (the value of) | |
| 583 `read-quoted-char-radix', we read as many of such digits as are | |
| 584 typed and return a character with the corresponding Unicode code | |
| 3344 | 585 point. Any input that is not a digit (in the base used) terminates |
| 586 the sequence. If the terminator is RET, it is discarded; any other | |
| 3341 | 587 terminator is used itself as input. |
| 1333 | 588 |
| 589 The optional argument PROMPT specifies a string to use to prompt the user. | |
| 590 The variable `read-quoted-char-radix' controls which radix to use | |
| 591 for numeric input." | |
| 592 (let (;(message-log-max nil) | |
| 593 done (first t) (code 0) char event | |
| 428 | 594 (prompt (and prompt (gettext prompt))) |
| 1333 | 595 ) |
| 596 (while (not done) | |
| 597 (let ((inhibit-quit first) | |
| 3341 | 598 ;; Don't let C-h get the help message--only help |
| 599 ;; function keys. | |
| 600 ;; XEmacs: we don't support the help function keys as of | |
| 601 ;; 2006-04-16. GNU have a Vhelp_event_list in addition | |
| 602 ;; to help-char in src/keyboard.c, and it's only useful | |
| 603 ;; to set help-form while help-char is nil when that | |
| 604 ;; functionality is available. | |
| 428 | 605 (help-char nil) |
| 3341 | 606 (help-form (format |
| 428 | 607 "Type the special character you want to use, |
| 3341 | 608 or the character code, base %d (the value of `read-quoted-char-radix') |
| 1333 | 609 RET terminates the character code and is discarded; |
| 3341 | 610 any other non-digit terminates the character code and is then used as input." |
| 611 read-quoted-char-radix))) | |
| 428 | 612 (and prompt (display-message 'prompt (format "%s-" prompt))) |
| 613 (setq event (next-command-event) | |
| 3474 | 614 ;; If event-to-character fails, this is fine, we handle that |
| 615 ;; with the (null char) cond branch below. | |
| 616 char (event-to-character event)) | |
| 428 | 617 (if inhibit-quit (setq quit-flag nil))) |
| 1333 | 618 ;; Translate TAB key into control-I ASCII character, and so on. |
| 619 (and char | |
| 620 (let ((translated (lookup-key function-key-map (vector char)))) | |
| 621 (if (arrayp translated) | |
| 622 (setq char (aref translated 0))))) | |
| 623 (cond ((null char)) | |
| 624 ((not (characterp char)) | |
| 3196 | 625 ;; XEmacs change; event instead of char. |
| 626 (setq unread-command-events (list event) | |
| 1333 | 627 done t)) |
| 628 ; ((/= (logand char ?\M-\^@) 0) | |
| 629 ; ;; Turn a meta-character into a character with the 0200 bit set. | |
| 630 ; (setq code (logior (logand char (lognot ?\M-\^@)) 128) | |
| 631 ; done t)) | |
| 632 ((and (<= ?0 char) (< char (+ ?0 (min 10 read-quoted-char-radix)))) | |
| 633 (setq code (+ (* code read-quoted-char-radix) (- char ?0))) | |
| 634 (and prompt (setq prompt (display-message 'prompt | |
| 635 (format "%s %c" prompt char))))) | |
| 636 ((and (<= ?a (downcase char)) | |
| 637 (< (downcase char) (+ ?a -10 (min 26 read-quoted-char-radix)))) | |
| 638 (setq code (+ (* code read-quoted-char-radix) | |
| 639 (+ 10 (- (downcase char) ?a)))) | |
| 640 (and prompt (setq prompt (display-message 'prompt | |
| 641 (format "%s %c" prompt char))))) | |
| 642 ((and (not first) (eq char ?\C-m)) | |
| 643 (setq done t)) | |
| 644 ((not first) | |
| 3196 | 645 ;; XEmacs change; event instead of char. |
| 646 (setq unread-command-events (list event) | |
| 428 | 647 done t)) |
| 1346 | 648 (t (setq code (char-to-int char) |
| 1333 | 649 done t))) |
| 650 (setq first nil)) | |
| 3341 | 651 ;; XEmacs change; unicode-to-char instead of int-to-char |
| 652 (unicode-to-char code))) | |
| 1333 | 653 |
| 654 ;; in passwd.el. | |
| 655 ; (defun read-passwd (prompt &optional confirm default) | |
| 656 ; "Read a password, prompting with PROMPT. Echo `.' for each character typed. | |
| 657 ; End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. | |
| 658 ; Optional argument CONFIRM, if non-nil, then read it twice to make sure. | |
| 659 ; Optional DEFAULT is a default password to use instead of empty input." | |
| 660 ; (if confirm | |
| 661 ; (let (success) | |
| 662 ; (while (not success) | |
| 663 ; (let ((first (read-passwd prompt nil default)) | |
| 664 ; (second (read-passwd "Confirm password: " nil default))) | |
| 665 ; (if (equal first second) | |
| 666 ; (progn | |
| 667 ; (and (arrayp second) (fillarray second ?\0)) | |
| 668 ; (setq success first)) | |
| 669 ; (and (arrayp first) (fillarray first ?\0)) | |
| 670 ; (and (arrayp second) (fillarray second ?\0)) | |
| 671 ; (message "Password not repeated accurately; please start over") | |
| 672 ; (sit-for 1)))) | |
| 673 ; success) | |
| 674 ; (let ((pass nil) | |
| 675 ; (c 0) | |
| 676 ; (echo-keystrokes 0) | |
| 677 ; (cursor-in-echo-area t)) | |
| 678 ; (while (progn (message "%s%s" | |
| 679 ; prompt | |
| 680 ; (make-string (length pass) ?.)) | |
| 681 ; (setq c (read-char-exclusive nil t)) | |
| 682 ; (and (/= c ?\r) (/= c ?\n) (/= c ?\e))) | |
| 683 ; (clear-this-command-keys) | |
| 684 ; (if (= c ?\C-u) | |
| 685 ; (progn | |
| 686 ; (and (arrayp pass) (fillarray pass ?\0)) | |
| 687 ; (setq pass "")) | |
| 688 ; (if (and (/= c ?\b) (/= c ?\177)) | |
| 689 ; (let* ((new-char (char-to-string c)) | |
| 690 ; (new-pass (concat pass new-char))) | |
| 691 ; (and (arrayp pass) (fillarray pass ?\0)) | |
| 692 ; (fillarray new-char ?\0) | |
| 693 ; (setq c ?\0) | |
| 694 ; (setq pass new-pass)) | |
| 695 ; (if (> (length pass) 0) | |
| 696 ; (let ((new-pass (substring pass 0 -1))) | |
| 697 ; (and (arrayp pass) (fillarray pass ?\0)) | |
| 698 ; (setq pass new-pass)))))) | |
| 699 ; (message nil) | |
| 700 ; (or pass default "")))) | |
| 701 | |
| 702 ;; aliased to redraw-modeline, a built-in. | |
| 703 ; (defun force-mode-line-update (&optional all) | |
| 704 ; "Force the mode-line of the current buffer to be redisplayed. | |
| 705 ; With optional non-nil ALL, force redisplay of all mode-lines." | |
| 706 ; (if all (save-excursion (set-buffer (other-buffer)))) | |
| 707 ; (set-buffer-modified-p (buffer-modified-p))) | |
| 428 | 708 |
| 709 (defun momentary-string-display (string pos &optional exit-char message) | |
| 710 "Momentarily display STRING in the buffer at POS. | |
| 711 Display remains until next character is typed. | |
| 712 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed; | |
| 713 otherwise it is then available as input (as a command if nothing else). | |
| 714 Display MESSAGE (optional fourth arg) in the echo area. | |
| 715 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there." | |
| 716 (or exit-char (setq exit-char ?\ )) | |
| 1333 | 717 (let ((inhibit-read-only t) |
| 428 | 718 ;; Don't modify the undo list at all. |
| 719 (buffer-undo-list t) | |
| 720 (modified (buffer-modified-p)) | |
| 721 (name buffer-file-name) | |
| 722 insert-end) | |
| 723 (unwind-protect | |
| 724 (progn | |
| 725 (save-excursion | |
| 726 (goto-char pos) | |
| 727 ;; defeat file locking... don't try this at home, kids! | |
| 728 (setq buffer-file-name nil) | |
| 729 (insert-before-markers (gettext string)) | |
| 730 (setq insert-end (point)) | |
| 1333 | 731 ;; If the message end is off screen, recenter now. |
| 732 (if (< (window-end nil t) insert-end) | |
| 428 | 733 (recenter (/ (window-height) 2))) |
| 734 ;; If that pushed message start off the frame, | |
| 735 ;; scroll to start it at the top of the frame. | |
| 736 (move-to-window-line 0) | |
| 737 (if (> (point) pos) | |
| 738 (progn | |
| 739 (goto-char pos) | |
| 740 (recenter 0)))) | |
| 741 (message (or message (gettext "Type %s to continue editing.")) | |
| 742 (single-key-description exit-char)) | |
| 743 (let ((event (save-excursion (next-command-event)))) | |
| 744 (or (eq (event-to-character event) exit-char) | |
| 1333 | 745 (setq unread-command-events (list event))))) |
| 428 | 746 (if insert-end |
| 747 (save-excursion | |
| 748 (delete-region pos insert-end))) | |
| 749 (setq buffer-file-name name) | |
| 750 (set-buffer-modified-p modified)))) | |
| 751 | |
| 1333 | 752 ;; END SYNCHED WITH FSF 21.2. |
| 753 | |
| 428 | 754 ;;; cmdloop.el ends here |
