|
|
1.1 root 1: ; buggestions to mly@mit-mc
2:
3: ;; who says one can't have typeout windows in gnu emacs?
4: ;; like ^r select buffer from its emacs lunar or tmacs libraries.
5:
6: ;; Copyright (C) 1985 Richard M. Stallman.
7:
8: ;; This file is part of GNU Emacs.
9:
10: ;; GNU Emacs is distributed in the hope that it will be useful,
11: ;; but WITHOUT ANY WARRANTY. No author or distributor
12: ;; accepts responsibility to anyone for the consequences of using it
13: ;; or for whether it serves any particular purpose or works at all,
14: ;; unless he says so in writing. Refer to the GNU Emacs General Public
15: ;; License for full details.
16:
17: ;; Everyone is granted permission to copy, modify and redistribute
18: ;; GNU Emacs, but only under the conditions described in the
19: ;; GNU Emacs General Public License. A copy of this license is
20: ;; supposed to have been given to you along with GNU Emacs so you
21: ;; can know your rights and responsibilities. It should be in a
22: ;; file named COPYING. Among other things, the copyright notice
23: ;; and this notice must be preserved on all copies.
24:
25:
26: (require 'electric)
27:
28: ;; this depends on the format of list-buffers (from src/buffer.c) and
29: ;; on stuff in lisp/buff-menu.el
30:
31: (defvar Electric-buffer-menu-mode-map nil)
32: (defun electric-buffer-list (arg)
33: "Vaguely like ITS lunar select buffer;
34: combining typeoutoid buffer listing with menuoid buffer selection.
35: This pops up a buffer describing the set of emacs buffers.
36: If the very next character typed is a space then the buffer list is killed.
37:
38: Otherwise, one may use \\[next-line] and \\[previous-line] to move around in the buffer list window
39: and select a buffer by typing Space when the cursor is on the
40: appropriate line of the buffer-list window.
41: Other commands are much like those of buffer-menu-mode.
42:
43: Calls value of electric-buffer-menu-mode-hook on entry if non-nil.
44: Calls value of after-electric-buffer-menu on exit (select) if non-nil.
45:
46: \\{Electric-buffer-menu-mode-map}"
47: (interactive "P")
48: (let ((Helper-return-blurb "return to buffer editing")
49: (Helper-major-mode 'electric-buffer-menu-mode)
50: (Helper-mode-name "Electric Buffer Menu")
51: (goal-column)
52: (select)
53: (buffer))
54: (save-window-excursion
55: (save-window-excursion (list-buffers arg))
56: (setq buffer (window-buffer (Electric-pop-up-window "*Buffer List*")))
57: (unwind-protect
58: (progn
59: (set-buffer buffer)
60: (electric-buffer-menu-mode)
61: (setq select
62: (catch 'electric-buffer-menu-select
63: (let ((first (progn (goto-char (point-min))
64: (forward-line 2)
65: (point)))
66: (last (progn (goto-char (point-max))
67: (forward-line -1)
68: (point))))
69: (goto-char first)
70: (Electric-command-loop 'electric-buffer-menu-select
71: nil
72: t
73: 'Electric-buffer-menu-looper
74: (cons first last))))))
75: (set-buffer buffer)
76: (Buffer-menu-mode)
77: (or select (bury-buffer buffer))
78: (message "")))
79: (if select
80: (progn (set-buffer buffer)
81: (set-mark select) ; Buffer-menu-execute changes things.
82: (Buffer-menu-execute)
83: (goto-char (mark))
84: (Buffer-menu-select)
85: (and (boundp 'after-electric-buffer-menu)
86: after-electric-buffer-menu
87: (funcall after-electric-buffer-menu))))))
88:
89: (defun Electric-buffer-menu-looper (state conditions)
90: (cond ((and conditions
91: (not (memq (car conditions)
92: '(buffer-read-only
93: end-of-buffer beginning-of-buffer))))
94: (signal (car conditions) (cdr conditions)))
95: ((< (point) (car state))
96: (Electric-buffer-menu-beginning))
97: ((> (point) (cdr state))
98: (Electric-buffer-menu-end))))
99:
100: (defun electric-buffer-menu-mode ()
101: "Major mode for editing a list of buffers.
102: Each line describes one of the buffers in Emacs.
103: Letters do not insert themselves; instead, they are commands.
104: C-g or C-c C-c -- exit buffer menu, returning to previous window and buffer
105: configuration. If the very first character typed is a space, it
106: also has this effect.
107: Space -- select buffer of line point is on.
108: Also show buffers marked with m in other windows,
109: kills buffers marked with k, and saves those marked with s.
110: m -- mark buffer to be displayed.
111: ~ -- clear modified-flag on that buffer.
112: s -- mark that buffer to be saved.
113: d or k or C-d or C-k -- mark that buffer to be killed.
114: u -- remove all kinds of marks from current line.
115: v -- view buffer, returning when done.
116: Delete -- back up a line and remove marks.
117: \\{Electric-buffer-menu-mode-map}
118: Entry to this mode via command \\[electric-buffer-list] calls the value of
119: electric-buffer-menu-mode-hook if it is non-nil. The value of
120: after-electric-buffer-menu is called on exit (when a selection is made)
121: if it is non-nil."
122: (kill-all-local-variables)
123: (use-local-map Electric-buffer-menu-mode-map)
124: (setq mode-line-format "-- Electric Buffer List %M %[%]----%3p-%-")
125: (setq truncate-lines t)
126: (setq buffer-read-only t)
127: (setq major-mode 'electric-buffer-menu-mode)
128: (setq mode-name "Electric Buffer Menu")
129: (run-hooks 'electric-buffer-menu-mode-hook))
130:
131: ;; generally the same as Buffer-menu-mode-map (except we don't indirect)
132: (put 'Electric-buffer-menu-undefined 'suppress-keymap t)
133: (if Electric-buffer-menu-mode-map
134: nil
135: (let ((map (make-keymap)))
136: (fillarray map 'Electric-buffer-menu-undefined)
137: (define-key map "\e" (make-keymap))
138: (fillarray (lookup-key map "\e") 'Electric-buffer-menu-undefined)
139: (define-key map "\C-z" 'suspend-emacs)
140: (define-key map "v" 'Electric-buffer-menu-mode-view-buffer)
141: (define-key map "\C-h" 'Helper-help)
142: (define-key map "?" 'Helper-describe-bindings)
143: (define-key map "\C-c" nil)
144: (define-key map "\C-c\C-c" 'Electric-buffer-menu-quit)
145: (define-key map "\C-]" 'Electric-buffer-menu-quit)
146: (define-key map "q" 'Electric-buffer-menu-quit)
147: (define-key map " " 'Electric-buffer-menu-select)
148: (define-key map "\C-l" 'recenter)
149: (define-key map "s" 'Buffer-menu-save)
150: (define-key map "d" 'Buffer-menu-kill)
151: (define-key map "k" 'Buffer-menu-kill)
152: (define-key map "\C-d" 'Buffer-menu-kill)
153: (define-key map "\C-k" 'Buffer-menu-kill)
154: (define-key map "\177" 'Buffer-menu-backup-unmark)
155: (define-key map "~" 'Buffer-menu-not-modified)
156: (define-key map "u" 'Buffer-menu-unmark)
157: (let ((i ?0))
158: (while (<= i ?9)
159: (define-key map (char-to-string i) 'digit-argument)
160: (define-key map (concat "\e" (char-to-string i)) 'digit-argument)
161: (setq i (1+ i))))
162: (define-key map "-" 'negative-argument)
163: (define-key map "\e-" 'negative-argument)
164: (define-key map "m" 'Buffer-menu-mark)
165: (define-key map "\C-u" 'universal-argument)
166: (define-key map "\C-p" 'previous-line)
167: (define-key map "\C-n" 'next-line)
168: (define-key map "\C-v" 'scroll-up)
169: (define-key map "\ev" 'scroll-down)
170: (define-key map "\e\C-v" 'scroll-other-window)
171: (define-key map "\e>" 'Electric-buffer-menu-end)
172: (define-key map "\e<" 'Electric-buffer-menu-beginning)
173: (setq Electric-buffer-menu-mode-map map)))
174:
175: (defun Electric-buffer-menu-exit ()
176: (interactive)
177: (setq unread-command-char last-input-char)
178: ;; for robustness
179: (condition-case ()
180: (throw 'electric-buffer-menu-select nil)
181: (error (Buffer-menu-mode)
182: (other-buffer))))
183:
184: (defun Electric-buffer-menu-select ()
185: "Leave Electric Buffer Menu, selecting buffers and executing changes.
186: Saves buffers marked `S'. Kills buffers marked `K'.
187: Selects buffer at point and displays buffers marked `>' in other
188: windows."
189: (interactive)
190: (throw 'electric-buffer-menu-select (point)))
191:
192: (defun Electric-buffer-menu-quit ()
193: "Leave Electric Buffer Menu, restoring previous window configuration.
194: Does not execute select, save, or kill commands."
195: (interactive)
196: (throw 'electric-buffer-menu-select nil))
197:
198: (defun Electric-buffer-menu-undefined ()
199: (interactive)
200: (ding)
201: (message (if (and (eq (key-binding "\C-c\C-c") 'Electric-buffer-menu-quit)
202: (eq (key-binding " ") 'Electric-buffer-menu-select)
203: (eq (key-binding "\C-h") 'Helper-help)
204: (eq (key-binding "?") 'Helper-describe-bindings))
205: "Type C-c C-c to exit, Space to select, C-h for help, ? for commands"
206: (substitute-command-keys "\
207: Type \\[Electric-buffer-menu-quit] to exit, \
208: \\[Electric-buffer-menu-select] to select, \
209: \\[Helper-help] for help, \\[Helper-describe-bindings] for commands.")))
210: (sit-for 4))
211:
212: (defun Electric-buffer-menu-beginning ()
213: "Move to the first buffer description in Electric Buffer Menu."
214: (interactive)
215: (goto-char (point-min))
216: (forward-line 2))
217:
218: (defun Electric-buffer-menu-end ()
219: "Move to the last buffer description in Electric Buffer Menu."
220: (interactive)
221: (goto-char (point-max))
222: (forward-line -1)
223: (if (not (pos-visible-in-window-p (point-max)))
224: (recenter (1- (/ (window-height (selected-window)) 2)))))
225:
226: (defun Electric-buffer-menu-mode-view-buffer ()
227: "View buffer on current line in Electric Buffer Menu.
228: Returns to Electric Buffer Menu when done."
229: (interactive)
230: (let ((bufnam (Buffer-menu-buffer nil)))
231: (if bufnam
232: (view-buffer bufnam)
233: (ding)
234: (message "Buffer %s does not exist!" bufnam)
235: (sit-for 4))))
236:
237:
238:
239:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.