Mercurial > emacs
annotate lisp/ebuff-menu.el @ 4808:87a507860be7
Fixed typos or brainos of whoever though `@' was the comment char.
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Sun, 03 Oct 1993 19:54:21 +0000 |
parents | 2b34a2ef4d63 |
children | 5f1e5be68fcd |
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 |
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
807
diff
changeset
|
3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc. |
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 | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
22 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
23 ;;; Commentary: |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
24 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2026
diff
changeset
|
25 ;; 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
|
26 ;; 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
|
27 ;; ITS Emacs lunar or tmacs libraries. |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
28 |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
29 ;;; Code: |
475 | 30 |
31 (require 'electric) | |
32 | |
33 ;; this depends on the format of list-buffers (from src/buffer.c) and | |
34 ;; on stuff in lisp/buff-menu.el | |
35 | |
36 (defvar electric-buffer-menu-mode-map nil) | |
37 | |
38 ;;;###autoload | |
39 (defun electric-buffer-list (arg) | |
40 "Pops up a buffer describing the set of Emacs buffers. | |
41 Vaguely like ITS lunar select buffer; combining typeoutoid buffer | |
42 listing with menuoid buffer selection. | |
43 | |
44 If the very next character typed is a space then the buffer list | |
45 window disappears. Otherwise, one may move around in the buffer list | |
46 window, marking buffers to be selected, saved or deleted. | |
47 | |
48 To exit and select a new buffer, type a space when the cursor is on | |
49 the appropriate line of the buffer-list window. Other commands are | |
50 much like those of buffer-menu-mode. | |
51 | |
52 Calls value of `electric-buffer-menu-mode-hook' on entry if non-nil. | |
53 | |
54 \\{electric-buffer-menu-mode-map}" | |
55 (interactive "P") | |
56 (let (select buffer) | |
57 (save-window-excursion | |
58 (save-window-excursion (list-buffers arg)) | |
59 (setq buffer (window-buffer (Electric-pop-up-window "*Buffer List*"))) | |
60 (unwind-protect | |
61 (progn | |
62 (set-buffer buffer) | |
63 (Electric-buffer-menu-mode) | |
64 (setq select | |
65 (catch 'electric-buffer-menu-select | |
66 (message "<<< Press Space 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
|
67 (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
|
68 ?\ ) |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1607
diff
changeset
|
69 (progn (setq unread-command-events nil) |
475 | 70 (throw 'electric-buffer-menu-select nil))) |
71 (let ((first (progn (goto-char (point-min)) | |
72 (forward-line 2) | |
73 (point))) | |
74 (last (progn (goto-char (point-max)) | |
75 (forward-line -1) | |
76 (point))) | |
77 (goal-column 0)) | |
78 (goto-char first) | |
79 (Electric-command-loop 'electric-buffer-menu-select | |
80 nil | |
81 t | |
82 'electric-buffer-menu-looper | |
83 (cons first last)))))) | |
84 (set-buffer buffer) | |
85 (Buffer-menu-mode) | |
86 (bury-buffer buffer) | |
87 (message ""))) | |
88 (if select | |
89 (progn (set-buffer buffer) | |
90 (let ((opoint (point-marker))) | |
91 (Buffer-menu-execute) | |
92 (goto-char (point-min)) | |
93 (if (prog1 (search-forward "\n>" nil t) | |
94 (goto-char opoint) (set-marker opoint nil)) | |
95 (Buffer-menu-select) | |
96 (switch-to-buffer (Buffer-menu-buffer t)))))))) | |
97 | |
98 (defun electric-buffer-menu-looper (state condition) | |
99 (cond ((and condition | |
100 (not (memq (car condition) '(buffer-read-only | |
101 end-of-buffer | |
102 beginning-of-buffer)))) | |
103 (signal (car condition) (cdr condition))) | |
104 ((< (point) (car state)) | |
105 (goto-char (point-min)) | |
106 (forward-line 2)) | |
107 ((> (point) (cdr state)) | |
108 (goto-char (point-max)) | |
109 (forward-line -1) | |
110 (if (pos-visible-in-window-p (point-max)) | |
111 (recenter -1))))) | |
112 | |
113 (put 'Electric-buffer-menu-mode 'mode-class 'special) | |
114 (defun Electric-buffer-menu-mode () | |
115 "Major mode for editing a list of buffers. | |
116 Each line describes one of the buffers in Emacs. | |
117 Letters do not insert themselves; instead, they are commands. | |
118 \\<electric-buffer-menu-mode-map> | |
119 \\[keyboard-quit] or \\[Electric-buffer-menu-quit] -- exit buffer menu, returning to previous window and buffer | |
120 configuration. If the very first character typed is a space, it | |
121 also has this effect. | |
122 \\[Electric-buffer-menu-select] -- select buffer of line point is on. | |
123 Also show buffers marked with m in other windows, | |
124 deletes buffers marked with \"D\", and saves those marked with \"S\". | |
125 \\[Buffer-menu-mark] -- mark buffer to be displayed. | |
126 \\[Buffer-menu-not-modified] -- clear modified-flag on that buffer. | |
127 \\[Buffer-menu-save] -- mark that buffer to be saved. | |
128 \\[Buffer-menu-delete] or \\[Buffer-menu-delete-backwards] -- mark that buffer to be deleted. | |
129 \\[Buffer-menu-unmark] -- remove all kinds of marks from current line. | |
130 \\[Electric-buffer-menu-mode-view-buffer] -- view buffer, returning when done. | |
131 \\[Buffer-menu-backup-unmark] -- back up a line and remove marks. | |
132 | |
133 \\{electric-buffer-menu-mode-map} | |
134 | |
135 Entry to this mode via command electric-buffer-list calls the value of | |
136 electric-buffer-menu-mode-hook if it is non-nil." | |
137 (kill-all-local-variables) | |
138 (use-local-map electric-buffer-menu-mode-map) | |
139 (setq mode-name "Electric Buffer Menu") | |
140 (setq mode-line-buffer-identification "Electric Buffer List") | |
141 (make-local-variable 'Helper-return-blurb) | |
142 (setq Helper-return-blurb "return to buffer editing") | |
143 (setq truncate-lines t) | |
144 (setq buffer-read-only t) | |
145 (setq major-mode 'Electric-buffer-menu-mode) | |
146 (goto-char (point-min)) | |
147 (if (search-forward "\n." nil t) (forward-char -1)) | |
148 (run-hooks 'electric-buffer-menu-mode-hook)) | |
149 | |
150 ;; generally the same as Buffer-menu-mode-map | |
151 ;; (except we don't indirect to global-map) | |
152 (put 'Electric-buffer-menu-undefined 'suppress-keymap t) | |
153 (if electric-buffer-menu-mode-map | |
154 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
|
155 (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
|
156 (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
|
157 (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
|
158 (fillarray (car (cdr submap)) 'Electric-buffer-menu-undefined) |
475 | 159 (define-key map "\C-z" 'suspend-emacs) |
160 (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
|
161 (define-key map (char-to-string help-char) 'Helper-help) |
475 | 162 (define-key map "?" 'Helper-describe-bindings) |
163 (define-key map "\C-c" nil) | |
164 (define-key map "\C-c\C-c" 'Electric-buffer-menu-quit) | |
165 (define-key map "\C-]" 'Electric-buffer-menu-quit) | |
166 (define-key map "q" 'Electric-buffer-menu-quit) | |
167 (define-key map " " 'Electric-buffer-menu-select) | |
168 (define-key map "\C-l" 'recenter) | |
169 (define-key map "s" 'Buffer-menu-save) | |
170 (define-key map "d" 'Buffer-menu-delete) | |
171 (define-key map "k" 'Buffer-menu-delete) | |
172 (define-key map "\C-d" 'Buffer-menu-delete-backwards) | |
173 ;(define-key map "\C-k" 'Buffer-menu-delete) | |
174 (define-key map "\177" 'Buffer-menu-backup-unmark) | |
175 (define-key map "~" 'Buffer-menu-not-modified) | |
176 (define-key map "u" 'Buffer-menu-unmark) | |
177 (let ((i ?0)) | |
178 (while (<= i ?9) | |
179 (define-key map (char-to-string i) 'digit-argument) | |
180 (define-key map (concat "\e" (char-to-string i)) 'digit-argument) | |
181 (setq i (1+ i)))) | |
182 (define-key map "-" 'negative-argument) | |
183 (define-key map "\e-" 'negative-argument) | |
184 (define-key map "m" 'Buffer-menu-mark) | |
185 (define-key map "\C-u" 'universal-argument) | |
186 (define-key map "\C-p" 'previous-line) | |
187 (define-key map "\C-n" 'next-line) | |
188 (define-key map "p" 'previous-line) | |
189 (define-key map "n" 'next-line) | |
190 (define-key map "\C-v" 'scroll-up) | |
191 (define-key map "\ev" 'scroll-down) | |
192 (define-key map ">" 'scroll-right) | |
193 (define-key map "<" 'scroll-left) | |
194 (define-key map "\e\C-v" 'scroll-other-window) | |
195 (define-key map "\e>" 'end-of-buffer) | |
196 (define-key map "\e<" 'beginning-of-buffer) | |
197 (setq electric-buffer-menu-mode-map map))) | |
198 | |
199 (defun Electric-buffer-menu-exit () | |
200 (interactive) | |
2026
3514a9bf50c5
(electric-buffer-list): Handle any kind of event.
Richard M. Stallman <rms@gnu.org>
parents:
1821
diff
changeset
|
201 (setq unread-command-events (listify-key-sequence (this-command-keys))) |
475 | 202 ;; for robustness |
203 (condition-case () | |
204 (throw 'electric-buffer-menu-select nil) | |
205 (error (Buffer-menu-mode) | |
206 (other-buffer)))) | |
207 | |
208 (defun Electric-buffer-menu-select () | |
209 "Leave Electric Buffer Menu, selecting buffers and executing changes. | |
210 Saves buffers marked \"S\". Deletes buffers marked \"K\". | |
211 Selects buffer at point and displays buffers marked \">\" in other windows." | |
212 (interactive) | |
213 (throw 'electric-buffer-menu-select (point))) | |
214 | |
215 (defun Electric-buffer-menu-quit () | |
216 "Leave Electric Buffer Menu, restoring previous window configuration. | |
217 Does not execute select, save, or delete commands." | |
218 (interactive) | |
219 (throw 'electric-buffer-menu-select nil)) | |
220 | |
221 (defun Electric-buffer-menu-undefined () | |
222 (interactive) | |
223 (ding) | |
224 (message (if (and (eq (key-binding "\C-c\C-c") 'Electric-buffer-menu-quit) | |
225 (eq (key-binding " ") 'Electric-buffer-menu-select) | |
919 | 226 (eq (key-binding (char-to-string help-char)) 'Helper-help) |
475 | 227 (eq (key-binding "?") 'Helper-describe-bindings)) |
916
938f166a0874
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
915
diff
changeset
|
228 (substitute-command-keys "Type C-c C-c to exit, Space to select, \\[Helper-help] for help, ? for commands") |
475 | 229 (substitute-command-keys "\ |
230 Type \\[Electric-buffer-menu-quit] to exit, \ | |
231 \\[Electric-buffer-menu-select] to select, \ | |
232 \\[Helper-help] for help, \\[Helper-describe-bindings] for commands."))) | |
233 (sit-for 4)) | |
234 | |
235 (defun Electric-buffer-menu-mode-view-buffer () | |
236 "View buffer on current line in Electric Buffer Menu. | |
237 Returns to Electric Buffer Menu when done." | |
238 (interactive) | |
239 (let ((bufnam (Buffer-menu-buffer nil))) | |
240 (if bufnam | |
241 (view-buffer bufnam) | |
242 (ding) | |
243 (message "Buffer %s does not exist!" bufnam) | |
244 (sit-for 4)))) | |
245 | |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
475
diff
changeset
|
246 ;;; ebuff-menu.el ends here |