Mercurial > emacs
annotate lisp/electric.el @ 13570:1bd9b0579ae5
(install-arch-indep): Rename old info/dir only if exists.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 16 Nov 1995 21:59:46 +0000 |
parents | a10616f0ad17 |
children | 83f275dcd93a |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
1 ;;; electric.el --- window maker and Command loop for `electric' modes. |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
13260
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
3 ;; Copyright (C) 1985, 1986, 1995 Free Software Foundation, Inc. |
845 | 4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
5 ;; Author: K. Shane Hartman |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
6 ;; Maintainer: FSF |
811
e694e0879463
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
7 ;; Keywords: extensions |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
8 |
35 | 9 ;; This file is part of GNU Emacs. |
10 | |
11 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 ;; it under the terms of the GNU General Public License as published by | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
778
diff
changeset
|
13 ;; the Free Software Foundation; either version 2, or (at your option) |
35 | 14 ;; any later version. |
15 | |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
24 | |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
25 ;;; Commentary: |
35 | 26 |
584 | 27 ; zaaaaaaap |
35 | 28 |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
29 ;;; Code: |
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
30 |
35 | 31 ;; This loop is the guts for non-standard modes which retain control |
13260
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
32 ;; until some event occurs. It is a `do-forever', the only way out is |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
33 ;; to throw. It assumes that you have set up the keymap, window, and |
35 | 34 ;; everything else: all it does is read commands and execute them - |
35 ;; providing error messages should one occur (if there is no loop | |
36 ;; function - which see). The required argument is a tag which should | |
13260
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
37 ;; expect a value of nil if the user decides to punt. The second |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
38 ;; argument is the prompt to be used: if nil, use "->", if 'noprompt, |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
39 ;; don't use a prompt, if a string, use that string as prompt, and if |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
40 ;; a function of no variable, it will be evaluated in every iteration |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
41 ;; of the loop and its return value, which can be nil, 'noprompt or a |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
42 ;; string, will be used as prompt. Given third argument non-nil, it |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
43 ;; INHIBITS quitting unless the user types C-g at toplevel. This is |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
44 ;; so user can do things like C-u C-g and not get thrown out. Fourth |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
45 ;; argument, if non-nil, should be a function of two arguments which |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
46 ;; is called after every command is executed. The fifth argument, if |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
47 ;; provided, is the state variable for the function. If the |
35 | 48 ;; loop-function gets an error, the loop will abort WITHOUT throwing |
49 ;; (moral: use unwind-protect around call to this function for any | |
50 ;; critical stuff). The second argument for the loop function is the | |
51 ;; conditions for any error that occurred or nil if none. | |
52 | |
53 (defun Electric-command-loop (return-tag | |
54 &optional prompt inhibit-quit | |
55 loop-function loop-state) | |
13260
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
56 |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
57 (let (cmd |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
58 (err nil) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
59 (prompt-string prompt)) |
35 | 60 (while t |
13260
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
61 (if (not (or (stringp prompt) (eq prompt nil) (eq prompt 'noprompt))) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
62 (setq prompt-string (funcall prompt))) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
63 (if (not (stringp prompt-string)) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
64 (if (eq prompt-string 'noprompt) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
65 (setq prompt-string nil) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
66 (setq prompt-string "->"))) |
a10616f0ad17
(Electric-command-loop): Don't display a prompt
Richard M. Stallman <rms@gnu.org>
parents:
3439
diff
changeset
|
67 (setq cmd (read-key-sequence prompt-string)) |
35 | 68 (setq last-command-char (aref cmd (1- (length cmd))) |
69 this-command (key-binding cmd) | |
70 cmd this-command) | |
71 (if (or (prog1 quit-flag (setq quit-flag nil)) | |
3439
13660e63d8f0
(Electric-command-loop): Use eq to compare events.
Richard M. Stallman <rms@gnu.org>
parents:
2540
diff
changeset
|
72 (eq last-input-char ?\C-g)) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1609
diff
changeset
|
73 (progn (setq unread-command-events nil |
35 | 74 prefix-arg nil) |
75 ;; If it wasn't cancelling a prefix character, then quit. | |
76 (if (or (= (length (this-command-keys)) 1) | |
77 (not inhibit-quit)) ; safety | |
78 (progn (ding) | |
79 (message "Quit") | |
80 (throw return-tag nil)) | |
81 (setq cmd nil)))) | |
82 (setq current-prefix-arg prefix-arg) | |
83 (if cmd | |
84 (condition-case conditions | |
85 (progn (command-execute cmd) | |
703
e2780d9a814c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
662
diff
changeset
|
86 (setq last-command this-command) |
35 | 87 (if (or (prog1 quit-flag (setq quit-flag nil)) |
3439
13660e63d8f0
(Electric-command-loop): Use eq to compare events.
Richard M. Stallman <rms@gnu.org>
parents:
2540
diff
changeset
|
88 (eq last-input-char ?\C-g)) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1609
diff
changeset
|
89 (progn (setq unread-command-events nil) |
35 | 90 (if (not inhibit-quit) |
91 (progn (ding) | |
92 (message "Quit") | |
93 (throw return-tag nil)) | |
94 (ding))))) | |
95 (buffer-read-only (if loop-function | |
96 (setq err conditions) | |
97 (ding) | |
98 (message "Buffer is read-only") | |
99 (sit-for 2))) | |
100 (beginning-of-buffer (if loop-function | |
101 (setq err conditions) | |
102 (ding) | |
103 (message "Beginning of Buffer") | |
104 (sit-for 2))) | |
105 (end-of-buffer (if loop-function | |
106 (setq err conditions) | |
107 (ding) | |
108 (message "End of Buffer") | |
109 (sit-for 2))) | |
110 (error (if loop-function | |
111 (setq err conditions) | |
112 (ding) | |
113 (message "Error: %s" | |
114 (if (eq (car conditions) 'error) | |
115 (car (cdr conditions)) | |
116 (prin1-to-string conditions))) | |
117 (sit-for 2)))) | |
118 (ding)) | |
119 (if loop-function (funcall loop-function loop-state err)))) | |
120 (ding) | |
121 (throw return-tag nil)) | |
122 | |
123 ;; This function is like pop-to-buffer, sort of. | |
124 ;; The algorithm is | |
125 ;; If there is a window displaying buffer | |
126 ;; Select it | |
127 ;; Else if there is only one window | |
128 ;; Split it, selecting the window on the bottom with height being | |
129 ;; the lesser of max-height (if non-nil) and the number of lines in | |
130 ;; the buffer to be displayed subject to window-min-height constraint. | |
131 ;; Else | |
132 ;; Switch to buffer in the current window. | |
133 ;; | |
134 ;; Then if max-height is nil, and not all of the lines in the buffer | |
778 | 135 ;; are displayed, grab the whole frame. |
35 | 136 ;; |
137 ;; Returns selected window on buffer positioned at point-min. | |
138 | |
139 (defun Electric-pop-up-window (buffer &optional max-height) | |
140 (let* ((win (or (get-buffer-window buffer) (selected-window))) | |
141 (buf (get-buffer buffer)) | |
142 (one-window (one-window-p t)) | |
143 (pop-up-windows t) | |
144 (target-height) | |
145 (lines)) | |
146 (if (not buf) | |
147 (error "Buffer %s does not exist" buffer) | |
148 (save-excursion | |
149 (set-buffer buf) | |
150 (setq lines (count-lines (point-min) (point-max))) | |
151 (setq target-height | |
152 (min (max (if max-height (min max-height (1+ lines)) (1+ lines)) | |
153 window-min-height) | |
154 (save-window-excursion | |
155 (delete-other-windows) | |
156 (1- (window-height (selected-window))))))) | |
157 (cond ((and (eq (window-buffer win) buf)) | |
158 (select-window win)) | |
159 (one-window | |
160 (goto-char (window-start win)) | |
161 (pop-to-buffer buffer) | |
162 (setq win (selected-window)) | |
163 (enlarge-window (- target-height (window-height win)))) | |
164 (t | |
165 (switch-to-buffer buf))) | |
166 (if (and (not max-height) | |
167 (> target-height (window-height (selected-window)))) | |
168 (progn (goto-char (window-start win)) | |
169 (enlarge-window (- target-height (window-height win))))) | |
170 (goto-char (point-min)) | |
171 win))) | |
584 | 172 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
173 (provide 'electric) |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
174 |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
175 ;;; electric.el ends here |