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