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