annotate lisp/prim/cmdloop1.el @ 0:376386a54a3c r19-14

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