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 ()
|
|
186 (let ((tail (nthcdr 30 command-history)))
|
|
187 (if tail (setcdr tail nil)))
|
|
188 (let ((tail (nthcdr 30 values)))
|
|
189 (if tail (setcdr tail nil)))
|
|
190 )
|
|
191
|
|
192 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc)
|
|
193
|
|
194
|
|
195 ;;;; Object-oriented programming at its finest
|
|
196
|
|
197 ;; Now in src/print.c; used by Ferror_message_string and others
|
|
198 ;(defun display-error (error-object stream) ;(defgeneric report-condition ...)
|
|
199 ; "Display `error-object' on `stream' in a user-friendly way."
|
|
200 ; (funcall (or (let ((type (car-safe error-object)))
|
|
201 ; (catch 'error
|
|
202 ; (and (consp error-object)
|
|
203 ; (symbolp type)
|
|
204 ; ;;(stringp (get type 'error-message))
|
|
205 ; (consp (get type 'error-conditions))
|
|
206 ; (let ((tail (cdr error-object)))
|
|
207 ; (while (not (null tail))
|
|
208 ; (if (consp tail)
|
|
209 ; (setq tail (cdr tail))
|
|
210 ; (throw 'error nil)))
|
|
211 ; t)
|
|
212 ; ;; (check-type condition condition)
|
|
213 ; (get type 'error-conditions)
|
|
214 ; ;; Search class hierarchy
|
|
215 ; (let ((tail (get type 'error-conditions)))
|
|
216 ; (while (not (null tail))
|
|
217 ; (cond ((not (and (consp tail)
|
|
218 ; (symbolp (car tail))))
|
|
219 ; (throw 'error nil))
|
|
220 ; ((get (car tail) 'display-error)
|
|
221 ; (throw 'error (get (car tail)
|
|
222 ; 'display-error)))
|
|
223 ; (t
|
|
224 ; (setq tail (cdr tail)))))
|
|
225 ; ;; Default method
|
|
226 ; #'(lambda (error-object stream)
|
|
227 ; (let ((type (car error-object))
|
|
228 ; (tail (cdr error-object))
|
|
229 ; (first t)
|
|
230 ; (print-message-label 'error))
|
|
231 ; (if (eq type 'error)
|
|
232 ; (progn (princ (car tail) stream)
|
|
233 ; (setq tail (cdr tail)))
|
|
234 ; (princ (or (gettext (get type 'error-message)) type)
|
|
235 ; stream))
|
|
236 ; (while tail
|
|
237 ; (princ (if first ": " ", ") stream)
|
|
238 ; (prin1 (car tail) stream)
|
|
239 ; (setq tail (cdr tail)
|
|
240 ; first nil))))))))
|
|
241 ; #'(lambda (error-object stream)
|
|
242 ; (princ (gettext "Peculiar error ") stream)
|
|
243 ; (prin1 error-object stream)))
|
|
244 ; error-object stream))
|
|
245
|
|
246 (put 'file-error 'display-error
|
|
247 #'(lambda (error-object stream)
|
1346
|
248 (let ((type (car error-object))
|
|
249 (tail (cdr error-object))
|
|
250 (first t)
|
|
251 (print-message-label 'error))
|
|
252 (if (eq type 'file-error)
|
|
253 (progn (princ (car tail) stream)
|
|
254 (setq tail (cdr tail)))
|
|
255 (princ (or (gettext (get type 'error-message)) type)
|
|
256 stream))
|
|
257 (while tail
|
|
258 (princ (if first ": " ", ") stream)
|
|
259 (prin1 (car tail) stream)
|
|
260 (setq tail (cdr tail)
|
|
261 first nil)))))
|
428
|
262
|
|
263 (put 'undefined-keystroke-sequence 'display-error
|
|
264 #'(lambda (error-object stream)
|
|
265 (princ (key-description (car (cdr error-object))) stream)
|
|
266 ;; #### I18N3: doesn't localize properly.
|
|
267 (princ (gettext " not defined.") stream) ; doo dah, doo dah.
|
|
268 ))
|
|
269
|
|
270
|
|
271 (defcustom teach-extended-commands-p t
|
|
272 "*If true, then `\\[execute-extended-command]' will teach you keybindings.
|
|
273 Any time you execute a command with \\[execute-extended-command] which has a
|
|
274 shorter keybinding, you will be shown the alternate binding before the
|
|
275 command executes. There is a short pause after displaying the binding,
|
|
276 before executing it; the length can be controlled by
|
|
277 `teach-extended-commands-timeout'."
|
|
278 :type 'boolean
|
|
279 :group 'keyboard)
|
|
280
|
|
281 (defcustom teach-extended-commands-timeout 4
|
|
282 "*How long to pause after displaying a keybinding before executing.
|
|
283 The value is measured in seconds. This only applies if
|
|
284 `teach-extended-commands-p' is true."
|
|
285 :type 'number
|
|
286 :group 'keyboard)
|
|
287
|
|
288 ;That damn RMS went off and implemented something differently, after
|
|
289 ;we had already implemented it. We can't support both properly until
|
|
290 ;we have Lisp magic variables.
|
|
291 ;(defvar suggest-key-bindings t
|
|
292 ; "*FSFmacs equivalent of `teach-extended-commands-*'.
|
|
293 ;Provided for compatibility only.
|
|
294 ;Non-nil means show the equivalent key-binding when M-x command has one.
|
|
295 ;The value can be a length of time to show the message for.
|
|
296 ;If the value is non-nil and not a number, we wait 2 seconds.")
|
|
297 ;
|
|
298 ;(make-obsolete-variable 'suggest-key-bindings 'teach-extended-commands-p)
|
|
299
|
|
300 (defun execute-extended-command (prefix-arg)
|
|
301 "Read a command name from the minibuffer using 'completing-read'.
|
|
302 Then call the specified command using 'command-execute' and return its
|
|
303 return value. If the command asks for a prefix argument, supply the
|
|
304 value of the current raw prefix argument, or the value of PREFIX-ARG
|
|
305 when called from Lisp."
|
|
306 (interactive "P")
|
|
307 ;; Note: This doesn't hack "this-command-keys"
|
|
308 (let ((prefix-arg prefix-arg))
|
|
309 (setq this-command (read-command
|
|
310 ;; Note: this has the hard-wired
|
|
311 ;; "C-u" and "M-x" string bug in common
|
613
|
312 ;; with all Emacs's.
|
428
|
313 ;; (i.e. it prints C-u and M-x regardless of
|
|
314 ;; whether some other keys were actually bound
|
|
315 ;; to `execute-extended-command' and
|
|
316 ;; `universal-argument'.
|
|
317 (cond ((eq prefix-arg '-)
|
|
318 "- M-x ")
|
|
319 ((equal prefix-arg '(4))
|
|
320 "C-u M-x ")
|
|
321 ((integerp prefix-arg)
|
|
322 (format "%d M-x " prefix-arg))
|
|
323 ((and (consp prefix-arg)
|
|
324 (integerp (car prefix-arg)))
|
|
325 (format "%d M-x " (car prefix-arg)))
|
|
326 (t
|
|
327 "M-x ")))))
|
|
328
|
|
329 (if (and teach-extended-commands-p
|
|
330 (interactive-p))
|
|
331 ;; Remember the keys, run the command, and show the keys (if
|
|
332 ;; any). The funny variable names are a poor man's guarantee
|
|
333 ;; that we don't get tripped by this-command doing something
|
|
334 ;; funny. Quoth our forefathers: "We want lexical scope!"
|
|
335 (let ((_execute_command_keys_ (where-is-internal this-command))
|
|
336 (_execute_command_name_ this-command)) ; the name can change
|
|
337 (command-execute this-command t)
|
|
338 (when _execute_command_keys_
|
|
339 ;; Normally the region is adjusted in post_command_hook;
|
|
340 ;; however, it is not called until after we finish. It
|
|
341 ;; looks ugly for the region to get updated after the
|
|
342 ;; delays, so we do it now. The code below is a Lispified
|
|
343 ;; copy of code in event-stream.c:post_command_hook().
|
|
344 (if (and (not zmacs-region-stays)
|
|
345 (or (not (eq (selected-window) (minibuffer-window)))
|
|
346 (eq (zmacs-region-buffer) (current-buffer))))
|
|
347 (zmacs-deactivate-region)
|
|
348 (zmacs-update-region))
|
|
349 ;; Wait for a while, so the user can see a message printed,
|
|
350 ;; if any.
|
|
351 (when (sit-for 1)
|
|
352 (display-message
|
|
353 'no-log
|
|
354 (format (if (cdr _execute_command_keys_)
|
|
355 "Command `%s' is bound to keys: %s"
|
|
356 "Command `%s' is bound to key: %s")
|
|
357 _execute_command_name_
|
|
358 (sorted-key-descriptions _execute_command_keys_)))
|
|
359 (sit-for teach-extended-commands-timeout)
|
|
360 (clear-message 'no-log))))
|
|
361 ;; Else, just run the command.
|
|
362 (command-execute this-command t)))
|
|
363
|
|
364
|
|
365 ;;; C code calls this; the underscores in the variable names are to avoid
|
|
366 ;;; cluttering the specbind namespace (lexical scope! lexical scope!)
|
|
367 ;;; Putting this in Lisp instead of C slows kbd macros by 50%.
|
|
368 ;(defun command-execute (_command &optional _record-flag)
|
|
369 ; "Execute CMD as an editor command.
|
|
370 ;CMD must be a symbol that satisfies the `commandp' predicate.
|
|
371 ;Optional second arg RECORD-FLAG non-nil
|
|
372 ;means unconditionally put this command in `command-history'.
|
|
373 ;Otherwise, that is done only if an arg is read using the minibuffer."
|
|
374 ; (let ((_prefix prefix-arg)
|
|
375 ; (_cmd (indirect-function _command)))
|
|
376 ; (setq prefix-arg nil
|
|
377 ; this-command _command
|
|
378 ; current-prefix-arg _prefix
|
|
379 ; zmacs-region-stays nil)
|
|
380 ; ;; #### debug_on_next_call = 0;
|
|
381 ; (cond ((and (symbolp _command)
|
|
382 ; (get _command 'disabled))
|
|
383 ; (run-hooks disabled-command-hook))
|
|
384 ; ((or (stringp _cmd) (vectorp _cmd))
|
|
385 ; ;; If requested, place the macro in the command history.
|
|
386 ; ;; For other sorts of commands, call-interactively takes
|
|
387 ; ;; care of this.
|
|
388 ; (if _record-flag
|
|
389 ; (setq command-history
|
|
390 ; (cons (list 'execute-kbd-macro _cmd _prefix)
|
|
391 ; command-history)))
|
|
392 ; (execute-kbd-macro _cmd _prefix))
|
|
393 ; (t
|
|
394 ; (call-interactively _command _record-flag)))))
|
|
395
|
|
396 (defun y-or-n-p-minibuf (prompt)
|
|
397 "Ask user a \"y or n\" question. Return t if answer is \"y\".
|
|
398 Takes one argument, which is the string to display to ask the question.
|
|
399 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
|
|
400 No confirmation of the answer is requested; a single character is enough.
|
|
401 Also accepts Space to mean yes, or Delete to mean no."
|
|
402 (save-excursion
|
|
403 (let* ((pre "")
|
|
404 (yn (gettext "(y or n) "))
|
|
405 ;; we need to translate the prompt ourselves because of the
|
|
406 ;; strange way we handle it.
|
|
407 (prompt (gettext prompt))
|
|
408 event)
|
|
409 (while (stringp yn)
|
|
410 (if (let ((cursor-in-echo-area t)
|
|
411 (inhibit-quit t))
|
|
412 (message "%s%s%s" pre prompt yn)
|
|
413 (setq event (next-command-event event))
|
|
414 (condition-case nil
|
|
415 (prog1
|
|
416 (or quit-flag (eq 'keyboard-quit (key-binding event)))
|
|
417 (setq quit-flag nil))
|
|
418 (wrong-type-argument t)))
|
|
419 (progn
|
|
420 (message "%s%s%s%s" pre prompt yn (single-key-description event))
|
|
421 (setq quit-flag nil)
|
|
422 (signal 'quit '())))
|
|
423 (let* ((keys (events-to-keys (vector event)))
|
|
424 (def (lookup-key query-replace-map keys)))
|
|
425 (cond ((eq def 'skip)
|
|
426 (message "%s%sNo" prompt yn)
|
|
427 (setq yn nil))
|
|
428 ((eq def 'act)
|
|
429 (message "%s%sYes" prompt yn)
|
|
430 (setq yn t))
|
|
431 ((eq def 'recenter)
|
|
432 (recenter))
|
|
433 ((or (eq def 'quit) (eq def 'exit-prefix))
|
|
434 (signal 'quit '()))
|
|
435 ((button-release-event-p event) ; ignore them
|
|
436 nil)
|
|
437 (t
|
|
438 (message "%s%s%s%s" pre prompt yn
|
|
439 (single-key-description event))
|
|
440 (ding nil 'y-or-n-p)
|
|
441 (discard-input)
|
|
442 (if (= (length pre) 0)
|
|
443 (setq pre (gettext "Please answer y or n. ")))))))
|
|
444 yn)))
|
|
445
|
|
446 (defun yes-or-no-p-minibuf (prompt)
|
|
447 "Ask user a yes-or-no question. Return t if answer is yes.
|
|
448 Takes one argument, which is the string to display to ask the question.
|
|
449 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
|
|
450 The user must confirm the answer with RET,
|
|
451 and can edit it until it has been confirmed."
|
|
452 (save-excursion
|
|
453 (let ((p (concat (gettext prompt) (gettext "(yes or no) ")))
|
|
454 (ans ""))
|
|
455 (while (stringp ans)
|
|
456 (setq ans (downcase (read-string p nil t))) ;no history
|
|
457 (cond ((string-equal ans (gettext "yes"))
|
|
458 (setq ans t))
|
|
459 ((string-equal ans (gettext "no"))
|
|
460 (setq ans nil))
|
|
461 (t
|
|
462 (ding nil 'yes-or-no-p)
|
|
463 (discard-input)
|
|
464 (message "Please answer yes or no.")
|
|
465 (sleep-for 2))))
|
|
466 ans)))
|
|
467
|
442
|
468 (defun yes-or-no-p (prompt)
|
|
469 "Ask user a yes-or-no question. Return t if answer is yes.
|
|
470 The question is asked with a dialog box or the minibuffer, as appropriate.
|
|
471 Takes one argument, which is the string to display to ask the question.
|
|
472 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
|
|
473 The user must confirm the answer with RET,
|
|
474 and can edit it until it as been confirmed."
|
|
475 (if (should-use-dialog-box-p)
|
|
476 (yes-or-no-p-dialog-box prompt)
|
|
477 (yes-or-no-p-minibuf prompt)))
|
|
478
|
|
479 (defun y-or-n-p (prompt)
|
|
480 "Ask user a \"y or n\" question. Return t if answer is \"y\".
|
|
481 Takes one argument, which is the string to display to ask the question.
|
|
482 The question is asked with a dialog box or the minibuffer, as appropriate.
|
|
483 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
|
|
484 No confirmation of the answer is requested; a single character is enough.
|
|
485 Also accepts Space to mean yes, or Delete to mean no."
|
|
486 (if (should-use-dialog-box-p)
|
|
487 (yes-or-no-p-dialog-box prompt)
|
|
488 (y-or-n-p-minibuf prompt)))
|
|
489
|
428
|
490
|
|
491
|
|
492 (defun read-char ()
|
|
493 "Read a character from the command input (keyboard or macro).
|
|
494 If a mouse click or non-ASCII character is detected, an error is
|
|
495 signalled. The character typed is returned as an ASCII value. This
|
|
496 is most likely the wrong thing for you to be using: consider using
|
|
497 the `next-command-event' function instead."
|
|
498 (save-excursion
|
|
499 (let ((event (next-command-event)))
|
|
500 (or inhibit-quit
|
|
501 (and (event-matches-key-specifier-p event (quit-char))
|
|
502 (signal 'quit nil)))
|
|
503 (prog1 (or (event-to-character event)
|
|
504 ;; Kludge. If the event we read was a mouse-release,
|
|
505 ;; discard it and read the next one.
|
|
506 (if (button-release-event-p event)
|
|
507 (event-to-character (next-command-event event)))
|
|
508 (error "Key read has no ASCII equivalent %S" event))
|
|
509 ;; this is not necessary, but is marginally more efficient than GC.
|
|
510 (deallocate-event event)))))
|
|
511
|
|
512 (defun read-char-exclusive ()
|
|
513 "Read a character from the command input (keyboard or macro).
|
|
514 If a mouse click or non-ASCII character is detected, it is discarded.
|
|
515 The character typed is returned as an ASCII value. This is most likely
|
|
516 the wrong thing for you to be using: consider using the
|
|
517 `next-command-event' function instead."
|
|
518 (let (event ch)
|
|
519 (while (progn
|
|
520 (setq event (next-command-event))
|
|
521 (or inhibit-quit
|
|
522 (and (event-matches-key-specifier-p event (quit-char))
|
|
523 (signal 'quit nil)))
|
|
524 (setq ch (event-to-character event))
|
|
525 (deallocate-event event)
|
|
526 (null ch)))
|
|
527 ch))
|
|
528
|
1333
|
529 ;;;; Input and display facilities.
|
|
530
|
|
531 ;; BEGIN SYNCHED WITH FSF 21.2.
|
|
532
|
|
533 (defvar read-quoted-char-radix 8
|
|
534 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
|
|
535 Legitimate radix values are 8, 10 and 16.")
|
|
536
|
|
537 (custom-declare-variable-early
|
|
538 'read-quoted-char-radix 8
|
|
539 "*Radix for \\[quoted-insert] and other uses of `read-quoted-char'.
|
|
540 Legitimate radix values are 8, 10 and 16."
|
|
541 :type '(choice (const 8) (const 10) (const 16))
|
|
542 :group 'editing-basics)
|
|
543
|
428
|
544 (defun read-quoted-char (&optional prompt)
|
1333
|
545 "Like `read-char', but do not allow quitting.
|
|
546 Also, if the first character read is an octal digit,
|
|
547 we read any number of octal digits and return the
|
|
548 specified character code. Any nondigit terminates the sequence.
|
|
549 If the terminator is RET, it is discarded;
|
|
550 any other terminator is used itself as input.
|
|
551
|
|
552 The optional argument PROMPT specifies a string to use to prompt the user.
|
|
553 The variable `read-quoted-char-radix' controls which radix to use
|
|
554 for numeric input."
|
|
555 (let (;(message-log-max nil)
|
|
556 done (first t) (code 0) char event
|
428
|
557 (prompt (and prompt (gettext prompt)))
|
1333
|
558 )
|
|
559 (while (not done)
|
|
560 (let ((inhibit-quit first)
|
428
|
561 ;; Don't let C-h get the help message--only help function keys.
|
|
562 (help-char nil)
|
|
563 (help-form
|
|
564 "Type the special character you want to use,
|
1333
|
565 or the octal character code.
|
|
566 RET terminates the character code and is discarded;
|
|
567 any other non-digit terminates the character code and is then used as input."))
|
428
|
568 (and prompt (display-message 'prompt (format "%s-" prompt)))
|
|
569 (setq event (next-command-event)
|
2828
|
570 char (or (event-to-character event)
|
428
|
571 (signal 'error
|
|
572 (list "key read cannot be inserted in a buffer"
|
|
573 event))))
|
|
574 (if inhibit-quit (setq quit-flag nil)))
|
1333
|
575 ;; Translate TAB key into control-I ASCII character, and so on.
|
|
576 (and char
|
|
577 (let ((translated (lookup-key function-key-map (vector char))))
|
|
578 (if (arrayp translated)
|
|
579 (setq char (aref translated 0)))))
|
|
580 (cond ((null char))
|
|
581 ((not (characterp char))
|
|
582 (setq unread-command-events (list char)
|
|
583 done t))
|
|
584 ; ((/= (logand char ?\M-\^@) 0)
|
|
585 ; ;; Turn a meta-character into a character with the 0200 bit set.
|
|
586 ; (setq code (logior (logand char (lognot ?\M-\^@)) 128)
|
|
587 ; done t))
|
|
588 ((and (<= ?0 char) (< char (+ ?0 (min 10 read-quoted-char-radix))))
|
|
589 (setq code (+ (* code read-quoted-char-radix) (- char ?0)))
|
|
590 (and prompt (setq prompt (display-message 'prompt
|
|
591 (format "%s %c" prompt char)))))
|
|
592 ((and (<= ?a (downcase char))
|
|
593 (< (downcase char) (+ ?a -10 (min 26 read-quoted-char-radix))))
|
|
594 (setq code (+ (* code read-quoted-char-radix)
|
|
595 (+ 10 (- (downcase char) ?a))))
|
|
596 (and prompt (setq prompt (display-message 'prompt
|
|
597 (format "%s %c" prompt char)))))
|
|
598 ((and (not first) (eq char ?\C-m))
|
|
599 (setq done t))
|
|
600 ((not first)
|
|
601 (setq unread-command-events (list char)
|
428
|
602 done t))
|
1346
|
603 (t (setq code (char-to-int char)
|
1333
|
604 done t)))
|
|
605 (setq first nil))
|
|
606 (int-to-char code)))
|
|
607
|
|
608 ;; in passwd.el.
|
|
609 ; (defun read-passwd (prompt &optional confirm default)
|
|
610 ; "Read a password, prompting with PROMPT. Echo `.' for each character typed.
|
|
611 ; End with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line.
|
|
612 ; Optional argument CONFIRM, if non-nil, then read it twice to make sure.
|
|
613 ; Optional DEFAULT is a default password to use instead of empty input."
|
|
614 ; (if confirm
|
|
615 ; (let (success)
|
|
616 ; (while (not success)
|
|
617 ; (let ((first (read-passwd prompt nil default))
|
|
618 ; (second (read-passwd "Confirm password: " nil default)))
|
|
619 ; (if (equal first second)
|
|
620 ; (progn
|
|
621 ; (and (arrayp second) (fillarray second ?\0))
|
|
622 ; (setq success first))
|
|
623 ; (and (arrayp first) (fillarray first ?\0))
|
|
624 ; (and (arrayp second) (fillarray second ?\0))
|
|
625 ; (message "Password not repeated accurately; please start over")
|
|
626 ; (sit-for 1))))
|
|
627 ; success)
|
|
628 ; (let ((pass nil)
|
|
629 ; (c 0)
|
|
630 ; (echo-keystrokes 0)
|
|
631 ; (cursor-in-echo-area t))
|
|
632 ; (while (progn (message "%s%s"
|
|
633 ; prompt
|
|
634 ; (make-string (length pass) ?.))
|
|
635 ; (setq c (read-char-exclusive nil t))
|
|
636 ; (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
|
|
637 ; (clear-this-command-keys)
|
|
638 ; (if (= c ?\C-u)
|
|
639 ; (progn
|
|
640 ; (and (arrayp pass) (fillarray pass ?\0))
|
|
641 ; (setq pass ""))
|
|
642 ; (if (and (/= c ?\b) (/= c ?\177))
|
|
643 ; (let* ((new-char (char-to-string c))
|
|
644 ; (new-pass (concat pass new-char)))
|
|
645 ; (and (arrayp pass) (fillarray pass ?\0))
|
|
646 ; (fillarray new-char ?\0)
|
|
647 ; (setq c ?\0)
|
|
648 ; (setq pass new-pass))
|
|
649 ; (if (> (length pass) 0)
|
|
650 ; (let ((new-pass (substring pass 0 -1)))
|
|
651 ; (and (arrayp pass) (fillarray pass ?\0))
|
|
652 ; (setq pass new-pass))))))
|
|
653 ; (message nil)
|
|
654 ; (or pass default ""))))
|
|
655
|
|
656 ;; aliased to redraw-modeline, a built-in.
|
|
657 ; (defun force-mode-line-update (&optional all)
|
|
658 ; "Force the mode-line of the current buffer to be redisplayed.
|
|
659 ; With optional non-nil ALL, force redisplay of all mode-lines."
|
|
660 ; (if all (save-excursion (set-buffer (other-buffer))))
|
|
661 ; (set-buffer-modified-p (buffer-modified-p)))
|
428
|
662
|
|
663 (defun momentary-string-display (string pos &optional exit-char message)
|
|
664 "Momentarily display STRING in the buffer at POS.
|
|
665 Display remains until next character is typed.
|
|
666 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
|
|
667 otherwise it is then available as input (as a command if nothing else).
|
|
668 Display MESSAGE (optional fourth arg) in the echo area.
|
|
669 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
|
|
670 (or exit-char (setq exit-char ?\ ))
|
1333
|
671 (let ((inhibit-read-only t)
|
428
|
672 ;; Don't modify the undo list at all.
|
|
673 (buffer-undo-list t)
|
|
674 (modified (buffer-modified-p))
|
|
675 (name buffer-file-name)
|
|
676 insert-end)
|
|
677 (unwind-protect
|
|
678 (progn
|
|
679 (save-excursion
|
|
680 (goto-char pos)
|
|
681 ;; defeat file locking... don't try this at home, kids!
|
|
682 (setq buffer-file-name nil)
|
|
683 (insert-before-markers (gettext string))
|
|
684 (setq insert-end (point))
|
1333
|
685 ;; If the message end is off screen, recenter now.
|
|
686 (if (< (window-end nil t) insert-end)
|
428
|
687 (recenter (/ (window-height) 2)))
|
|
688 ;; If that pushed message start off the frame,
|
|
689 ;; scroll to start it at the top of the frame.
|
|
690 (move-to-window-line 0)
|
|
691 (if (> (point) pos)
|
|
692 (progn
|
|
693 (goto-char pos)
|
|
694 (recenter 0))))
|
|
695 (message (or message (gettext "Type %s to continue editing."))
|
|
696 (single-key-description exit-char))
|
|
697 (let ((event (save-excursion (next-command-event))))
|
|
698 (or (eq (event-to-character event) exit-char)
|
1333
|
699 (setq unread-command-events (list event)))))
|
428
|
700 (if insert-end
|
|
701 (save-excursion
|
|
702 (delete-region pos insert-end)))
|
|
703 (setq buffer-file-name name)
|
|
704 (set-buffer-modified-p modified))))
|
|
705
|
1333
|
706 ;; END SYNCHED WITH FSF 21.2.
|
|
707
|
428
|
708 ;;; cmdloop.el ends here
|