annotate lisp/prim/cmdloop.el @ 70:131b0175ea99 r20-0b30

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