annotate lisp/ebuff-menu.el @ 657:fec3f9a1e3e5

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