209
|
1 ;;; cmdloop.el --- support functions for the top-level command loop.
|
|
2
|
|
3 ;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
|
|
4
|
|
5 ;; Author: Richard Mlynarik
|
|
6 ;; Date: 8-Jul-92
|
|
7 ;; Maintainer: XEmacs Development Team
|
|
8 ;; Keywords: internal, dumped
|
|
9
|
|
10 ;; This file is part of XEmacs.
|
|
11
|
|
12 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
13 ;; under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
20 ;; General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
|
23 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
|
26
|
|
27 ;;; Synched up with: FSF 19.30. (Some of the stuff below is in FSF's subr.el.)
|
|
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)
|
|
73 (if (and (region-active-p)
|
|
74 (eq (current-buffer) (zmacs-region-buffer)))
|
|
75 ;; pseudo-zmacs compatibility: don't beep if this ^G is simply
|
|
76 ;; deactivating the region. If it is inactive, beep.
|
|
77 nil
|
|
78 (signal 'quit nil)))
|
|
79
|
|
80 (defvar buffer-quit-function nil
|
|
81 "Function to call to \"quit\" the current buffer, or nil if none.
|
|
82 \\[keyboard-escape-quit] calls this function when its more local actions
|
|
83 \(such as cancelling a prefix argument, minibuffer or region) do not apply.")
|
|
84
|
|
85 (defun keyboard-escape-quit ()
|
|
86 "Exit the current \"mode\" (in a generalized sense of the word).
|
|
87 This command can exit an interactive command such as `query-replace',
|
|
88 can clear out a prefix argument or a region,
|
|
89 can get out of the minibuffer or other recursive edit,
|
|
90 cancel the use of the current buffer (for special-purpose buffers),
|
|
91 or go back to just one window (by deleting all but the selected window)."
|
|
92 (interactive)
|
|
93 (cond ((eq last-command 'mode-exited) nil)
|
|
94 ((> (minibuffer-depth) 0)
|
|
95 (abort-recursive-edit))
|
|
96 (current-prefix-arg
|
|
97 nil)
|
|
98 ((region-active-p)
|
|
99 (zmacs-deactivate-region))
|
|
100 ((> (recursion-depth) 0)
|
|
101 (exit-recursive-edit))
|
|
102 (buffer-quit-function
|
|
103 (funcall buffer-quit-function))
|
|
104 ((not (one-window-p t))
|
|
105 (delete-other-windows))
|
|
106 ((string-match "^ \\*" (buffer-name (current-buffer)))
|
|
107 (bury-buffer))))
|
|
108
|
284
|
109 ;; Someone wrote: "This should really be a ring of last errors."
|
|
110 ;;
|
|
111 ;; But why bother? This stuff is not all that necessary now that we
|
|
112 ;; have message log, anyway.
|
209
|
113 (defvar last-error nil
|
284
|
114 "Object describing the last signaled error.")
|
209
|
115
|
|
116 (defcustom errors-deactivate-region nil
|
|
117 "*Non-nil means that errors will cause the region to be deactivated."
|
|
118 :type 'boolean
|
|
119 :group 'editing-basics)
|
|
120
|
|
121 (defun command-error (error-object)
|
|
122 (let ((inhibit-quit t)
|
|
123 (debug-on-error nil)
|
|
124 (etype (car-safe error-object)))
|
|
125 (setq quit-flag nil)
|
|
126 (setq standard-output t)
|
|
127 (setq standard-input t)
|
|
128 (setq executing-kbd-macro nil)
|
|
129 (and errors-deactivate-region
|
|
130 (zmacs-deactivate-region))
|
|
131 (discard-input)
|
|
132
|
|
133 (setq last-error error-object)
|
|
134
|
|
135 (message nil)
|
|
136 (ding nil (cond ((eq etype 'undefined-keystroke-sequence)
|
|
137 (if (and (vectorp (nth 1 error-object))
|
|
138 (/= 0 (length (nth 1 error-object)))
|
|
139 (button-event-p (aref (nth 1 error-object) 0)))
|
|
140 'undefined-click
|
|
141 'undefined-key))
|
|
142 ((eq etype 'quit)
|
|
143 'quit)
|
|
144 ((memq etype '(end-of-buffer beginning-of-buffer))
|
|
145 'buffer-bound)
|
|
146 ((eq etype 'buffer-read-only)
|
|
147 'read-only)
|
|
148 (t 'command-error)))
|
|
149 (display-error error-object t)
|
|
150
|
|
151 (if (noninteractive)
|
|
152 (progn
|
282
|
153 (message "%s exiting." emacs-program-name)
|
209
|
154 (kill-emacs -1)))
|
|
155 t))
|
|
156
|
|
157 (defun describe-last-error ()
|
|
158 "Redisplay the last error-message. See the variable `last-error'."
|
|
159 (interactive)
|
284
|
160 (if last-error
|
|
161 (with-displaying-help-buffer
|
|
162 (lambda ()
|
|
163 (princ "Last error was:\n" standard-output)
|
|
164 (display-error last-error standard-output)))
|
|
165 (message "No error yet")))
|
209
|
166
|
|
167
|
|
168 ;;#### Must be done later in the loadup sequence
|
|
169 ;(define-key (symbol-function 'help-command) "e" 'describe-last-error)
|
|
170
|
|
171
|
|
172 (defun truncate-command-history-for-gc ()
|
|
173 (let ((tail (nthcdr 30 command-history)))
|
|
174 (if tail (setcdr tail nil)))
|
|
175 (let ((tail (nthcdr 30 values)))
|
|
176 (if tail (setcdr tail nil)))
|
|
177 )
|
|
178
|
|
179 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc)
|
|
180
|
|
181
|
|
182 ;;;; Object-oriented programming at its finest
|
|
183
|
|
184 ;; Now in src/print.c; used by Ferror_message_string and others
|
|
185 ;(defun display-error (error-object stream) ;(defgeneric report-condition ...)
|
|
186 ; "Display `error-object' on `stream' in a user-friendly way."
|
|
187 ; (funcall (or (let ((type (car-safe error-object)))
|
|
188 ; (catch 'error
|
|
189 ; (and (consp error-object)
|
|
190 ; (symbolp type)
|
|
191 ; ;;(stringp (get type 'error-message))
|
|
192 ; (consp (get type 'error-conditions))
|
|
193 ; (let ((tail (cdr error-object)))
|
|
194 ; (while (not (null tail))
|
|
195 ; (if (consp tail)
|
|
196 ; (setq tail (cdr tail))
|
|
197 ; (throw 'error nil)))
|
|
198 ; t)
|
|
199 ; ;; (check-type condition condition)
|
|
200 ; (get type 'error-conditions)
|
|
201 ; ;; Search class hierarchy
|
|
202 ; (let ((tail (get type 'error-conditions)))
|
|
203 ; (while (not (null tail))
|
|
204 ; (cond ((not (and (consp tail)
|
|
205 ; (symbolp (car tail))))
|
|
206 ; (throw 'error nil))
|
|
207 ; ((get (car tail) 'display-error)
|
|
208 ; (throw 'error (get (car tail)
|
|
209 ; 'display-error)))
|
|
210 ; (t
|
|
211 ; (setq tail (cdr tail)))))
|
|
212 ; ;; Default method
|
|
213 ; #'(lambda (error-object stream)
|
|
214 ; (let ((type (car error-object))
|
|
215 ; (tail (cdr error-object))
|
|
216 ; (first t)
|
|
217 ; (print-message-label 'error))
|
|
218 ; (if (eq type 'error)
|
|
219 ; (progn (princ (car tail) stream)
|
|
220 ; (setq tail (cdr tail)))
|
|
221 ; (princ (or (gettext (get type 'error-message)) type)
|
|
222 ; stream))
|
|
223 ; (while tail
|
|
224 ; (princ (if first ": " ", ") stream)
|
|
225 ; (prin1 (car tail) stream)
|
|
226 ; (setq tail (cdr tail)
|
|
227 ; first nil))))))))
|
|
228 ; #'(lambda (error-object stream)
|
|
229 ; (princ (gettext "Peculiar error ") stream)
|
|
230 ; (prin1 error-object stream)))
|
|
231 ; error-object stream))
|
|
232
|
|
233 (put 'file-error 'display-error
|
|
234 #'(lambda (error-object stream)
|
|
235 (let ((tail (cdr error-object))
|
|
236 (first t))
|
|
237 (princ (car tail) stream)
|
|
238 (while (setq tail (cdr tail))
|
|
239 (princ (if first ": " ", ") stream)
|
|
240 (princ (car tail) stream)
|
|
241 (setq first nil)))))
|
|
242
|
|
243 (put 'undefined-keystroke-sequence 'display-error
|
|
244 #'(lambda (error-object stream)
|
|
245 (princ (key-description (car (cdr error-object))) stream)
|
|
246 ;; #### I18N3: doesn't localize properly.
|
|
247 (princ (gettext " not defined.") stream) ; doo dah, doo dah.
|
|
248 ))
|
|
249
|
|
250
|
|
251 (defcustom teach-extended-commands-p t
|
|
252 "*If true, then `\\[execute-extended-command]' will teach you keybindings.
|
|
253 Any time you execute a command with \\[execute-extended-command] which has a
|
|
254 shorter keybinding, you will be shown the alternate binding before the
|
|
255 command executes. There is a short pause after displaying the binding,
|
|
256 before executing it; the length can be controlled by
|
|
257 `teach-extended-commands-timeout'."
|
|
258 :type 'boolean
|
|
259 :group 'keyboard)
|
|
260
|
|
261 (defcustom teach-extended-commands-timeout 4
|
|
262 "*How long to pause after displaying a keybinding before executing.
|
|
263 The value is measured in seconds. This only applies if
|
|
264 `teach-extended-commands-p' is true."
|
|
265 :type 'number
|
|
266 :group 'keyboard)
|
|
267
|
276
|
268 ;That damn RMS went off and implemented something differently, after
|
|
269 ;we had already implemented it. We can't support both properly until
|
|
270 ;we have Lisp magic variables.
|
209
|
271 ;(defvar suggest-key-bindings t
|
|
272 ; "*FSFmacs equivalent of `teach-extended-commands-*'.
|
|
273 ;Provided for compatibility only.
|
|
274 ;Non-nil means show the equivalent key-binding when M-x command has one.
|
|
275 ;The value can be a length of time to show the message for.
|
|
276 ;If the value is non-nil and not a number, we wait 2 seconds.")
|
|
277 ;
|
|
278 ;(make-obsolete-variable 'suggest-key-bindings 'teach-extended-commands-p)
|
|
279
|
|
280 (defun execute-extended-command (prefix-arg)
|
|
281 "Read a command name from the minibuffer using 'completing-read'.
|
|
282 Then call the specified command using 'command-execute' and return its
|
|
283 return value. If the command asks for a prefix argument, supply the
|
|
284 value of the current raw prefix argument, or the value of PREFIX-ARG
|
|
285 when called from Lisp."
|
|
286 (interactive "P")
|
|
287 ;; Note: This doesn't hack "this-command-keys"
|
|
288 (let ((prefix-arg prefix-arg))
|
|
289 (setq this-command (read-command
|
|
290 ;; Note: this has the hard-wired
|
|
291 ;; "C-u" and "M-x" string bug in common
|
|
292 ;; with all GNU Emacs's.
|
|
293 ;; (i.e. it prints C-u and M-x regardless of
|
|
294 ;; whether some other keys were actually bound
|
|
295 ;; to `execute-extended-command' and
|
|
296 ;; `universal-argument'.
|
|
297 (cond ((eq prefix-arg '-)
|
|
298 "- M-x ")
|
|
299 ((equal prefix-arg '(4))
|
|
300 "C-u M-x ")
|
|
301 ((integerp prefix-arg)
|
|
302 (format "%d M-x " prefix-arg))
|
|
303 ((and (consp prefix-arg)
|
|
304 (integerp (car prefix-arg)))
|
|
305 (format "%d M-x " (car prefix-arg)))
|
|
306 (t
|
|
307 "M-x ")))))
|
|
308
|
|
309 (if (and teach-extended-commands-p
|
|
310 (interactive-p))
|
|
311 ;; We need to fiddle with keys: remember the keys, run the
|
|
312 ;; command, and show the keys (if any).
|
|
313 (let ((_execute_command_keys_ (where-is-internal this-command))
|
|
314 (_execute_command_name_ this-command)) ; the name can change
|
|
315 (command-execute this-command t)
|
|
316 (when (and _execute_command_keys_
|
|
317 ;; Wait for a while, so the user can see a message
|
|
318 ;; printed, if any.
|
|
319 (sit-for 1))
|
|
320 (display-message
|
|
321 'no-log
|
|
322 (format "Command `%s' is bound to key%s: %s"
|
|
323 _execute_command_name_
|
|
324 (if (cdr _execute_command_keys_) "s" "")
|
|
325 (sorted-key-descriptions _execute_command_keys_)))
|
|
326 (sit-for teach-extended-commands-timeout)
|
|
327 (clear-message 'no-log)))
|
|
328 ;; Else, just run the command.
|
|
329 (command-execute this-command t)))
|
|
330
|
|
331
|
|
332 ;;; C code calls this; the underscores in the variable names are to avoid
|
|
333 ;;; cluttering the specbind namespace (lexical scope! lexical scope!)
|
|
334 ;;; Putting this in Lisp instead of C slows kbd macros by 50%.
|
|
335 ;(defun command-execute (_command &optional _record-flag)
|
|
336 ; "Execute CMD as an editor command.
|
|
337 ;CMD must be a symbol that satisfies the `commandp' predicate.
|
|
338 ;Optional second arg RECORD-FLAG non-nil
|
|
339 ;means unconditionally put this command in `command-history'.
|
|
340 ;Otherwise, that is done only if an arg is read using the minibuffer."
|
|
341 ; (let ((_prefix prefix-arg)
|
|
342 ; (_cmd (indirect-function _command)))
|
|
343 ; (setq prefix-arg nil
|
|
344 ; this-command _command
|
|
345 ; current-prefix-arg _prefix
|
|
346 ; zmacs-region-stays nil)
|
|
347 ; ;; #### debug_on_next_call = 0;
|
|
348 ; (cond ((and (symbolp _command)
|
|
349 ; (get _command 'disabled))
|
|
350 ; (run-hooks disabled-command-hook))
|
|
351 ; ((or (stringp _cmd) (vectorp _cmd))
|
|
352 ; ;; If requested, place the macro in the command history.
|
|
353 ; ;; For other sorts of commands, call-interactively takes
|
|
354 ; ;; care of this.
|
|
355 ; (if _record-flag
|
|
356 ; (setq command-history
|
|
357 ; (cons (list 'execute-kbd-macro _cmd _prefix)
|
|
358 ; command-history)))
|
|
359 ; (execute-kbd-macro _cmd _prefix))
|
|
360 ; (t
|
|
361 ; (call-interactively _command _record-flag)))))
|
|
362
|
|
363 (defun y-or-n-p-minibuf (prompt)
|
|
364 "Ask user a \"y or n\" question. Return t if answer is \"y\".
|
|
365 Takes one argument, which is the string to display to ask the question.
|
|
366 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
|
|
367 No confirmation of the answer is requested; a single character is enough.
|
|
368 Also accepts Space to mean yes, or Delete to mean no."
|
|
369 (save-excursion
|
|
370 (let* ((pre "")
|
|
371 (yn (gettext "(y or n) "))
|
|
372 ;; we need to translate the prompt ourselves because of the
|
|
373 ;; strange way we handle it.
|
|
374 (prompt (gettext prompt))
|
|
375 event)
|
|
376 (while (stringp yn)
|
|
377 (if (let ((cursor-in-echo-area t)
|
|
378 (inhibit-quit t))
|
|
379 (message "%s%s%s" pre prompt yn)
|
|
380 (setq event (next-command-event event))
|
|
381 (condition-case nil
|
|
382 (prog1
|
|
383 (or quit-flag (eq 'keyboard-quit (key-binding event)))
|
|
384 (setq quit-flag nil))
|
|
385 (wrong-type-argument t)))
|
|
386 (progn
|
|
387 (message "%s%s%s%s" pre prompt yn (single-key-description event))
|
|
388 (setq quit-flag nil)
|
|
389 (signal 'quit '())))
|
|
390 (let* ((keys (events-to-keys (vector event)))
|
|
391 (def (lookup-key query-replace-map keys)))
|
|
392 (cond ((eq def 'skip)
|
|
393 (message "%s%sNo" prompt yn)
|
|
394 (setq yn nil))
|
|
395 ((eq def 'act)
|
|
396 (message "%s%sYes" prompt yn)
|
|
397 (setq yn t))
|
|
398 ((eq def 'recenter)
|
|
399 (recenter))
|
|
400 ((or (eq def 'quit) (eq def 'exit-prefix))
|
|
401 (signal 'quit '()))
|
|
402 ((button-release-event-p event) ; ignore them
|
|
403 nil)
|
|
404 (t
|
|
405 (message "%s%s%s%s" pre prompt yn
|
|
406 (single-key-description event))
|
|
407 (ding nil 'y-or-n-p)
|
|
408 (discard-input)
|
|
409 (if (= (length pre) 0)
|
|
410 (setq pre (gettext "Please answer y or n. ")))))))
|
|
411 yn)))
|
|
412
|
|
413 (defun yes-or-no-p-minibuf (prompt)
|
|
414 "Ask user a yes-or-no question. Return t if answer is yes.
|
|
415 Takes one argument, which is the string to display to ask the question.
|
|
416 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
|
|
417 The user must confirm the answer with RET,
|
|
418 and can edit it until it has been confirmed."
|
|
419 (save-excursion
|
|
420 (let ((p (concat (gettext prompt) (gettext "(yes or no) ")))
|
|
421 (ans ""))
|
|
422 (while (stringp ans)
|
|
423 (setq ans (downcase (read-string p nil t))) ;no history
|
|
424 (cond ((string-equal ans (gettext "yes"))
|
|
425 (setq ans 't))
|
|
426 ((string-equal ans (gettext "no"))
|
|
427 (setq ans 'nil))
|
|
428 (t
|
|
429 (ding nil 'yes-or-no-p)
|
|
430 (discard-input)
|
|
431 (message "Please answer yes or no.")
|
|
432 (sleep-for 2))))
|
|
433 ans)))
|
|
434
|
|
435 ;; these may be redefined later, but make the original def easily encapsulable
|
|
436 (define-function 'yes-or-no-p 'yes-or-no-p-minibuf)
|
|
437 (define-function 'y-or-n-p 'y-or-n-p-minibuf)
|
|
438
|
|
439
|
|
440 (defun read-char ()
|
|
441 "Read a character from the command input (keyboard or macro).
|
|
442 If a mouse click or non-ASCII character is detected, an error is
|
|
443 signalled. The character typed is returned as an ASCII value. This
|
|
444 is most likely the wrong thing for you to be using: consider using
|
|
445 the `next-command-event' function instead."
|
|
446 (save-excursion
|
284
|
447 (let ((event (next-command-event)))
|
|
448 (or inhibit-quit
|
|
449 (and (event-matches-key-specifier-p event (quit-char))
|
|
450 (signal 'quit nil)))
|
209
|
451 (prog1 (or (event-to-character event)
|
|
452 ;; Kludge. If the event we read was a mouse-release,
|
|
453 ;; discard it and read the next one.
|
|
454 (if (button-release-event-p event)
|
|
455 (event-to-character (next-command-event event)))
|
|
456 (error "Key read has no ASCII equivalent %S" event))
|
|
457 ;; this is not necessary, but is marginally more efficient than GC.
|
|
458 (deallocate-event event)))))
|
|
459
|
|
460 (defun read-char-exclusive ()
|
|
461 "Read a character from the command input (keyboard or macro).
|
|
462 If a mouse click or non-ASCII character is detected, it is discarded.
|
|
463 The character typed is returned as an ASCII value. This is most likely
|
|
464 the wrong thing for you to be using: consider using the
|
|
465 `next-command-event' function instead."
|
284
|
466 (let (event ch)
|
209
|
467 (while (progn
|
|
468 (setq event (next-command-event))
|
284
|
469 (or inhibit-quit
|
|
470 (and (event-matches-key-specifier-p event (quit-char))
|
|
471 (signal 'quit nil)))
|
209
|
472 (setq ch (event-to-character event))
|
|
473 (deallocate-event event)
|
|
474 (null ch)))
|
|
475 ch))
|
|
476
|
|
477 (defun read-quoted-char (&optional prompt)
|
|
478 "Like `read-char', except that if the first character read is an octal
|
|
479 digit, we read up to two more octal digits and return the character
|
|
480 represented by the octal number consisting of those digits.
|
|
481 Optional argument PROMPT specifies a string to use to prompt the user."
|
284
|
482 (let ((count 0) (code 0) done
|
|
483 (prompt (and prompt (gettext prompt)))
|
|
484 char event)
|
|
485 (while (and (not done) (< count 3))
|
|
486 (let ((inhibit-quit (zerop count))
|
209
|
487 ;; Don't let C-h get the help message--only help function keys.
|
|
488 (help-char nil)
|
|
489 (help-form
|
|
490 "Type the special character you want to use,
|
|
491 or three octal digits representing its character code."))
|
284
|
492 (and prompt (display-message 'prompt (format "%s-" prompt)))
|
|
493 (setq event (next-command-event)
|
|
494 char (or (event-to-character event nil nil t)
|
|
495 (signal 'error
|
|
496 (list "key read cannot be inserted in a buffer"
|
|
497 event))))
|
|
498 (if inhibit-quit (setq quit-flag nil)))
|
|
499 (cond ((<= ?0 char ?7)
|
|
500 (setq code (+ (* code 8) (- char ?0))
|
|
501 count (1+ count))
|
|
502 (when prompt
|
|
503 (display-message 'prompt
|
|
504 (setq prompt (format "%s %c" prompt char)))))
|
|
505 ((> count 0)
|
|
506 (setq unread-command-event event
|
|
507 done t))
|
|
508 (t (setq code (char-int char)
|
|
509 done t))))
|
|
510 (int-char code)
|
209
|
511 ;; Turn a meta-character into a character with the 0200 bit set.
|
284
|
512 ; (logior (if (/= (logand code ?\M-\^@) 0) 128 0)
|
|
513 ; (logand 255 code))))
|
|
514 ))
|
209
|
515
|
|
516 (defun momentary-string-display (string pos &optional exit-char message)
|
|
517 "Momentarily display STRING in the buffer at POS.
|
|
518 Display remains until next character is typed.
|
|
519 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
|
|
520 otherwise it is then available as input (as a command if nothing else).
|
|
521 Display MESSAGE (optional fourth arg) in the echo area.
|
|
522 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
|
|
523 (or exit-char (setq exit-char ?\ ))
|
|
524 (let ((buffer-read-only nil)
|
|
525 ;; Don't modify the undo list at all.
|
|
526 (buffer-undo-list t)
|
|
527 (modified (buffer-modified-p))
|
|
528 (name buffer-file-name)
|
|
529 insert-end)
|
|
530 (unwind-protect
|
|
531 (progn
|
|
532 (save-excursion
|
|
533 (goto-char pos)
|
|
534 ;; defeat file locking... don't try this at home, kids!
|
|
535 (setq buffer-file-name nil)
|
|
536 (insert-before-markers (gettext string))
|
|
537 (setq insert-end (point))
|
|
538 ;; If the message end is off frame, recenter now.
|
|
539 (if (> (window-end) insert-end)
|
|
540 (recenter (/ (window-height) 2)))
|
|
541 ;; If that pushed message start off the frame,
|
|
542 ;; scroll to start it at the top of the frame.
|
|
543 (move-to-window-line 0)
|
|
544 (if (> (point) pos)
|
|
545 (progn
|
|
546 (goto-char pos)
|
|
547 (recenter 0))))
|
|
548 (message (or message (gettext "Type %s to continue editing."))
|
|
549 (single-key-description exit-char))
|
|
550 (let ((event (save-excursion (next-command-event))))
|
|
551 (or (eq (event-to-character event) exit-char)
|
|
552 (setq unread-command-event event))))
|
|
553 (if insert-end
|
|
554 (save-excursion
|
|
555 (delete-region pos insert-end)))
|
|
556 (setq buffer-file-name name)
|
|
557 (set-buffer-modified-p modified))))
|
|
558
|
|
559 ;;; cmdloop.el ends here
|