9e9a56afa06de3c1d09d6ba922b556c75d7f6b1b
[chise/xemacs-chise.git.1] / lisp / cmdloop.el
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
109 ;; `cancel-mode-internal' is a function of a misc-user event, which is
110 ;; queued when window system directs XEmacs frame to cancel any modal
111 ;; behavior it exposes, like mouse pointer grabbing.
112 ;;
113 ;; This function does nothing at the top level, but the code which
114 ;; runs modal event loops, such as selection drag loop in `mouse-track',
115 ;; check if misc-user function symbol is `cancel-mode-internal', and
116 ;; takes necessary cleanup actions.
117 (defun cancel-mode-internal (object)
118   (setq zmacs-region-stays t))
119 \f
120 ;; Someone wrote: "This should really be a ring of last errors."
121 ;;
122 ;; But why bother?  This stuff is not all that necessary now that we
123 ;; have message log, anyway.
124 (defvar last-error nil
125   "Object describing the last signaled error.")
126
127 (defcustom errors-deactivate-region nil
128   "*Non-nil means that errors will cause the region to be deactivated."
129   :type 'boolean
130   :group 'editing-basics)
131
132 (defun command-error (error-object)
133   (let* ((old-debug-on-error debug-on-error)
134          (inhibit-quit t)
135          (debug-on-error nil)
136          (etype (car-safe error-object)))
137     (setq quit-flag nil)
138     (setq standard-output t)
139     (setq standard-input t)
140     (setq executing-kbd-macro nil)
141     (and errors-deactivate-region
142          (zmacs-deactivate-region))
143     (discard-input)
144
145     (setq last-error error-object)
146
147     (message nil)
148     (ding nil (cond ((eq etype 'undefined-keystroke-sequence)
149                      (if (and (vectorp (nth 1 error-object))
150                               (/= 0 (length (nth 1 error-object)))
151                               (button-event-p (aref (nth 1 error-object) 0)))
152                          'undefined-click
153                        'undefined-key))
154                     ((eq etype 'quit)
155                      'quit)
156                     ((memq etype '(end-of-buffer beginning-of-buffer))
157                      'buffer-bound)
158                     ((eq etype 'buffer-read-only)
159                      'read-only)
160                     (t 'command-error)))
161     (display-error error-object t)
162
163     (if (noninteractive)
164         (progn
165           (if old-debug-on-error
166               (progn
167                 (message "Backtrace:\n\n")
168                 (backtrace)
169                 (message "\n")))
170           (message "%s exiting\n." emacs-program-name)
171           (kill-emacs -1)))
172     t))
173
174 (defun describe-last-error ()
175   "Redisplay the last error-message.  See the variable `last-error'."
176   (interactive)
177   (if last-error
178       (with-displaying-help-buffer
179        (lambda ()
180          (princ "Last error was:\n" standard-output)
181          (display-error last-error standard-output)))
182     (message "No error yet")))
183
184
185 ;;#### Must be done later in the loadup sequence
186 ;(define-key (symbol-function 'help-command) "e" 'describe-last-error)
187
188
189 (defun truncate-command-history-for-gc ()
190   ;; We should try to avoid accessing any bindings to speak of in this
191   ;; function; as this hook is called asynchronously, the search for
192   ;; those bindings might search local bindings from essentially
193   ;; arbitrary functions. We force the body of the function to run at
194   ;; command-loop level, where the danger of local bindings is much
195   ;; reduced; the code can still do its job because the command history
196   ;; and values list will not grow before then anyway.
197   ;;
198   ;; Nothing is done in batch mode, both because it is a waste of time
199   ;; (there is no command loop!) and because this any GCs during dumping
200   ;; will invoke this code, and if it were to enqueue an eval event,
201   ;; the portable dumper would try to dump it and fail.
202   (if (not (noninteractive))
203       (enqueue-eval-event
204        #'(lambda (arg)
205            (let ((tail (nthcdr 30 command-history)))
206              (if tail (setcdr tail nil)))
207            (let ((tail (nthcdr 30 values)))
208              (if tail (setcdr tail nil))))
209        nil)))
210
211 (add-hook 'pre-gc-hook 'truncate-command-history-for-gc)
212
213 \f
214 ;;;; Object-oriented programming at its finest
215
216 ;; Now in src/print.c; used by Ferror_message_string and others
217 ;(defun display-error (error-object stream) ;(defgeneric report-condition ...)
218 ;  "Display `error-object' on `stream' in a user-friendly way."
219 ;  (funcall (or (let ((type (car-safe error-object)))
220 ;                 (catch 'error
221 ;                   (and (consp error-object)
222 ;                        (symbolp type)
223 ;                        ;;(stringp (get type 'error-message))
224 ;                       (consp (get type 'error-conditions))
225 ;                        (let ((tail (cdr error-object)))
226 ;                          (while (not (null tail))
227 ;                            (if (consp tail)
228 ;                                (setq tail (cdr tail))
229 ;                                (throw 'error nil)))
230 ;                          t)
231 ;                        ;; (check-type condition condition)
232 ;                        (get type 'error-conditions)
233 ;                        ;; Search class hierarchy
234 ;                        (let ((tail (get type 'error-conditions)))
235 ;                          (while (not (null tail))
236 ;                            (cond ((not (and (consp tail)
237 ;                                             (symbolp (car tail))))
238 ;                                   (throw 'error nil))
239 ;                                  ((get (car tail) 'display-error)
240 ;                                   (throw 'error (get (car tail)
241 ;                                                      'display-error)))
242 ;                                  (t
243 ;                                   (setq tail (cdr tail)))))
244 ;                          ;; Default method
245 ;                          #'(lambda (error-object stream)
246 ;                              (let ((type (car error-object))
247 ;                                    (tail (cdr error-object))
248 ;                                    (first t)
249 ;                                   (print-message-label 'error))
250 ;                                (if (eq type 'error)
251 ;                                    (progn (princ (car tail) stream)
252 ;                                           (setq tail (cdr tail)))
253 ;                                 (princ (or (gettext (get type 'error-message)) type)
254 ;                                        stream))
255 ;                                (while tail
256 ;                                  (princ (if first ": " ", ") stream)
257 ;                                  (prin1 (car tail) stream)
258 ;                                  (setq tail (cdr tail)
259 ;                                        first nil))))))))
260 ;              #'(lambda (error-object stream)
261 ;                   (princ (gettext "Peculiar error ") stream)
262 ;                   (prin1 error-object stream)))
263 ;           error-object stream))
264
265 (put 'file-error 'display-error
266      #'(lambda (error-object stream)
267          (let ((tail (cdr error-object))
268                (first t))
269            (princ (car tail) stream)
270            (while (setq tail (cdr tail))
271              (princ (if first ": " ", ") stream)
272              (princ (car tail) stream)
273              (setq first nil)))))
274
275 (put 'undefined-keystroke-sequence 'display-error
276      #'(lambda (error-object stream)
277          (princ (key-description (car (cdr error-object))) stream)
278          ;; #### I18N3: doesn't localize properly.
279          (princ (gettext " not defined.") stream) ; doo dah, doo dah.
280          ))
281
282 \f
283 (defcustom teach-extended-commands-p t
284   "*If true, then `\\[execute-extended-command]' will teach you keybindings.
285 Any time you execute a command with \\[execute-extended-command] which has a
286 shorter keybinding, you will be shown the alternate binding before the
287 command executes.  There is a short pause after displaying the binding,
288 before executing it; the length can be controlled by
289 `teach-extended-commands-timeout'."
290   :type 'boolean
291   :group 'keyboard)
292
293 (defcustom teach-extended-commands-timeout 4
294   "*How long to pause after displaying a keybinding before executing.
295 The value is measured in seconds.  This only applies if
296 `teach-extended-commands-p' is true."
297   :type 'number
298   :group 'keyboard)
299
300 ;That damn RMS went off and implemented something differently, after
301 ;we had already implemented it.  We can't support both properly until
302 ;we have Lisp magic variables.
303 ;(defvar suggest-key-bindings t
304 ;  "*FSFmacs equivalent of `teach-extended-commands-*'.
305 ;Provided for compatibility only.
306 ;Non-nil means show the equivalent key-binding when M-x command has one.
307 ;The value can be a length of time to show the message for.
308 ;If the value is non-nil and not a number, we wait 2 seconds.")
309 ;
310 ;(make-obsolete-variable 'suggest-key-bindings 'teach-extended-commands-p)
311
312 (defun execute-extended-command (prefix-arg)
313   "Read a command name from the minibuffer using 'completing-read'.
314 Then call the specified command using 'command-execute' and return its
315 return value.  If the command asks for a prefix argument, supply the
316 value of the current raw prefix argument, or the value of PREFIX-ARG
317 when called from Lisp."
318   (interactive "P")
319   ;; Note:  This doesn't hack "this-command-keys"
320   (let ((prefix-arg prefix-arg))
321     (setq this-command (read-command
322                         ;; Note: this has the hard-wired
323                         ;;  "C-u" and "M-x" string bug in common
324                         ;;  with all GNU Emacs's.
325                         ;; (i.e. it prints C-u and M-x regardless of
326                         ;; whether some other keys were actually bound
327                         ;; to `execute-extended-command' and 
328                         ;; `universal-argument'.
329                         (cond ((eq prefix-arg '-)
330                                "- M-x ")
331                               ((equal prefix-arg '(4))
332                                "C-u M-x ")
333                               ((integerp prefix-arg)
334                                (format "%d M-x " prefix-arg))
335                               ((and (consp prefix-arg)
336                                     (integerp (car prefix-arg)))
337                                (format "%d M-x " (car prefix-arg)))
338                               (t
339                                "M-x ")))))
340
341   (if (and teach-extended-commands-p
342            (interactive-p))
343       ;; Remember the keys, run the command, and show the keys (if
344       ;; any).  The funny variable names are a poor man's guarantee
345       ;; that we don't get tripped by this-command doing something
346       ;; funny.  Quoth our forefathers: "We want lexical scope!"
347       (let ((_execute_command_keys_ (where-is-internal this-command))
348             (_execute_command_name_ this-command)) ; the name can change
349         (command-execute this-command t)
350         (when _execute_command_keys_
351           ;; Normally the region is adjusted in post_command_hook;
352           ;; however, it is not called until after we finish.  It
353           ;; looks ugly for the region to get updated after the
354           ;; delays, so we do it now.  The code below is a Lispified
355           ;; copy of code in event-stream.c:post_command_hook().
356           (if (and (not zmacs-region-stays)
357                    (or (not (eq (selected-window) (minibuffer-window)))
358                        (eq (zmacs-region-buffer) (current-buffer))))
359               (zmacs-deactivate-region)
360             (zmacs-update-region))
361           ;; Wait for a while, so the user can see a message printed,
362           ;; if any.
363           (when (sit-for 1)
364             (display-message
365                 'no-log
366               (format (if (cdr _execute_command_keys_)
367                           "Command `%s' is bound to keys: %s"
368                         "Command `%s' is bound to key: %s")
369                       _execute_command_name_
370                       (sorted-key-descriptions _execute_command_keys_)))
371             (sit-for teach-extended-commands-timeout)
372             (clear-message 'no-log))))
373     ;; Else, just run the command.
374     (command-execute this-command t)))
375
376
377 ;;; C code calls this; the underscores in the variable names are to avoid
378 ;;; cluttering the specbind namespace (lexical scope!  lexical scope!)
379 ;;; Putting this in Lisp instead of C slows kbd macros by 50%.
380 ;(defun command-execute (_command &optional _record-flag)
381 ;  "Execute CMD as an editor command.
382 ;CMD must be a symbol that satisfies the `commandp' predicate.
383 ;Optional second arg RECORD-FLAG non-nil
384 ;means unconditionally put this command in `command-history'.
385 ;Otherwise, that is done only if an arg is read using the minibuffer."
386 ;  (let ((_prefix prefix-arg)
387 ;        (_cmd (indirect-function _command)))
388 ;    (setq prefix-arg nil
389 ;          this-command _command
390 ;          current-prefix-arg _prefix
391 ;          zmacs-region-stays nil)
392 ;    ;; #### debug_on_next_call = 0;
393 ;    (cond ((and (symbolp _command)
394 ;                (get _command 'disabled))
395 ;           (run-hooks disabled-command-hook))
396 ;          ((or (stringp _cmd) (vectorp _cmd))
397 ;           ;; If requested, place the macro in the command history.  
398 ;           ;;  For other sorts of commands, call-interactively takes
399 ;           ;;  care of this. 
400 ;           (if _record-flag
401 ;               (setq command-history
402 ;                     (cons (list 'execute-kbd-macro _cmd _prefix)
403 ;                           command-history)))
404 ;             (execute-kbd-macro _cmd _prefix))
405 ;            (t
406 ;             (call-interactively _command _record-flag)))))
407 \f
408 (defun y-or-n-p-minibuf (prompt)
409   "Ask user a \"y or n\" question.  Return t if answer is \"y\", nil if \"n\".
410 Takes one argument, which is the string to display to ask the question.
411 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
412 No confirmation of the answer is requested; a single character is enough.
413 Also accepts Space to mean yes, or Delete to mean no."
414   (save-excursion
415     (let* ((pre "")
416            (yn (gettext "(y or n) "))
417            ;; we need to translate the prompt ourselves because of the
418            ;; strange way we handle it.
419            (prompt (gettext prompt))
420            event)
421       (while (stringp yn)
422         (if (let ((cursor-in-echo-area t)
423                   (inhibit-quit t))
424               (message "%s%s%s" pre prompt yn)
425               (setq event (next-command-event event))
426               (condition-case nil
427                   (prog1
428                       (or quit-flag (eq 'keyboard-quit (key-binding event)))
429                     (setq quit-flag nil))
430                 (wrong-type-argument t)))
431             (progn
432               (message "%s%s%s%s" pre prompt yn (single-key-description event))
433               (setq quit-flag nil)
434               (signal 'quit '())))
435         (let* ((keys (events-to-keys (vector event)))
436                (def (lookup-key query-replace-map keys)))
437           (cond ((eq def 'skip)
438                  (message "%s%sNo" prompt yn)
439                  (setq yn nil))
440                 ((eq def 'act)
441                  (message "%s%sYes" prompt yn)
442                  (setq yn t))
443                 ((eq def 'recenter)
444                  (recenter))
445                 ((or (eq def 'quit) (eq def 'exit-prefix))
446                  (signal 'quit '()))
447                 ((button-release-event-p event) ; ignore them
448                  nil)
449                 (t
450                  (message "%s%s%s%s" pre prompt yn
451                           (single-key-description event))
452                  (ding nil 'y-or-n-p)
453                  (discard-input)
454                  (if (= (length pre) 0)
455                      (setq pre (gettext "Please answer y or n.  ")))))))
456       yn)))
457
458 (defun yes-or-no-p-minibuf (prompt)
459   "Ask user a yes-or-no question.  Return t if answer is yes.
460 Takes one argument, which is the string to display to ask the question.
461 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
462 The user must confirm the answer with RET,
463 and can edit it until it has been confirmed."
464   (save-excursion
465     (let ((p (concat (gettext prompt) (gettext "(yes or no) ")))
466           (ans ""))
467       (while (stringp ans)
468         (setq ans (downcase (read-string p nil t))) ;no history
469         (cond ((string-equal ans (gettext "yes"))
470                (setq ans t))
471               ((string-equal ans (gettext "no"))
472                (setq ans nil))
473               (t
474                (ding nil 'yes-or-no-p)
475                (discard-input)
476                (message "Please answer yes or no.")
477                (sleep-for 2))))
478       ans)))
479
480 (defun yes-or-no-p (prompt)
481   "Ask user a yes-or-no question.  Return t if answer is yes.
482 The question is asked with a dialog box or the minibuffer, as appropriate.
483 Takes one argument, which is the string to display to ask the question.
484 It should end in a space; `yes-or-no-p' adds `(yes or no) ' to it.
485 The user must confirm the answer with RET,
486 and can edit it until it as been confirmed."
487   (if (should-use-dialog-box-p)
488       (yes-or-no-p-dialog-box prompt)
489     (yes-or-no-p-minibuf prompt)))
490
491 (defun y-or-n-p (prompt)
492   "Ask user a \"y or n\" question.  Return t if answer is \"y\", nil if \"n\".
493 Takes one argument, which is the string to display to ask the question.
494 The question is asked with a dialog box or the minibuffer, as appropriate.
495 It should end in a space; `y-or-n-p' adds `(y or n) ' to it.
496 No confirmation of the answer is requested; a single character is enough.
497 Also accepts Space to mean yes, or Delete to mean no."
498   (if (should-use-dialog-box-p)
499       (yes-or-no-p-dialog-box prompt)
500     (y-or-n-p-minibuf prompt)))
501
502 \f
503
504 (defun read-char ()
505   "Read a character from the command input (keyboard or macro).
506 If a mouse click or non-ASCII character is detected, an error is
507 signalled.  The character typed is returned as an ASCII value.  This
508 is most likely the wrong thing for you to be using: consider using
509 the `next-command-event' function instead."
510   (save-excursion
511     (let ((event (next-command-event)))
512       (or inhibit-quit
513           (and (event-matches-key-specifier-p event (quit-char))
514                (signal 'quit nil)))
515       (prog1 (or (event-to-character event)
516                  ;; Kludge.  If the event we read was a mouse-release,
517                  ;; discard it and read the next one.
518                  (if (button-release-event-p event)
519                      (event-to-character (next-command-event event)))
520                  (error "Key read has no ASCII equivalent %S" event))
521         ;; this is not necessary, but is marginally more efficient than GC.
522         (deallocate-event event)))))
523
524 (defun read-char-exclusive ()
525   "Read a character from the command input (keyboard or macro).
526 If a mouse click or non-ASCII character is detected, it is discarded.
527 The character typed is returned as an ASCII value.  This is most likely
528 the wrong thing for you to be using: consider using the
529 `next-command-event' function instead."
530   (let (event ch)
531     (while (progn
532              (setq event (next-command-event))
533              (or inhibit-quit
534                  (and (event-matches-key-specifier-p event (quit-char))
535                       (signal 'quit nil)))
536              (setq ch (event-to-character event))
537              (deallocate-event event)
538              (null ch)))
539     ch))
540
541 (defun read-quoted-char (&optional prompt)
542   "Like `read-char', except that if the first character read is an octal
543 digit, we read up to two more octal digits and return the character
544 represented by the octal number consisting of those digits.
545 Optional argument PROMPT specifies a string to use to prompt the user."
546   (let ((count 0) (code 0) done
547         (prompt (and prompt (gettext prompt)))
548         char event)
549     (while (and (not done) (< count 3))
550       (let ((inhibit-quit (zerop count))
551             ;; Don't let C-h get the help message--only help function keys.
552             (help-char nil)
553             (help-form
554              "Type the special character you want to use,
555 or three octal digits representing its character code."))
556         (and prompt (display-message 'prompt (format "%s-" prompt)))
557         (setq event (next-command-event)
558               char (or (event-to-character event nil nil t)
559                        (signal 'error
560                                (list "key read cannot be inserted in a buffer"
561                                      event))))
562         (if inhibit-quit (setq quit-flag nil)))
563       (cond ((<= ?0 char ?7)
564              (setq code (+ (* code 8) (- char ?0))
565                    count (1+ count))
566              (when prompt
567                (display-message 'prompt
568                  (setq prompt (format "%s %c" prompt char)))))
569             ((> count 0)
570              (setq unread-command-event event
571                    done t))
572             (t (setq code (char-int char)
573                      done t))))
574     (int-char code)
575     ;; Turn a meta-character into a character with the 0200 bit set.
576 ;    (logior (if (/= (logand code ?\M-\^@) 0) 128 0)
577 ;           (logand 255 code))))
578     ))
579
580 (defun momentary-string-display (string pos &optional exit-char message) 
581   "Momentarily display STRING in the buffer at POS.
582 Display remains until next character is typed.
583 If the char is EXIT-CHAR (optional third arg, default is SPC) it is swallowed;
584 otherwise it is then available as input (as a command if nothing else).
585 Display MESSAGE (optional fourth arg) in the echo area.
586 If MESSAGE is nil, instructions to type EXIT-CHAR are displayed there."
587   (or exit-char (setq exit-char ?\ ))
588   (let ((buffer-read-only nil)
589         ;; Don't modify the undo list at all.
590         (buffer-undo-list t)
591         (modified (buffer-modified-p))
592         (name buffer-file-name)
593         insert-end)
594     (unwind-protect
595         (progn
596           (save-excursion
597             (goto-char pos)
598             ;; defeat file locking... don't try this at home, kids!
599             (setq buffer-file-name nil)
600             (insert-before-markers (gettext string))
601             (setq insert-end (point))
602             ;; If the message end is off frame, recenter now.
603             (if (> (window-end) insert-end)
604                 (recenter (/ (window-height) 2)))
605             ;; If that pushed message start off the frame,
606             ;; scroll to start it at the top of the frame.
607             (move-to-window-line 0)
608             (if (> (point) pos)
609                 (progn
610                   (goto-char pos)
611                   (recenter 0))))
612           (message (or message (gettext "Type %s to continue editing."))
613                    (single-key-description exit-char))
614           (let ((event (save-excursion (next-command-event))))
615             (or (eq (event-to-character event) exit-char)
616                 (setq unread-command-event event))))
617       (if insert-end
618           (save-excursion
619             (delete-region pos insert-end)))
620       (setq buffer-file-name name)
621       (set-buffer-modified-p modified))))
622
623 ;;; cmdloop.el ends here