Mercurial > emacs
annotate lisp/ebuff-menu.el @ 15225:a78a1df9690c
(Fcall_process): Fix previous change (now !MSDOS only).
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 12 May 1996 22:50:25 +0000 |
parents | 49af6e2bfaa8 |
children | 11218164bc54 |
rev | line source |
---|---|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
1 ;;; ebuff-menu.el --- electric-buffer-list mode |
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
2 |
7300 | 3 ;; Copyright (C) 1985, 1986, 1994 Free Software Foundation, Inc. |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
4 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
5 ;; Author: Richard Mlynarik <mly@ai.mit.edu> |
475 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; 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:
662
diff
changeset
|
11 ;; the Free Software Foundation; either version 2, or (at your option) |
475 | 12 ;; any later version. |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
475 | 23 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
24 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
25 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
26 ;; Who says one can't have typeout windows in GNU Emacs? The entry |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
27 ;; point, `electric-buffer-list' works like ^r select buffer from the |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
28 ;; ITS Emacs lunar or tmacs libraries. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
29 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
30 ;;; Code: |
475 | 31 |
32 (require 'electric) | |
33 | |
34 ;; this depends on the format of list-buffers (from src/buffer.c) and | |
35 ;; on stuff in lisp/buff-menu.el | |
36 | |
37 (defvar electric-buffer-menu-mode-map nil) | |
38 | |
39 ;;;###autoload | |
40 (defun electric-buffer-list (arg) | |
41 "Pops up a buffer describing the set of Emacs buffers. | |
42 Vaguely like ITS lunar select buffer; combining typeoutoid buffer | |
43 listing with menuoid buffer selection. | |
44 | |
45 If the very next character typed is a space then the buffer list | |
46 window disappears. Otherwise, one may move around in the buffer list | |
47 window, marking buffers to be selected, saved or deleted. | |
48 | |
49 To exit and select a new buffer, type a space when the cursor is on | |
50 the appropriate line of the buffer-list window. Other commands are | |
51 much like those of buffer-menu-mode. | |
52 | |
53 Calls value of `electric-buffer-menu-mode-hook' on entry if non-nil. | |
54 | |
55 \\{electric-buffer-menu-mode-map}" | |
56 (interactive "P") | |
57 (let (select buffer) | |
58 (save-window-excursion | |
59 (save-window-excursion (list-buffers arg)) | |
60 (setq buffer (window-buffer (Electric-pop-up-window "*Buffer List*"))) | |
61 (unwind-protect | |
62 (progn | |
63 (set-buffer buffer) | |
64 (Electric-buffer-menu-mode) | |
65 (setq select | |
66 (catch 'electric-buffer-menu-select | |
8122
2fae14e8ae5d
(electric-buffer-list): Change prompt message.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
67 (message "<<< Press Return to bury the buffer list >>>") |
2026
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
68 (if (eq (setq unread-command-events (list (read-event))) |
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
69 ?\ ) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1607
diff
changeset
|
70 (progn (setq unread-command-events nil) |
475 | 71 (throw 'electric-buffer-menu-select nil))) |
12568
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
72 (let ((start-point (point)) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
73 (first (progn (goto-char (point-min)) |
475 | 74 (forward-line 2) |
75 (point))) | |
76 (last (progn (goto-char (point-max)) | |
77 (forward-line -1) | |
78 (point))) | |
79 (goal-column 0)) | |
12568
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
80 ;; Use start-point if it is meaningful. |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
81 (goto-char (if (or (< start-point first) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
82 (> start-point last)) |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
83 first |
94ee086557db
(electric-buffer-list): Save point before
Karl Heuer <kwzh@gnu.org>
parents:
11275
diff
changeset
|
84 start-point)) |
475 | 85 (Electric-command-loop 'electric-buffer-menu-select |
86 nil | |
87 t | |
88 'electric-buffer-menu-looper | |
89 (cons first last)))))) | |
90 (set-buffer buffer) | |
91 (Buffer-menu-mode) | |
92 (bury-buffer buffer) | |
93 (message ""))) | |
94 (if select | |
95 (progn (set-buffer buffer) | |
96 (let ((opoint (point-marker))) | |
97 (Buffer-menu-execute) | |
98 (goto-char (point-min)) | |
99 (if (prog1 (search-forward "\n>" nil t) | |
100 (goto-char opoint) (set-marker opoint nil)) | |
101 (Buffer-menu-select) | |
102 (switch-to-buffer (Buffer-menu-buffer t)))))))) | |
103 | |
104 (defun electric-buffer-menu-looper (state condition) | |
105 (cond ((and condition | |
106 (not (memq (car condition) '(buffer-read-only | |
107 end-of-buffer | |
108 beginning-of-buffer)))) | |
109 (signal (car condition) (cdr condition))) | |
110 ((< (point) (car state)) | |
111 (goto-char (point-min)) | |
112 (forward-line 2)) | |
113 ((> (point) (cdr state)) | |
114 (goto-char (point-max)) | |
115 (forward-line -1) | |
116 (if (pos-visible-in-window-p (point-max)) | |
117 (recenter -1))))) | |
118 | |
119 (put 'Electric-buffer-menu-mode 'mode-class 'special) | |
120 (defun Electric-buffer-menu-mode () | |
121 "Major mode for editing a list of buffers. | |
122 Each line describes one of the buffers in Emacs. | |
123 Letters do not insert themselves; instead, they are commands. | |
124 \\<electric-buffer-menu-mode-map> | |
125 \\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer | |
126 configuration. If the very first character typed is a space, it | |
127 also has this effect. | |
128 \\[Electric-buffer-menu-select] -- select buffer of line point is on. | |
129 Also show buffers marked with m in other windows, | |
130 deletes buffers marked with \"D\", and saves those marked with \"S\". | |
131 \\[Buffer-menu-mark] -- mark buffer to be displayed. | |
132 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. | |
133 \\[Buffer-menu-save] -- mark that buffer to be saved. | |
134 \\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted. | |
135 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line. | |
136 \\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done. | |
137 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks. | |
138 | |
139 \\{electric-buffer-menu-mode-map} | |
140 | |
141 Entry to this mode via command electric-buffer-list calls the value of | |
142 electric-buffer-menu-mode-hook if it is non-nil." | |
143 (kill-all-local-variables) | |
144 (use-local-map electric-buffer-menu-mode-map) | |
145 (setq mode-name "Electric Buffer Menu") | |
146 (setq mode-line-buffer-identification "Electric Buffer List") | |
147 (make-local-variable 'Helper-return-blurb) | |
148 (setq Helper-return-blurb "return to buffer editing") | |
149 (setq truncate-lines t) | |
150 (setq buffer-read-only t) | |
151 (setq major-mode 'Electric-buffer-menu-mode) | |
152 (goto-char (point-min)) | |
153 (if (search-forward "\n." nil t) (forward-char -1)) | |
154 (run-hooks 'electric-buffer-menu-mode-hook)) | |
155 | |
156 ;; generally the same as Buffer-menu-mode-map | |
157 ;; (except we don't indirect to global-map) | |
158 (put 'Electric-buffer-menu-undefined 'suppress-keymap t) | |
159 (if electric-buffer-menu-mode-map | |
160 nil | |
2397
2b34a2ef4d63
(electric-buffer-menu-mode-map): fillarray isn't a valid operation on maps
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
161 (let ((map (make-keymap)) (submap (make-keymap))) |
2b34a2ef4d63
(electric-buffer-menu-mode-map): fillarray isn't a valid operation on maps
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
162 (fillarray (car (cdr map)) 'Electric-buffer-menu-undefined) |
2b34a2ef4d63
(electric-buffer-menu-mode-map): fillarray isn't a valid operation on maps
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
163 (define-key map "\e" submap) |
2b34a2ef4d63
(electric-buffer-menu-mode-map): fillarray isn't a valid operation on maps
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2307
diff
changeset
|
164 (fillarray (car (cdr submap)) 'Electric-buffer-menu-undefined) |
475 | 165 (define-key map "\C-z" 'suspend-emacs) |
166 (define-key map "v" 'Electric-buffer-menu-mode-view-buffer) | |
918
94b50bbd43c3
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
917
diff
changeset
|
167 (define-key map (char-to-string help-char) 'Helper-help) |
475 | 168 (define-key map "?" 'Helper-describe-bindings) |
169 (define-key map "\C-c" nil) | |
170 (define-key map "\C-c\C-c" 'Electric-buffer-menu-quit) | |
171 (define-key map "\C-]" 'Electric-buffer-menu-quit) | |
172 (define-key map "q" 'Electric-buffer-menu-quit) | |
173 (define-key map " " 'Electric-buffer-menu-select) | |
8122
2fae14e8ae5d
(electric-buffer-list): Change prompt message.
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
174 (define-key map "\C-m" 'Electric-buffer-menu-select) |
475 | 175 (define-key map "\C-l" 'recenter) |
176 (define-key map "s" 'Buffer-menu-save) | |
177 (define-key map "d" 'Buffer-menu-delete) | |
178 (define-key map "k" 'Buffer-menu-delete) | |
179 (define-key map "\C-d" 'Buffer-menu-delete-backwards) | |
180 ;(define-key map "\C-k" 'Buffer-menu-delete) | |
181 (define-key map "\177" 'Buffer-menu-backup-unmark) | |
182 (define-key map "~" 'Buffer-menu-not-modified) | |
183 (define-key map "u" 'Buffer-menu-unmark) | |
184 (let ((i ?0)) | |
185 (while (<= i ?9) | |
186 (define-key map (char-to-string i) 'digit-argument) | |
187 (define-key map (concat "\e" (char-to-string i)) 'digit-argument) | |
188 (setq i (1+ i)))) | |
189 (define-key map "-" 'negative-argument) | |
190 (define-key map "\e-" 'negative-argument) | |
191 (define-key map "m" 'Buffer-menu-mark) | |
192 (define-key map "\C-u" 'universal-argument) | |
193 (define-key map "\C-p" 'previous-line) | |
194 (define-key map "\C-n" 'next-line) | |
195 (define-key map "p" 'previous-line) | |
196 (define-key map "n" 'next-line) | |
197 (define-key map "\C-v" 'scroll-up) | |
198 (define-key map "\ev" 'scroll-down) | |
199 (define-key map ">" 'scroll-right) | |
200 (define-key map "<" 'scroll-left) | |
201 (define-key map "\e\C-v" 'scroll-other-window) | |
202 (define-key map "\e>" 'end-of-buffer) | |
203 (define-key map "\e<" 'beginning-of-buffer) | |
11275
53f0ebe096f5
(electric-buffer-menu-mode-map): Undefine ESC ESC
Richard M. Stallman <rms@gnu.org>
parents:
10115
diff
changeset
|
204 (define-key map "\e\e" nil) |
10115
e55ee438bd10
(electric-buffer-menu-mode-map):
Richard M. Stallman <rms@gnu.org>
parents:
8122
diff
changeset
|
205 (define-key map "\e\e\e" 'Electric-buffer-menu-quit) |
e55ee438bd10
(electric-buffer-menu-mode-map):
Richard M. Stallman <rms@gnu.org>
parents:
8122
diff
changeset
|
206 (define-key map [escape escape escape] 'Electric-buffer-menu-quit) |
7006
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
207 (define-key map [mouse-2] 'Electric-buffer-menu-mouse-select) |
475 | 208 (setq electric-buffer-menu-mode-map map))) |
209 | |
210 (defun Electric-buffer-menu-exit () | |
211 (interactive) | |
2026
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
212 (setq unread-command-events (listify-key-sequence (this-command-keys))) |
475 | 213 ;; for robustness |
214 (condition-case () | |
215 (throw 'electric-buffer-menu-select nil) | |
216 (error (Buffer-menu-mode) | |
217 (other-buffer)))) | |
218 | |
219 (defun Electric-buffer-menu-select () | |
220 "Leave Electric Buffer Menu, selecting buffers and executing changes. | |
221 Saves buffers marked \"S\". Deletes buffers marked \"K\". | |
222 Selects buffer at point and displays buffers marked \">\" in other windows." | |
223 (interactive) | |
224 (throw 'electric-buffer-menu-select (point))) | |
225 | |
7006
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
226 (defun Electric-buffer-menu-mouse-select (event) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
227 (interactive "e") |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
228 (select-window (posn-window (event-end event))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
229 (set-buffer (window-buffer (selected-window))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
230 (goto-char (posn-point (event-end event))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
231 (throw 'electric-buffer-menu-select (point))) |
5f1e5be68fcd
(Electric-buffer-menu-mouse-select): New function.
Karl Heuer <kwzh@gnu.org>
parents:
2397
diff
changeset
|
232 |
475 | 233 (defun Electric-buffer-menu-quit () |
234 "Leave Electric Buffer Menu, restoring previous window configuration. | |
235 Does not execute select, save, or delete commands." | |
236 (interactive) | |
237 (throw 'electric-buffer-menu-select nil)) | |
238 | |
239 (defun Electric-buffer-menu-undefined () | |
240 (interactive) | |
241 (ding) | |
14310
49af6e2bfaa8
(Electric-buffer-menu-undefined): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
242 (message "%s" |
49af6e2bfaa8
(Electric-buffer-menu-undefined): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
243 (if (and (eq (key-binding "\C-c\C-c") 'Electric-buffer-menu-quit) |
475 | 244 (eq (key-binding " ") 'Electric-buffer-menu-select) |
919 | 245 (eq (key-binding (char-to-string help-char)) 'Helper-help) |
475 | 246 (eq (key-binding "?") 'Helper-describe-bindings)) |
916
938f166a0874
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
915
diff
changeset
|
247 (substitute-command-keys "Type C-c C-c to exit, Space to select, \\[Helper-help] for help, ? for commands") |
475 | 248 (substitute-command-keys "\ |
249 Type \\[Electric-buffer-menu-quit] to exit, \ | |
250 \\[Electric-buffer-menu-select] to select, \ | |
251 \\[Helper-help] for help, \\[Helper-describe-bindings] for commands."))) | |
252 (sit-for 4)) | |
253 | |
254 (defun Electric-buffer-menu-mode-view-buffer () | |
255 "View buffer on current line in Electric Buffer Menu. | |
256 Returns to Electric Buffer Menu when done." | |
257 (interactive) | |
258 (let ((bufnam (Buffer-menu-buffer nil))) | |
259 (if bufnam | |
260 (view-buffer bufnam) | |
261 (ding) | |
262 (message "Buffer %s does not exist!" bufnam) | |
263 (sit-for 4)))) | |
264 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
265 ;;; ebuff-menu.el ends here |