annotate lisp/cmdloop.el @ 1123:37bdd24225ef

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