Mercurial > emacs
annotate lisp/electric.el @ 2594:e1277aec1738
(gud-format-command): Fix %f expansuuin to send ondly the basename of
files to gdb.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Tue, 27 Apr 1993 21:59:46 +0000 |
parents | 0c20256f752d |
children | 13660e63d8f0 |
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 |
845 | 3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. |
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 |
32 ;; until some event occurs. It is a `do-forever', the only way out is to | |
33 ;; throw. It assumes that you have set up the keymap, window, and | |
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 | |
37 ;; expect a value of nil if the user decides to punt. The | |
38 ;; second argument is a prompt string (defaults to "->"). Given third | |
39 ;; argument non-nil, it INHIBITS quitting unless the user types C-g at | |
40 ;; toplevel. This is so user can do things like C-u C-g and not get | |
41 ;; thrown out. Fourth argument, if non-nil, should be a function of two | |
42 ;; arguments which is called after every command is executed. The fifth | |
43 ;; argument, if provided, is the state variable for the function. If the | |
44 ;; loop-function gets an error, the loop will abort WITHOUT throwing | |
45 ;; (moral: use unwind-protect around call to this function for any | |
46 ;; critical stuff). The second argument for the loop function is the | |
47 ;; conditions for any error that occurred or nil if none. | |
48 | |
49 (defun Electric-command-loop (return-tag | |
50 &optional prompt inhibit-quit | |
51 loop-function loop-state) | |
52 (if (not prompt) (setq prompt "->")) | |
53 (let (cmd (err nil)) | |
54 (while t | |
55 (setq cmd (read-key-sequence (if (stringp prompt) | |
56 prompt (funcall prompt)))) | |
57 (setq last-command-char (aref cmd (1- (length cmd))) | |
58 this-command (key-binding cmd) | |
59 cmd this-command) | |
60 (if (or (prog1 quit-flag (setq quit-flag nil)) | |
61 (= last-input-char ?\C-g)) | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1609
diff
changeset
|
62 (progn (setq unread-command-events nil |
35 | 63 prefix-arg nil) |
64 ;; If it wasn't cancelling a prefix character, then quit. | |
65 (if (or (= (length (this-command-keys)) 1) | |
66 (not inhibit-quit)) ; safety | |
67 (progn (ding) | |
68 (message "Quit") | |
69 (throw return-tag nil)) | |
70 (setq cmd nil)))) | |
71 (setq current-prefix-arg prefix-arg) | |
72 (if cmd | |
73 (condition-case conditions | |
74 (progn (command-execute cmd) | |
703
e2780d9a814c
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
662
diff
changeset
|
75 (setq last-command this-command) |
35 | 76 (if (or (prog1 quit-flag (setq quit-flag nil)) |
77 (= last-input-char ?\C-g)) | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1609
diff
changeset
|
78 (progn (setq unread-command-events nil) |
35 | 79 (if (not inhibit-quit) |
80 (progn (ding) | |
81 (message "Quit") | |
82 (throw return-tag nil)) | |
83 (ding))))) | |
84 (buffer-read-only (if loop-function | |
85 (setq err conditions) | |
86 (ding) | |
87 (message "Buffer is read-only") | |
88 (sit-for 2))) | |
89 (beginning-of-buffer (if loop-function | |
90 (setq err conditions) | |
91 (ding) | |
92 (message "Beginning of Buffer") | |
93 (sit-for 2))) | |
94 (end-of-buffer (if loop-function | |
95 (setq err conditions) | |
96 (ding) | |
97 (message "End of Buffer") | |
98 (sit-for 2))) | |
99 (error (if loop-function | |
100 (setq err conditions) | |
101 (ding) | |
102 (message "Error: %s" | |
103 (if (eq (car conditions) 'error) | |
104 (car (cdr conditions)) | |
105 (prin1-to-string conditions))) | |
106 (sit-for 2)))) | |
107 (ding)) | |
108 (if loop-function (funcall loop-function loop-state err)))) | |
109 (ding) | |
110 (throw return-tag nil)) | |
111 | |
112 ;; This function is like pop-to-buffer, sort of. | |
113 ;; The algorithm is | |
114 ;; If there is a window displaying buffer | |
115 ;; Select it | |
116 ;; Else if there is only one window | |
117 ;; Split it, selecting the window on the bottom with height being | |
118 ;; the lesser of max-height (if non-nil) and the number of lines in | |
119 ;; the buffer to be displayed subject to window-min-height constraint. | |
120 ;; Else | |
121 ;; Switch to buffer in the current window. | |
122 ;; | |
123 ;; Then if max-height is nil, and not all of the lines in the buffer | |
778 | 124 ;; are displayed, grab the whole frame. |
35 | 125 ;; |
126 ;; Returns selected window on buffer positioned at point-min. | |
127 | |
128 (defun Electric-pop-up-window (buffer &optional max-height) | |
129 (let* ((win (or (get-buffer-window buffer) (selected-window))) | |
130 (buf (get-buffer buffer)) | |
131 (one-window (one-window-p t)) | |
132 (pop-up-windows t) | |
133 (target-height) | |
134 (lines)) | |
135 (if (not buf) | |
136 (error "Buffer %s does not exist" buffer) | |
137 (save-excursion | |
138 (set-buffer buf) | |
139 (setq lines (count-lines (point-min) (point-max))) | |
140 (setq target-height | |
141 (min (max (if max-height (min max-height (1+ lines)) (1+ lines)) | |
142 window-min-height) | |
143 (save-window-excursion | |
144 (delete-other-windows) | |
145 (1- (window-height (selected-window))))))) | |
146 (cond ((and (eq (window-buffer win) buf)) | |
147 (select-window win)) | |
148 (one-window | |
149 (goto-char (window-start win)) | |
150 (pop-to-buffer buffer) | |
151 (setq win (selected-window)) | |
152 (enlarge-window (- target-height (window-height win)))) | |
153 (t | |
154 (switch-to-buffer buf))) | |
155 (if (and (not max-height) | |
156 (> target-height (window-height (selected-window)))) | |
157 (progn (goto-char (window-start win)) | |
158 (enlarge-window (- target-height (window-height win))))) | |
159 (goto-char (point-min)) | |
160 win))) | |
584 | 161 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
162 (provide 'electric) |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
163 |
2229
bd3c525fa6fc
Added standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1821
diff
changeset
|
164 ;;; electric.el ends here |