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