annotate lisp/prim/cmdloop1.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 131b0175ea99
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; Written by Richard Mlynarik 8-Jul-92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; Putting this in lisp slows things down.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defun recursive-edit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "Invoke the editor command loop recursively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 To get out of the recursive edit, a command can do `(throw 'exit nil)';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 that tells this function to return.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 Alternately, `(throw 'exit t)' makes this function signal an error."
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 (let ((command-loop-level (1+ command-loop-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (redraw-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (let ((_buf (and (not (eq (current-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (window-buffer (selected-window))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; command_loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (if (catch 'exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (let ((standard-output t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (standard-input t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; command_loop_2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (while t (funcall command-loop t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; turn abort-recursive-edit into a quit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (signal 'quit '()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (if _buf (set-buffer _buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (redraw-modeline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; We demand lexical scope!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun command-loop (_catch_errors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 "This function is the default value of the variable command-loop."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (setq prefix-arg nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setq last-command 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (cond ((not _catch_errors)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (command-loop-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ((> (recursion-depth) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (while (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (command-loop-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (t (command-error e) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (if (not (null top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; On entry to the outer level, run the startup file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (catch 'top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (eval top-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (t (command-error e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; If an error occurred during startup and the initial device
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; wasn't created, then die now (the error was already printed out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; on the terminal device).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (if (and (not (noninteractive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (or (not (devicep (selected-device)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (eq 'terminal (device-type (selected-device)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (kill-emacs -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; End of -batch run causes exit here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (kill-emacs t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (catch 'top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (while (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (command-loop-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (t (command-error e) t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Putting this in lisp slows things down a lot; see also comment above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;(defun command-loop-1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ; (let ((_event (allocate-event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ; (_old-command-loop command-loop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ; ;; We deal with quits ourself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ; (_old-inhibit-quit inhibit-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ; (inhibit-quit t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ; ;; ## cancel_echoing();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ; ;; This magically makes single character keyboard macros work just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ; ;; like the real thing. This is slightly bogus, but it's in here for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ; ;; compatibility with Emacs 18.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ; ;; It's not even clear what the "right thing" is.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ; (and executing-macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ; (eq (length executing-macro) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ; (setq last-command 't))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ; ;; Keep looping until somebody wants a different command-loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ; (while (eq command-loop _old-command-loop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ; ;; Make sure current window's buffer is selected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ; (set-buffer (window-buffer (selected-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ; ;; C code had a `QUIT' here so that if ^G was typed before we got here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ; ;; (that is, before emacs was idle and waiting for input) then we treat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ; ;; that as an interrupt. The easiest way to do that here is to make a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ; ;; function call (but pick one the compiler won't optimize away...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ; (let ((inhibit-quit _old-inhibit-quit)) (eval nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ; ;; This condition-case was originally just wrapped around the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ; ;; call to dispatch-event, but in fact we can have errors signalled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ; ;; by process-filters in either sit-for and next-event. Those errors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ; ;; shouldn't be fatal to the command-loop, so we put the condition-case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ; ;; here and hope we're not hiding other bugs in the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ; (condition-case e
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ; (if (and (> (minibuffer-depth) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ; (message-displayed-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ; (sit-for 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ; (message nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ; (next-event _event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ; ;; If ^G was typed while emacs was reading input from the user,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ; ;; then it is treated as just another key. This is what v18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ; ;; did. This is bogus because it gives the illusion that one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ; ;; can bind commands to sequences involving ^G, when really one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ; ;; can only execute those sequences in non-typeahead contexts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ; (setq quit-flag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ; (let ((inhibit-quit _old-inhibit-quit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ; (dispatch-event _event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ; ;; check for bogus code trying to use the old method of unreading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ; (if (globally-boundp 'unread-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ; (makunbound 'unread-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ; (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ; "%S set unread-command-char instead of unread-command-event."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ; this-command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ; (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ; (command-error e))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (setq-default command-loop 'command-loop)