annotate lisp/prim/cmdloop.el @ 171:929b76928fce r20-3b12

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