Mercurial > emacs
annotate lisp/ibuffer.el @ 42917:ec2db12c7670
(copy-without-properties): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 23 Jan 2002 17:46:44 +0000 |
parents | 5abd84afe99c |
children | 2a6ac08c9a18 |
rev | line source |
---|---|
42702 | 1 ;;; ibuffer.el --- operate on buffers like dired |
2 | |
42771
ed597889bfc8
(toplevel): Remove X-RCS, URL, Compatibility headers. Update
Colin Walters <walters@gnu.org>
parents:
42702
diff
changeset
|
3 ;; Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
42702 | 4 |
5 ;; Author: Colin Walters <walters@verbum.org> | |
6 ;; Created: 8 Sep 2000 | |
7 ;; Keywords: buffer, convenience | |
8 | |
9 ;; This file is not currently part of GNU Emacs. | |
10 | |
11 ;; This program is free software; you can redistribute it and/or | |
12 ;; modify it under the terms of the GNU General Public License as | |
13 ;; published by the Free Software Foundation; either version 2, or (at | |
14 ;; your option) any later version. | |
15 | |
16 ;; This program is distributed in the hope that it will be useful, but | |
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 ;; General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
22 ;; along with this program ; see the file COPYING. If not, write to | |
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
27 | |
28 ;; ibuffer.el is an advanced replacement for the `buffer-menu' which | |
29 ;; is normally distributed with Emacs. Its interface is intended to | |
30 ;; be analogous to that of Dired. | |
31 | |
32 ;;; Code: | |
33 | |
34 (eval-when-compile | |
35 (require 'cl) | |
36 (require 'ibuf-macs) | |
37 (require 'dired)) | |
38 | |
39 ;;; Compatibility | |
40 (eval-and-compile | |
41 (if (fboundp 'window-list) | |
42 (defun ibuffer-window-list () | |
43 (window-list nil 'nomini)) | |
44 (defun ibuffer-window-list () | |
45 (let ((ibuffer-window-list-result nil)) | |
46 (walk-windows #'(lambda (win) (push win ibuffer-window-list-result)) 'nomini) | |
47 (nreverse ibuffer-window-list-result)))) | |
48 | |
49 (cond ((boundp 'global-font-lock-mode) | |
50 (defsubst ibuffer-use-fontification () | |
51 (when (boundp 'font-lock-mode) | |
52 font-lock-mode))) | |
53 ((boundp 'font-lock-auto-fontify) | |
54 (defsubst ibuffer-use-fontification () | |
55 font-lock-auto-fontify)) | |
56 (t | |
57 (defsubst ibuffer-use-fontification () | |
58 nil)))) | |
59 | |
60 (defgroup ibuffer nil | |
61 "An advanced replacement for `buffer-menu'. | |
62 | |
63 Ibuffer allows you to operate on buffers in a manner much like Dired. | |
64 Operations include sorting, marking by regular expression, and | |
65 the ability to filter the displayed buffers by various criteria." | |
66 :link '(url-link "http://cvs.verbum.org/ibuffer") | |
67 :group 'convenience) | |
68 | |
69 (defcustom ibuffer-formats '((mark modified read-only " " (name 16 16 :left :elide) | |
70 " " (size 6 -1 :right) | |
71 " " (mode 16 16 :right :elide) " " filename) | |
72 (mark " " (name 16 -1) " " filename)) | |
73 "A list of ways to display buffer lines. | |
74 | |
75 With Ibuffer, you are not limited to displaying just certain | |
76 attributes of a buffer such as size, name, and mode in a particular | |
77 fashion. Through this variable, you can completely customize and | |
78 control the appearance of an Ibuffer buffer. See also | |
79 `define-ibuffer-column', which allows you to define your own columns | |
80 for display. | |
81 | |
82 This variable has the form | |
42873
e4be1ae52e5c
(toplevel, ibuffer-default-directory): Doc fixes.
Colin Walters <walters@gnu.org>
parents:
42871
diff
changeset
|
83 ((COLUMN COLUMN ...) (COLUMN COLUMN ...) ...) |
42702 | 84 Each element in `ibuffer-formats' should be a list containing COLUMN |
85 specifiers. A COLUMN can be any of the following: | |
86 | |
87 SYMBOL - A symbol naming the column. Predefined columns are: | |
88 mark modified read-only name size mode process filename | |
89 When you define your own columns using `define-ibuffer-column', just | |
90 use their name like the predefined columns here. This entry can | |
91 also be a function of two arguments, which should return a string. | |
92 The first argument is the buffer object, and the second is the mark | |
93 on that buffer. | |
94 or | |
95 \"STRING\" - A literal string to display. | |
96 or | |
97 (SYMBOL MIN-SIZE MAX-SIZE &optional ALIGN ELIDE) - SYMBOL is a | |
98 symbol naming the column, and MIN-SIZE and MAX-SIZE are integers (or | |
99 functions of no arguments returning an integer) which constrict the | |
100 size of a column. If MAX-SIZE is -1, there is no upper bound. The | |
101 default values are 0 and -1, respectively. If MIN-SIZE is negative, | |
102 use the end of the string. The optional element ALIGN describes the | |
103 alignment of the column; it can be :left, :center or :right. The | |
104 optional element ELIDE describes whether or not to elide the column | |
105 if it is too long; valid values are :elide and nil. The default is | |
106 nil (don't elide). | |
107 | |
108 Some example of valid entries in `ibuffer-formats', with | |
109 description (also, feel free to try them out, and experiment with your | |
110 own!): | |
111 | |
112 (mark \" \" name) | |
113 This format just displays the current mark (if any) and the name of | |
114 the buffer, separated by a space. | |
115 (mark modified read-only \" \" (name 16 16 :left) \" \" (size 6 -1 :right)) | |
116 This format displays the current mark (if any), its modification and | |
117 read-only status, as well as the name of the buffer and its size. In | |
118 this format, the name is restricted to 16 characters (longer names | |
119 will be truncated, nad shorter names will be padded with spaces), and | |
120 the name is also aligned to the right. The size of the buffer will | |
121 be padded with spaces up to a minimum of six characters, but there is | |
122 no upper limit on its size. The size will also be aligned to the | |
123 right. | |
124 | |
125 Thus, if you wanted to use these two formats, add | |
126 | |
127 (setq ibuffer-formats '((mark \" \" name) | |
128 (mark modified read-only | |
129 (name 16 16 :left) (size 6 -1 :right)))) | |
130 | |
131 to your ~/.emacs file. | |
132 | |
133 Using \\[ibuffer-switch-format], you can rotate the display between | |
134 the specified formats in the list." | |
135 :type '(repeat sexp) | |
136 :group 'ibuffer) | |
137 | |
138 (defcustom ibuffer-always-compile-formats (featurep 'bytecomp) | |
139 "If non-nil, then use the byte-compiler to optimize `ibuffer-formats'. | |
140 This will increase the redisplay speed, at the cost of loading the | |
141 elisp byte-compiler." | |
142 :type 'boolean | |
143 :group 'ibuffer) | |
144 | |
145 (defcustom ibuffer-fontification-alist | |
146 `((10 buffer-read-only font-lock-reference-face) | |
147 (15 (string-match "^*" (buffer-name)) font-lock-keyword-face) | |
148 (20 (string-match "^ " (buffer-name)) font-lock-warning-face) | |
149 (25 (memq major-mode '(help-mode apropos-mode info-mode)) font-lock-comment-face) | |
150 (30 (eq major-mode 'dired-mode) font-lock-function-name-face)) | |
151 "An alist describing how to fontify buffers. | |
152 Each element should be of the form (PRIORITY FORM FACE), where | |
153 PRIORITY is an integer, FORM is an arbitrary form to evaluate in the | |
154 buffer, and FACE is the face to use for fontification. If the FORM | |
155 evaluates to non-nil, then FACE will be put on the buffer name. The | |
156 element with the highest PRIORITY takes precedence." | |
157 :type '(repeat | |
158 (list (integer :tag "Priority") | |
159 (sexp :tag "Test Form") | |
160 face)) | |
161 :group 'ibuffer) | |
162 | |
163 (defcustom ibuffer-use-other-window nil | |
164 "If non-nil, display the Ibuffer in another window by default." | |
165 :type 'boolean | |
166 :group 'ibuffer) | |
167 | |
168 (defcustom ibuffer-default-shrink-to-minimum-size nil | |
169 "If non-nil, minimize the size of the Ibuffer window by default." | |
170 :type 'boolean | |
171 :group 'ibuffer) | |
172 (defvar ibuffer-shrink-to-minimum-size nil) | |
173 | |
174 (defcustom ibuffer-case-fold-search case-fold-search | |
175 "If non-nil, ignore case when searching." | |
176 :type 'boolean | |
177 :group 'ibuffer) | |
178 | |
179 (defcustom ibuffer-default-sorting-mode 'recency | |
180 "The criteria by which to sort the buffers. | |
181 | |
182 Note that this variable is local to each ibuffer buffer. Thus, you | |
183 can have multiple ibuffer buffers open, each with a different sorted | |
184 view of the buffers." | |
185 :type '(choice (const :tag "Last view time" :value recency) | |
186 (const :tag "Lexicographic" :value alphabetic) | |
187 (const :tag "Buffer size" :value size) | |
188 (const :tag "Major mode" :value major-mode)) | |
189 :group 'ibuffer) | |
190 (defvar ibuffer-sorting-mode nil) | |
191 | |
192 (defcustom ibuffer-default-sorting-reversep nil | |
193 "If non-nil, reverse the default sorting order." | |
194 :type 'boolean | |
195 :group 'ibuffer) | |
196 (defvar ibuffer-sorting-reversep nil) | |
197 | |
198 (defcustom ibuffer-elide-long-columns nil | |
199 "If non-nil, then elide column entries which exceed their max length. | |
200 This variable is deprecated; use the :elide argument of | |
201 `ibuffer-formats' to elide just certain columns." | |
202 :type 'boolean | |
203 :group 'ibuffer) | |
204 | |
205 (defcustom ibuffer-eliding-string "..." | |
206 "The string to use for eliding long columns." | |
207 :type 'string | |
208 :group 'ibuffer) | |
209 | |
210 (defcustom ibuffer-maybe-show-predicates `(,(lambda (buf) | |
211 (and (string-match "^ " (buffer-name buf)) | |
212 (null buffer-file-name)))) | |
213 "A list of predicates (a regexp or function) for buffers to display conditionally. | |
214 If a regexp, then it will be matched against the buffer's name. | |
215 If a function, it will be called with the buffer as an argument, and | |
216 should return non-nil if this buffer should be shown. | |
217 | |
218 Viewing of buffers hidden because of these predicates is enabled by | |
219 giving a non-nil prefix argument to `ibuffer-update'. Note that this | |
220 specialized filtering occurs before real filtering." | |
221 :type '(repeat (choice regexp function)) | |
222 :group 'ibuffer) | |
223 | |
224 (defvar ibuffer-current-format nil) | |
225 | |
226 (defcustom ibuffer-modified-char ?* | |
227 "The character to display for modified buffers." | |
228 :type 'character | |
229 :group 'ibuffer) | |
230 | |
231 (defcustom ibuffer-read-only-char ?% | |
232 "The character to display for read-only buffers." | |
233 :type 'character | |
234 :group 'ibuffer) | |
235 | |
236 (defcustom ibuffer-marked-char ?> | |
237 "The character to display for marked buffers." | |
238 :type 'character | |
239 :group 'ibuffer) | |
240 | |
241 (defcustom ibuffer-deletion-char ?D | |
242 "The character to display for buffers marked for deletion." | |
243 :type 'character | |
244 :group 'ibuffer) | |
245 | |
246 (defcustom ibuffer-expert nil | |
247 "If non-nil, don't ask for confirmation of \"dangerous\" operations." | |
248 :type 'boolean | |
249 :group 'ibuffer) | |
250 | |
251 (defcustom ibuffer-view-ibuffer nil | |
252 "If non-nil, display the current Ibuffer buffer itself. | |
253 Note that this has a drawback - the data about the current Ibuffer | |
254 buffer will most likely be inaccurate. This includes modification | |
255 state, size, etc." | |
256 :type 'boolean | |
257 :group 'ibuffer) | |
258 | |
259 (defcustom ibuffer-always-show-last-buffer nil | |
260 "If non-nil, always display the previous buffer. This variable | |
261 takes precedence over filtering, and even | |
262 `ibuffer-never-show-predicates'." | |
263 :type '(choice (const :tag "Always" :value t) | |
264 (const :tag "Never" :value nil) | |
265 (const :tag "Always except minibuffer" :value :nomini)) | |
266 :group 'ibuffer) | |
267 | |
268 (defcustom ibuffer-use-header-line (boundp 'header-line-format) | |
269 "If non-nil, display a header line containing current filters. | |
270 This feature only works on Emacs 21 or later." | |
271 :type 'boolean | |
272 :group 'ibuffer) | |
273 | |
274 (defcustom ibuffer-default-directory nil | |
275 "The default directory to use for a new ibuffer buffer. | |
42873
e4be1ae52e5c
(toplevel, ibuffer-default-directory): Doc fixes.
Colin Walters <walters@gnu.org>
parents:
42871
diff
changeset
|
276 If nil, inherit the directory of the buffer in which `ibuffer' was |
42702 | 277 called. Otherwise, this variable should be a string naming a |
278 directory, like `default-directory'." | |
279 :type '(choice (const :tag "Inherit" :value nil) | |
280 string) | |
281 :group 'ibuffer) | |
282 | |
283 (defcustom ibuffer-hooks nil | |
284 "Hooks run when `ibuffer' is called." | |
285 :type 'hook | |
286 :group 'ibuffer) | |
287 | |
288 (defcustom ibuffer-mode-hooks nil | |
289 "Hooks run upon entry into `ibuffer-mode'." | |
290 :type 'hook | |
291 :group 'ibuffer) | |
292 | |
293 (defcustom ibuffer-marked-face 'font-lock-warning-face | |
294 "Face used for displaying marked buffers." | |
295 :type 'face | |
296 :group 'ibuffer) | |
297 | |
298 (defcustom ibuffer-deletion-face 'font-lock-type-face | |
299 "Face used for displaying buffers marked for deletion." | |
300 :type 'face | |
301 :group 'ibuffer) | |
302 | |
303 (defcustom ibuffer-title-face 'font-lock-type-face | |
304 "Face used for the title string." | |
305 :type 'face | |
306 :group 'ibuffer) | |
307 | |
308 (defcustom ibuffer-directory-abbrev-alist nil | |
309 "An alist of file name abbreviations like `directory-abbrev-alist'." | |
310 :type '(repeat (cons :format "%v" | |
311 :value ("" . "") | |
312 (regexp :tag "From") | |
313 (regexp :tag "To"))) | |
314 :group 'ibuffer) | |
315 | |
316 (defvar ibuffer-mode-map nil) | |
317 (defvar ibuffer-mode-operate-map nil) | |
318 (unless ibuffer-mode-map | |
319 (let ((map (make-sparse-keymap)) | |
320 (operate-map (make-sparse-keymap "Operate"))) | |
321 (define-key map (kbd "0") 'digit-argument) | |
322 (define-key map (kbd "1") 'digit-argument) | |
323 (define-key map (kbd "2") 'digit-argument) | |
324 (define-key map (kbd "3") 'digit-argument) | |
325 (define-key map (kbd "4") 'digit-argument) | |
326 (define-key map (kbd "5") 'digit-argument) | |
327 (define-key map (kbd "6") 'digit-argument) | |
328 (define-key map (kbd "7") 'digit-argument) | |
329 (define-key map (kbd "8") 'digit-argument) | |
330 (define-key map (kbd "9") 'digit-argument) | |
331 | |
332 (define-key map (kbd "m") 'ibuffer-mark-forward) | |
333 (define-key map (kbd "t") 'ibuffer-toggle-marks) | |
334 (define-key map (kbd "u") 'ibuffer-unmark-forward) | |
335 (define-key map (kbd "=") 'ibuffer-diff-with-file) | |
336 (define-key map (kbd "j") 'ibuffer-jump-to-buffer) | |
337 (define-key map (kbd "DEL") 'ibuffer-unmark-backward) | |
338 (define-key map (kbd "M-DEL") 'ibuffer-unmark-all) | |
339 (define-key map (kbd "* *") 'ibuffer-unmark-all) | |
340 (define-key map (kbd "* M") 'ibuffer-mark-by-mode) | |
341 (define-key map (kbd "* m") 'ibuffer-mark-modified-buffers) | |
342 (define-key map (kbd "* u") 'ibuffer-mark-unsaved-buffers) | |
343 (define-key map (kbd "* s") 'ibuffer-mark-special-buffers) | |
344 (define-key map (kbd "* r") 'ibuffer-mark-read-only-buffers) | |
345 (define-key map (kbd "* /") 'ibuffer-mark-dired-buffers) | |
346 (define-key map (kbd "* e") 'ibuffer-mark-dissociated-buffers) | |
347 (define-key map (kbd "* h") 'ibuffer-mark-help-buffers) | |
348 (define-key map (kbd ".") 'ibuffer-mark-old-buffers) | |
349 | |
350 (define-key map (kbd "d") 'ibuffer-mark-for-delete) | |
351 (define-key map (kbd "C-d") 'ibuffer-mark-for-delete-backwards) | |
352 (define-key map (kbd "k") 'ibuffer-mark-for-delete) | |
353 (define-key map (kbd "x") 'ibuffer-do-kill-on-deletion-marks) | |
354 | |
355 ;; immediate operations | |
356 (define-key map (kbd "n") 'ibuffer-forward-line) | |
357 (define-key map (kbd "SPC") 'forward-line) | |
358 (define-key map (kbd "p") 'ibuffer-backward-line) | |
359 (define-key map (kbd "M-}") 'ibuffer-forward-next-marked) | |
360 (define-key map (kbd "M-{") 'ibuffer-backwards-next-marked) | |
361 (define-key map (kbd "l") 'ibuffer-redisplay) | |
362 (define-key map (kbd "g") 'ibuffer-update) | |
363 (define-key map "`" 'ibuffer-switch-format) | |
364 (define-key map "-" 'ibuffer-add-to-tmp-hide) | |
365 (define-key map "+" 'ibuffer-add-to-tmp-show) | |
366 (define-key map "b" 'ibuffer-bury-buffer) | |
367 (define-key map (kbd ",") 'ibuffer-toggle-sorting-mode) | |
368 (define-key map (kbd "s i") 'ibuffer-invert-sorting) | |
369 (define-key map (kbd "s a") 'ibuffer-do-sort-by-alphabetic) | |
370 (define-key map (kbd "s v") 'ibuffer-do-sort-by-recency) | |
371 (define-key map (kbd "s s") 'ibuffer-do-sort-by-size) | |
372 (define-key map (kbd "s m") 'ibuffer-do-sort-by-major-mode) | |
373 | |
374 (define-key map (kbd "/ m") 'ibuffer-filter-by-mode) | |
375 (define-key map (kbd "/ n") 'ibuffer-filter-by-name) | |
376 (define-key map (kbd "/ c") 'ibuffer-filter-by-content) | |
377 (define-key map (kbd "/ e") 'ibuffer-filter-by-predicate) | |
378 (define-key map (kbd "/ f") 'ibuffer-filter-by-filename) | |
379 (define-key map (kbd "/ >") 'ibuffer-filter-by-size-gt) | |
380 (define-key map (kbd "/ <") 'ibuffer-filter-by-size-lt) | |
381 (define-key map (kbd "/ r") 'ibuffer-switch-to-saved-filters) | |
382 (define-key map (kbd "/ a") 'ibuffer-add-saved-filters) | |
383 (define-key map (kbd "/ x") 'ibuffer-delete-saved-filters) | |
384 (define-key map (kbd "/ d") 'ibuffer-decompose-filter) | |
385 (define-key map (kbd "/ s") 'ibuffer-save-filters) | |
386 (define-key map (kbd "/ p") 'ibuffer-pop-filter) | |
387 (define-key map (kbd "/ !") 'ibuffer-negate-filter) | |
388 (define-key map (kbd "/ t") 'ibuffer-exchange-filters) | |
389 (define-key map (kbd "/ TAB") 'ibuffer-exchange-filters) | |
390 (define-key map (kbd "/ o") 'ibuffer-or-filter) | |
391 (define-key map (kbd "/ /") 'ibuffer-filter-disable) | |
392 | |
393 (define-key map (kbd "q") 'ibuffer-quit) | |
394 (define-key map (kbd "h") 'describe-mode) | |
395 (define-key map (kbd "?") 'describe-mode) | |
396 | |
397 (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp) | |
398 (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp) | |
399 (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp) | |
400 | |
401 (define-key map (kbd "C-t") 'ibuffer-visit-tags-table) | |
402 | |
403 (define-key map (kbd "|") 'ibuffer-do-shell-command-pipe) | |
404 (define-key map (kbd "!") 'ibuffer-do-shell-command-file) | |
405 (define-key map (kbd "~") 'ibuffer-do-toggle-modified) | |
406 ;; marked operations | |
407 (define-key map (kbd "A") 'ibuffer-do-view) | |
408 (define-key map (kbd "D") 'ibuffer-do-delete) | |
409 (define-key map (kbd "E") 'ibuffer-do-eval) | |
410 (define-key map (kbd "F") 'ibuffer-do-shell-command-file) | |
411 (define-key map (kbd "I") 'ibuffer-do-query-replace-regexp) | |
412 (define-key map (kbd "H") 'ibuffer-do-view-other-frame) | |
413 (define-key map (kbd "N") 'ibuffer-do-shell-command-pipe-replace) | |
414 (define-key map (kbd "M") 'ibuffer-do-toggle-modified) | |
415 (define-key map (kbd "O") 'ibuffer-do-occur) | |
416 (define-key map (kbd "P") 'ibuffer-do-print) | |
417 (define-key map (kbd "Q") 'ibuffer-do-query-replace) | |
418 (define-key map (kbd "R") 'ibuffer-do-rename-uniquely) | |
419 (define-key map (kbd "S") 'ibuffer-do-save) | |
420 (define-key map (kbd "T") 'ibuffer-do-toggle-read-only) | |
421 (define-key map (kbd "U") 'ibuffer-do-replace-regexp) | |
422 (define-key map (kbd "V") 'ibuffer-do-revert) | |
423 (define-key map (kbd "W") 'ibuffer-do-view-and-eval) | |
424 (define-key map (kbd "X") 'ibuffer-do-shell-command-pipe) | |
425 | |
426 (define-key map (kbd "k") 'ibuffer-do-kill-lines) | |
427 (define-key map (kbd "w") 'ibuffer-copy-filename-as-kill) | |
428 | |
429 (define-key map (kbd "RET") 'ibuffer-visit-buffer) | |
430 (define-key map (kbd "e") 'ibuffer-visit-buffer) | |
431 (define-key map (kbd "f") 'ibuffer-visit-buffer) | |
432 (define-key map (kbd "C-x C-f") 'ibuffer-find-file) | |
433 (define-key map (kbd "o") 'ibuffer-visit-buffer-other-window) | |
434 (define-key map (kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect) | |
435 (define-key map (kbd "M-o") 'ibuffer-visit-buffer-1-window) | |
436 (define-key map (kbd "v") 'ibuffer-do-view) | |
437 (define-key map (kbd "C-x v") 'ibuffer-do-view-horizontally) | |
438 (define-key map (kbd "C-c C-a") 'ibuffer-auto-mode) | |
439 (define-key map (kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window) | |
440 (define-key map (kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame) | |
441 | |
442 (define-key map [menu-bar view] | |
443 (cons "View" (make-sparse-keymap "View"))) | |
444 | |
445 (define-key-after map [menu-bar view visit-buffer] | |
446 '(menu-item "View this buffer" ibuffer-visit-buffer)) | |
447 (define-key-after map [menu-bar view visit-buffer-other-window] | |
448 '(menu-item "View (other window)" ibuffer-visit-buffer-other-window)) | |
449 (define-key-after map [menu-bar view visit-buffer-other-frame] | |
450 '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame)) | |
451 (define-key-after map [menu-bar view ibuffer-update] | |
452 '(menu-item "Update" ibuffer-update | |
453 :help "Regenerate the list of buffers")) | |
454 (define-key-after map [menu-bar view switch-format] | |
455 '(menu-item "Switch display format" ibuffer-switch-format | |
456 :help "Toggle between available values of `ibuffer-formats'")) | |
457 | |
458 (define-key-after map [menu-bar view dashes] | |
459 '("--")) | |
460 | |
461 (define-key-after map [menu-bar view sort] | |
462 (cons "Sort" (make-sparse-keymap "Sort"))) | |
463 | |
464 (define-key-after map [menu-bar view sort do-sort-by-major-mode] | |
465 '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode | |
466 :help "Sort by the alphabetic order of the buffer's major mode")) | |
467 (define-key-after map [menu-bar view sort do-sort-by-size] | |
468 '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size | |
469 :help "Sort by the size of the buffer")) | |
470 (define-key-after map [menu-bar view sort do-sort-by-alphabetic] | |
471 '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic | |
472 :help "Sort by the alphabetic order of buffer name")) | |
473 (define-key-after map [menu-bar view sort do-sort-by-recency] | |
474 '(menu-item "Sort by view time" ibuffer-do-sort-by-recency | |
475 :help "Sort by the last time the buffer was displayed")) | |
476 (define-key-after map [menu-bar view sort invert-sorting] | |
477 '(menu-item "Reverse sorting order" ibuffer-invert-sorting)) | |
478 (define-key-after map [menu-bar view sort toggle-sorting-mode] | |
479 '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode | |
480 :help "Switch between the various sorting criteria")) | |
481 | |
482 (define-key-after map [menu-bar view filter] | |
483 (cons "Filter" (make-sparse-keymap "Filter"))) | |
484 | |
485 (define-key-after map [menu-bar view filter filter-disable] | |
486 '(menu-item "Disable all filtering" ibuffer-filter-disable)) | |
487 (define-key-after map [menu-bar view filter filter-by-mode] | |
488 '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode | |
489 :help "Show only buffers in a major mode")) | |
490 (define-key-after map [menu-bar view filter filter-by-name] | |
491 '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name | |
492 :help "Show only buffers whose name matches a regexp")) | |
493 (define-key-after map [menu-bar view filter filter-by-filename] | |
494 '(menu-item "Add filter by filename..." ibuffer-filter-by-filename | |
495 :help "Show only buffers whose filename matches a regexp")) | |
496 (define-key-after map [menu-bar view filter filter-by-size-lt] | |
497 '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt | |
498 :help "Show only buffers of size less than...")) | |
499 (define-key-after map [menu-bar view filter filter-by-size-gt] | |
500 '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt | |
501 :help "Show only buffers of size greater than...")) | |
502 (define-key-after map [menu-bar view filter filter-by-content] | |
503 '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content | |
504 :help "Show only buffers containing a regexp")) | |
505 (define-key-after map [menu-bar view filter filter-by-predicate] | |
506 '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate | |
507 :help "Show only buffers for which a predicate is true")) | |
508 (define-key-after map [menu-bar view filter pop-filter] | |
509 '(menu-item "Remove top filter" ibuffer-pop-filter)) | |
510 (define-key-after map [menu-bar view filter or-filter] | |
511 '(menu-item "OR top two filters" ibuffer-or-filter | |
512 :help "Create a new filter which is the logical OR of the top two filters")) | |
513 (define-key-after map [menu-bar view filter negate-filter] | |
514 '(menu-item "Negate top filter" ibuffer-negate-filter)) | |
515 (define-key-after map [menu-bar view filter decompose-filter] | |
516 '(menu-item "Decompose top filter" ibuffer-decompose-filter | |
517 :help "Break down a complex filter like OR or NOT")) | |
518 (define-key-after map [menu-bar view filter exchange-filters] | |
519 '(menu-item "Swap top two filters" ibuffer-exchange-filters)) | |
520 (define-key-after map [menu-bar view filter save-filters] | |
521 '(menu-item "Save current filters permanently..." ibuffer-save-filters | |
522 :help "Use a mnemnonic name to store current filter stack")) | |
523 (define-key-after map [menu-bar view filter switch-to-saved-filters] | |
524 '(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters | |
525 :help "Replace current filters with a saved stack")) | |
526 (define-key-after map [menu-bar view filter add-saved-filters] | |
527 '(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters | |
528 :help "Include current filters in an already saved stack")) | |
529 (define-key-after map [menu-bar view filter delete-saved-filters] | |
530 '(menu-item "Delete permanently saved filters..." ibuffer-delete-saved-filters | |
531 :help "Remove stack of filters from saved list")) | |
532 (define-key-after map [menu-bar view dashes2] | |
533 '("--")) | |
534 (define-key-after map [menu-bar view diff-with-file] | |
535 '(menu-item "Diff with file" ibuffer-diff-with-file | |
536 :help "View the differences between this buffer and its file")) | |
537 (define-key-after map [menu-bar view auto-mode] | |
538 '(menu-item "Toggle Auto Mode" ibuffer-auto-mode | |
539 :help "Attempt to automatically update the Ibuffer buffer")) | |
540 (define-key-after map [menu-bar view customize] | |
541 '(menu-item "Customize Ibuffer" (lambda () (interactive) | |
542 (customize-group 'ibuffer)) | |
543 :help "Use Custom to customize Ibuffer")) | |
544 | |
545 (define-key-after map [menu-bar mark] | |
546 (cons "Mark" (make-sparse-keymap "Mark"))) | |
547 | |
548 (define-key-after map [menu-bar mark toggle-marks] | |
549 '(menu-item "Toggle marks" ibuffer-toggle-marks | |
550 :help "Unmark marked buffers, and mark unmarked buffers")) | |
551 (define-key-after map [menu-bar mark mark-forward] | |
552 '(menu-item "Mark" ibuffer-mark-forward | |
553 :help "Mark the buffer at point")) | |
554 (define-key-after map [menu-bar mark unmark-forward] | |
555 '(menu-item "Unmark" ibuffer-unmark-forward | |
556 :help "Unmark the buffer at point")) | |
557 (define-key-after map [menu-bar mark mark-by-mode] | |
558 '(menu-item "Mark by mode..." ibuffer-mark-by-mode | |
559 :help "Mark all buffers in a particular major mode")) | |
560 (define-key-after map [menu-bar mark mark-modified-buffers] | |
561 '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers | |
562 :help "Mark all buffers which have been modified")) | |
563 (define-key-after map [menu-bar mark mark-unsaved-buffers] | |
564 '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers | |
565 :help "Mark all buffers which have a file and are modified")) | |
566 (define-key-after map [menu-bar mark mark-read-only-buffers] | |
567 '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers | |
568 :help "Mark all buffers which are read-only")) | |
569 (define-key-after map [menu-bar mark mark-special-buffers] | |
570 '(menu-item "Mark special buffers" ibuffer-mark-special-buffers | |
571 :help "Mark all buffers whose name begins with a *")) | |
572 (define-key-after map [menu-bar mark mark-dired-buffers] | |
573 '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers | |
574 :help "Mark buffers in dired-mode")) | |
575 (define-key-after map [menu-bar mark mark-dissociated-buffers] | |
576 '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers | |
577 :help "Mark buffers with a non-existent associated file")) | |
578 (define-key-after map [menu-bar mark mark-help-buffers] | |
579 '(menu-item "Mark help buffers" ibuffer-mark-help-buffers | |
580 :help "Mark buffers in help-mode")) | |
581 (define-key-after map [menu-bar mark mark-old-buffers] | |
582 '(menu-item "Mark old buffers" ibuffer-mark-old-buffers | |
583 :help "Mark buffers which have not been viewed recently")) | |
584 (define-key-after map [menu-bar mark unmark-all] | |
585 '(menu-item "Unmark All" ibuffer-unmark-all)) | |
586 | |
587 (define-key-after map [menu-bar mark dashes] | |
588 '("--")) | |
589 | |
590 (define-key-after map [menu-bar mark mark-by-name-regexp] | |
591 '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp | |
592 :help "Mark buffers whose name matches a regexp")) | |
593 (define-key-after map [menu-bar mark mark-by-mode-regexp] | |
594 '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp | |
595 :help "Mark buffers whose major mode name matches a regexp")) | |
596 (define-key-after map [menu-bar mark mark-by-file-name-regexp] | |
597 '(menu-item "Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp | |
598 :help "Mark buffers whose file name matches a regexp")) | |
599 | |
600 ;; Operate map is added later | |
601 | |
602 (define-key-after operate-map [do-view] | |
603 '(menu-item "View" ibuffer-do-view)) | |
604 (define-key-after operate-map [do-view-other-frame] | |
605 '(menu-item "View (separate frame)" ibuffer-do-view-other-frame)) | |
606 (define-key-after operate-map [do-save] | |
607 '(menu-item "Save" ibuffer-do-save)) | |
608 (define-key-after operate-map [do-replace-regexp] | |
609 '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp | |
610 :help "Replace text inside marked buffers")) | |
611 (define-key-after operate-map [do-query-replace] | |
612 '(menu-item "Query Replace..." ibuffer-do-query-replace | |
613 :help "Replace text in marked buffers, asking each time")) | |
614 (define-key-after operate-map [do-query-replace-regexp] | |
615 '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp | |
616 :help "Replace text in marked buffers by regexp, asking each time")) | |
617 (define-key-after operate-map [do-print] | |
618 '(menu-item "Print" ibuffer-do-print)) | |
619 (define-key-after operate-map [do-toggle-modified] | |
620 '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified)) | |
621 (define-key-after operate-map [do-revert] | |
622 '(menu-item "Revert" ibuffer-do-revert | |
623 :help "Revert marked buffers to their associated file")) | |
624 (define-key-after operate-map [do-rename-uniquely] | |
625 '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely | |
626 :help "Rename marked buffers to a new, unique name")) | |
627 (define-key-after operate-map [do-delete] | |
628 '(menu-item "Kill" ibuffer-do-delete)) | |
629 (define-key-after operate-map [do-occur] | |
630 '(menu-item "List lines matching..." ibuffer-do-occur | |
631 :help "View all lines in marked buffers matching a regexp")) | |
632 (define-key-after operate-map [do-shell-command-pipe] | |
633 '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe | |
634 :help "For each marked buffer, send its contents to a shell command")) | |
635 (define-key-after operate-map [do-shell-command-pipe-replace] | |
636 '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace | |
637 :help "For each marked buffer, replace its contents with output of shell command")) | |
638 (define-key-after operate-map [do-shell-command-file] | |
639 '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file | |
640 :help "For each marked buffer, run a shell command with its file as argument")) | |
641 (define-key-after operate-map [do-eval] | |
642 '(menu-item "Eval..." ibuffer-do-eval | |
643 :help "Evaluate a Lisp form in each marked buffer")) | |
644 (define-key-after operate-map [do-view-and-eval] | |
645 '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval | |
646 :help "Evaluate a Lisp form in each marked buffer while viewing it")) | |
647 | |
648 (setq ibuffer-mode-map map | |
649 ibuffer-mode-operate-map operate-map))) | |
650 | |
651 (defvar ibuffer-name-map nil) | |
652 (unless ibuffer-name-map | |
653 (let ((map (make-sparse-keymap))) | |
654 (set-keymap-parent map ibuffer-mode-map) | |
655 (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark) | |
656 (define-key map [(mouse-2)] 'ibuffer-mouse-visit-buffer) | |
657 (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu) | |
658 (setq ibuffer-name-map map))) | |
659 | |
660 (defvar ibuffer-mode-name-map nil) | |
661 (unless ibuffer-mode-name-map | |
662 (let ((map (make-sparse-keymap))) | |
663 (set-keymap-parent map ibuffer-mode-map) | |
664 (define-key map [(mouse-2)] 'ibuffer-mouse-filter-by-mode) | |
665 (define-key map (kbd "RET") 'ibuffer-interactive-filter-by-mode) | |
666 (setq ibuffer-mode-name-map map))) | |
667 | |
668 ;; quiet the byte-compiler | |
669 (defvar ibuffer-mode-operate-menu nil) | |
670 (defvar ibuffer-mode-mark-menu nil) | |
671 (defvar ibuffer-mode-view-menu nil) | |
672 | |
673 (defvar ibuffer-mode-hooks nil) | |
674 | |
675 (defvar ibuffer-delete-window-on-quit nil | |
676 "Whether or not to delete the window upon exiting `ibuffer'.") | |
677 | |
678 (defvar ibuffer-did-modification nil) | |
679 | |
680 (defvar ibuffer-sorting-functions-alist nil | |
681 "An alist of functions which describe how to sort buffers. | |
682 | |
683 Note: You most likely do not want to modify this variable directly; | |
684 use `define-ibuffer-sorter' instead. | |
685 | |
686 The alist elements are constructed like (NAME DESCRIPTION FUNCTION) | |
687 Where NAME is a symbol describing the sorting method, DESCRIPTION is a | |
688 short string which will be displayed in the minibuffer and menu, and | |
689 FUNCTION is a function of two arguments, which will be the buffers to | |
690 compare.") | |
691 | |
692 ;;; Utility functions | |
693 (defun ibuffer-columnize-and-insert-list (list &optional pad-width) | |
694 "Insert LIST into the current buffer in as many columns as possible. | |
695 The maximum number of columns is determined by the current window | |
696 width and the longest string in LIST." | |
697 (unless pad-width | |
698 (setq pad-width 3)) | |
699 (let ((width (window-width)) | |
700 (max (+ (apply #'max (mapcar #'length list)) | |
701 pad-width))) | |
702 (let ((columns (/ width max))) | |
703 (when (zerop columns) | |
704 (setq columns 1)) | |
705 (while list | |
706 (dotimes (i (1- columns)) | |
707 (insert (concat (car list) (make-string (- max (length (car list))) | |
708 ? ))) | |
709 (setq list (cdr list))) | |
710 (when (not (null list)) | |
711 (insert (pop list))) | |
712 (insert "\n"))))) | |
713 | |
714 (defun ibuffer-accumulate-lines (count) | |
715 (save-excursion | |
716 (let ((forwardp (> count 0)) | |
717 (result nil)) | |
718 (while (not (or (zerop count) | |
719 (if forwardp | |
720 (eobp) | |
721 (bobp)))) | |
722 (if forwardp | |
723 (decf count) | |
724 (incf count)) | |
725 (push | |
726 (buffer-substring | |
727 (line-beginning-position) | |
728 (line-end-position)) | |
729 result) | |
730 (forward-line (if forwardp 1 -1))) | |
731 (nreverse result)))) | |
732 | |
733 (defsubst ibuffer-current-mark () | |
734 (cadr (get-text-property (line-beginning-position) | |
735 'ibuffer-properties))) | |
736 | |
737 (defun ibuffer-mouse-toggle-mark (event) | |
738 "Toggle the marked status of the buffer chosen with the mouse." | |
739 (interactive "e") | |
740 (unwind-protect | |
741 (save-excursion | |
742 (mouse-set-point event) | |
743 (let ((mark (ibuffer-current-mark))) | |
744 (setq buffer-read-only nil) | |
745 (if (eq mark ibuffer-marked-char) | |
746 (ibuffer-set-mark ? ) | |
747 (ibuffer-set-mark ibuffer-marked-char)))) | |
748 (setq buffer-read-only t))) | |
749 | |
750 (defun ibuffer-find-file (file &optional wildcards) | |
751 "Like `find-file', but default to the directory of the buffer at point." | |
752 (interactive | |
753 (let ((default-directory (let ((buf (ibuffer-current-buffer))) | |
754 (if (buffer-live-p buf) | |
755 (with-current-buffer buf | |
756 default-directory) | |
757 default-directory)))) | |
758 (list (read-file-name "Find file: " default-directory) | |
759 current-prefix-arg))) | |
760 (find-file file wildcards)) | |
761 | |
762 (defun ibuffer-mouse-visit-buffer (event) | |
763 "Visit the buffer chosen with the mouse." | |
764 (interactive "e") | |
765 (switch-to-buffer | |
766 (save-excursion | |
767 (mouse-set-point event) | |
768 (ibuffer-current-buffer)))) | |
769 | |
770 (defun ibuffer-mouse-popup-menu (event) | |
771 "Display a menu of operations." | |
772 (interactive "e") | |
773 (let ((origline (count-lines (point-min) (point)))) | |
774 (unwind-protect | |
775 (progn | |
776 (setq buffer-read-only nil) | |
777 (ibuffer-save-marks | |
778 ;; hm. we could probably do this in a better fashion | |
779 (ibuffer-unmark-all ?\r) | |
780 (setq buffer-read-only nil) | |
781 (mouse-set-point event) | |
782 (ibuffer-set-mark ibuffer-marked-char) | |
783 (setq buffer-read-only nil) | |
784 (save-excursion | |
785 (popup-menu ibuffer-mode-operate-map)))) | |
786 (progn | |
787 (setq buffer-read-only t) | |
788 (goto-line (1+ origline)))))) | |
789 | |
790 (defun ibuffer-backward-line (&optional arg) | |
791 "Move backwards ARG lines, wrapping around the list if necessary." | |
792 (interactive "P") | |
793 (unless arg | |
794 (setq arg 1)) | |
795 (beginning-of-line) | |
796 (while (> arg 0) | |
797 (forward-line -1) | |
798 (when (get-text-property (point) 'ibuffer-title) | |
799 (goto-char (point-max)) | |
800 (forward-line -1) | |
801 (setq arg 0)) | |
802 (setq arg (1- arg)))) | |
803 | |
804 (defun ibuffer-forward-line (&optional arg) | |
805 "Move forward ARG lines, wrapping around the list if necessary." | |
806 (interactive "P") | |
807 (unless arg | |
808 (setq arg 1)) | |
809 (beginning-of-line) | |
810 (if (< arg 0) | |
811 (ibuffer-backward-line (- arg)) | |
812 (progn | |
813 (when (get-text-property (point) 'ibuffer-title) | |
814 ;; If we're already on the title, moving past it counts as | |
815 ;; moving a line. | |
816 (decf arg) | |
817 (while (and (get-text-property (point) 'ibuffer-title) | |
818 (not (eobp))) | |
819 (forward-line 1))) | |
820 (while (> arg 0) | |
821 (forward-line 1) | |
822 (when (eobp) | |
823 (goto-char (point-min))) | |
824 (while (and (get-text-property (point) 'ibuffer-title) | |
825 (not (eobp))) | |
826 (forward-line 1)) | |
827 (setq arg (1- arg)))))) | |
828 | |
829 (defun ibuffer-visit-buffer () | |
830 "Visit the buffer on this line." | |
831 (interactive) | |
832 (let ((buf (ibuffer-current-buffer))) | |
833 (unless (buffer-live-p buf) | |
834 (error "Buffer %s has been killed!" buf)) | |
835 (bury-buffer (current-buffer)) | |
836 (switch-to-buffer buf))) | |
837 | |
838 (defun ibuffer-visit-buffer-other-window (&optional noselect) | |
839 "Visit the buffer on this line in another window." | |
840 (interactive) | |
841 (let ((buf (ibuffer-current-buffer))) | |
842 (unless (buffer-live-p buf) | |
843 (error "Buffer %s has been killed!" buf)) | |
844 (bury-buffer (current-buffer)) | |
845 (if noselect | |
846 (let ((curwin (selected-window))) | |
847 (pop-to-buffer buf) | |
848 (select-window curwin)) | |
849 (switch-to-buffer-other-window buf)))) | |
850 | |
851 (defun ibuffer-visit-buffer-other-window-noselect () | |
852 "Visit the buffer on this line in another window, but don't select it." | |
853 (interactive) | |
854 (ibuffer-visit-buffer-other-window t)) | |
855 | |
856 (defun ibuffer-visit-buffer-other-frame () | |
857 "Visit the buffer on this line in another frame." | |
858 (interactive) | |
859 (let ((buf (ibuffer-current-buffer))) | |
860 (unless (buffer-live-p buf) | |
861 (error "Buffer %s has been killed!" buf)) | |
862 (bury-buffer (current-buffer)) | |
863 (switch-to-buffer-other-frame buf))) | |
864 | |
865 (defun ibuffer-visit-buffer-1-window () | |
866 "Visit the buffer on this line, and delete other windows." | |
867 (interactive) | |
868 (let ((buf (ibuffer-current-buffer))) | |
869 (unless (buffer-live-p buf) | |
870 (error "Buffer %s has been killed!" buf)) | |
871 (switch-to-buffer buf) | |
872 (delete-other-windows))) | |
873 | |
874 (defun ibuffer-bury-buffer () | |
875 "Bury the buffer on this line." | |
876 (interactive) | |
877 (let ((buf (ibuffer-current-buffer)) | |
878 (line (+ 1 (count-lines 1 (point))))) | |
879 (unless (buffer-live-p buf) | |
880 (error "Buffer %s has been killed!" buf)) | |
881 (bury-buffer buf) | |
882 (ibuffer-update nil t) | |
883 (goto-line line))) | |
884 | |
885 (defun ibuffer-visit-tags-table () | |
886 "Visit the tags table in the buffer on this line. See `visit-tags-table'." | |
887 (interactive) | |
888 (let ((file (buffer-file-name (ibuffer-current-buffer)))) | |
889 (if file | |
890 (visit-tags-table file) | |
891 (error "Specified buffer has no file")))) | |
892 | |
893 (defun ibuffer-do-view (&optional other-frame) | |
894 "View marked buffers, or the buffer on the current line. | |
895 If optional argument OTHER-FRAME is non-nil, then display each | |
896 marked buffer in a new frame. Otherwise, display each buffer as | |
897 a new window in the current frame, splitting vertically." | |
898 (interactive) | |
899 (ibuffer-do-view-1 (if other-frame 'other-frame 'vertically))) | |
900 | |
901 (defun ibuffer-do-view-horizontally (&optional other-frame) | |
902 "As `ibuffer-do-view', but split windows horizontally." | |
903 (interactive) | |
904 (ibuffer-do-view-1 (if other-frame 'other-frame 'horizontally))) | |
905 | |
906 (defun ibuffer-do-view-1 (type) | |
907 (let ((marked-bufs (ibuffer-get-marked-buffers))) | |
908 (when (null marked-bufs) | |
909 (setq marked-bufs (list (ibuffer-current-buffer)))) | |
910 (unless (and (eq type 'other-frame) | |
911 (not ibuffer-expert) | |
912 (> (length marked-bufs) 3) | |
913 (not (y-or-n-p (format "Really create a new frame for %s buffers? " | |
914 (length marked-bufs))))) | |
915 (set-buffer-modified-p nil) | |
916 (delete-other-windows) | |
917 (switch-to-buffer (pop marked-bufs)) | |
918 (let ((height (/ (1- (if (eq type 'horizontally) (frame-width) | |
919 (frame-height))) | |
920 (1+ (length marked-bufs))))) | |
921 (mapcar (if (eq type 'other-frame) | |
922 #'(lambda (buf) | |
923 (let ((curframe (selected-frame))) | |
924 (select-frame (new-frame)) | |
925 (switch-to-buffer buf) | |
926 (select-frame curframe))) | |
927 #'(lambda (buf) | |
928 (split-window nil height (eq type 'horizontally)) | |
929 (other-window 1) | |
930 (switch-to-buffer buf))) | |
931 marked-bufs))))) | |
932 | |
933 (defun ibuffer-do-view-other-frame () | |
934 "View each of the marked buffers in a separate frame." | |
935 (interactive) | |
936 (ibuffer-do-view t)) | |
937 | |
938 (defsubst ibuffer-map-marked-lines (func) | |
939 (prog1 (ibuffer-map-on-mark ibuffer-marked-char func) | |
940 (ibuffer-redisplay t))) | |
941 | |
942 (defun ibuffer-shrink-to-fit (&optional owin) | |
943 (fit-window-to-buffer nil (when owin (/ (frame-height) | |
944 (length (window-list (selected-frame))))))) | |
945 | |
946 (defun ibuffer-confirm-operation-on (operation names) | |
947 "Display a buffer asking whether to perform OPERATION on NAMES." | |
948 (or ibuffer-expert | |
949 (if (= (length names) 1) | |
950 (y-or-n-p (format "Really %s buffer %s? " operation (car names))) | |
951 (let ((buf (get-buffer-create "*Ibuffer confirmation*"))) | |
952 (with-current-buffer buf | |
953 (setq buffer-read-only nil) | |
954 (erase-buffer) | |
955 (ibuffer-columnize-and-insert-list names) | |
956 (goto-char (point-min)) | |
957 (setq buffer-read-only t)) | |
958 (let ((lastwin (car (last (ibuffer-window-list))))) | |
959 ;; Now attempt to display the buffer... | |
960 (save-window-excursion | |
961 (select-window lastwin) | |
962 ;; The window might be too small to split; in that case, | |
963 ;; try a few times to increase its size before giving up. | |
964 (let ((attempts 0) | |
965 (trying t)) | |
966 (while trying | |
967 (condition-case err | |
968 (progn | |
969 (split-window) | |
970 (setq trying nil)) | |
971 (error | |
972 ;; Handle a failure | |
973 (if (or (> (incf attempts) 4) | |
974 (and (stringp (cadr err)) | |
975 ;; This definitely falls in the ghetto hack category... | |
976 (not (string-match "too small" (cadr err))))) | |
977 (apply #'signal err) | |
978 (enlarge-window 3)))))) | |
979 ;; This part doesn't work correctly sometimes under XEmacs. | |
980 (select-window (next-window)) | |
981 (switch-to-buffer buf) | |
982 (unwind-protect | |
983 (progn | |
984 (fit-window-to-buffer) | |
985 (y-or-n-p (format "Really %s %d buffers? " | |
986 operation (length names)))) | |
987 (kill-buffer buf)))))))) | |
988 | |
989 (defsubst ibuffer-map-lines-nomodify (function) | |
990 "As `ibuffer-map-lines', but don't set the modification flag." | |
991 (ibuffer-map-lines function t)) | |
992 | |
993 (defun ibuffer-buffer-names-with-mark (mark) | |
994 (let ((ibuffer-buffer-names-with-mark-result nil)) | |
995 (ibuffer-map-lines-nomodify | |
996 #'(lambda (buf mk beg end) | |
997 (when (char-equal mark mk) | |
998 (push (buffer-name buf) | |
999 ibuffer-buffer-names-with-mark-result)))) | |
1000 ibuffer-buffer-names-with-mark-result)) | |
1001 | |
1002 (defsubst ibuffer-marked-buffer-names () | |
1003 (ibuffer-buffer-names-with-mark ibuffer-marked-char)) | |
1004 | |
1005 (defsubst ibuffer-deletion-marked-buffer-names () | |
1006 (ibuffer-buffer-names-with-mark ibuffer-deletion-char)) | |
1007 | |
1008 (defun ibuffer-count-marked-lines (&optional all) | |
1009 (if all | |
1010 (ibuffer-map-lines-nomodify | |
1011 #'(lambda (buf mark beg end) | |
1012 (not (char-equal mark ? )))) | |
1013 (ibuffer-map-lines-nomodify | |
1014 #'(lambda (buf mark beg end) | |
1015 (char-equal mark ibuffer-marked-char))))) | |
1016 | |
1017 (defsubst ibuffer-count-deletion-lines () | |
1018 (ibuffer-map-lines-nomodify | |
1019 #'(lambda (buf mark beg end) | |
1020 (char-equal mark ibuffer-deletion-char)))) | |
1021 | |
1022 (defsubst ibuffer-map-deletion-lines (func) | |
1023 (ibuffer-map-on-mark ibuffer-deletion-char func)) | |
1024 | |
1025 (define-ibuffer-op save () | |
1026 "Save marked buffers as with `save-buffer'." | |
1027 (:complex t | |
1028 :opstring "saved" | |
1029 :modifier-p :maybe) | |
1030 (when (buffer-modified-p buf) | |
1031 (if (not (with-current-buffer buf | |
1032 buffer-file-name)) | |
1033 ;; handle the case where we're prompted | |
1034 ;; for a file name | |
1035 (save-window-excursion | |
1036 (switch-to-buffer buf) | |
1037 (save-buffer)) | |
1038 (with-current-buffer buf | |
1039 (save-buffer)))) | |
1040 t) | |
1041 | |
1042 (define-ibuffer-op toggle-modified () | |
1043 "Toggle modification flag of marked buffers." | |
1044 (:opstring "(un)marked as modified" | |
1045 :modifier-p t) | |
1046 (set-buffer-modified-p (not (buffer-modified-p)))) | |
1047 | |
1048 (define-ibuffer-op toggle-read-only () | |
1049 "Toggle read only status in marked buffers." | |
1050 (:opstring "toggled read only status in" | |
1051 :modifier-p t) | |
1052 (toggle-read-only)) | |
1053 | |
1054 (define-ibuffer-op delete () | |
1055 "Kill marked buffers as with `kill-this-buffer'." | |
1056 (:opstring "killed" | |
1057 :active-opstring "kill" | |
1058 :dangerous t | |
1059 :complex t | |
1060 :modifier-p t) | |
1061 (if (kill-buffer buf) | |
1062 'kill | |
1063 nil)) | |
1064 | |
1065 (define-ibuffer-op kill-on-deletion-marks () | |
1066 "Kill buffers marked for deletion as with `kill-this-buffer'." | |
1067 (:opstring "killed" | |
1068 :active-opstring "kill" | |
1069 :dangerous t | |
1070 :complex t | |
1071 :mark :deletion | |
1072 :modifier-p t) | |
1073 (if (kill-buffer buf) | |
1074 'kill | |
1075 nil)) | |
1076 | |
1077 (defun ibuffer-unmark-all (mark) | |
1078 "Unmark all buffers with mark MARK." | |
1079 (interactive "cRemove marks (RET means all):") | |
1080 (if (= (ibuffer-count-marked-lines t) 0) | |
1081 (message "No buffers marked; use 'm' to mark a buffer") | |
1082 (cond | |
1083 ((char-equal mark ibuffer-marked-char) | |
1084 (ibuffer-map-marked-lines | |
1085 #'(lambda (buf mark beg end) | |
1086 (ibuffer-set-mark-1 ? ) | |
1087 t))) | |
1088 ((char-equal mark ibuffer-deletion-char) | |
1089 (ibuffer-map-deletion-lines | |
1090 #'(lambda (buf mark beg end) | |
1091 (ibuffer-set-mark-1 ? ) | |
1092 t))) | |
1093 (t | |
1094 (ibuffer-map-lines | |
1095 #'(lambda (buf mark beg end) | |
1096 (when (not (char-equal mark ? )) | |
1097 (ibuffer-set-mark-1 ? )) | |
1098 t))))) | |
1099 (ibuffer-redisplay t)) | |
1100 | |
1101 (defun ibuffer-toggle-marks () | |
1102 "Toggle which buffers are marked. | |
1103 In other words, unmarked buffers become marked, and marked buffers | |
1104 become unmarked." | |
1105 (interactive) | |
1106 (let ((count | |
1107 (ibuffer-map-lines | |
1108 #'(lambda (buf mark beg end) | |
1109 (cond ((eq mark ibuffer-marked-char) | |
1110 (ibuffer-set-mark-1 ? ) | |
1111 nil) | |
1112 ((eq mark ? ) | |
1113 (ibuffer-set-mark-1 ibuffer-marked-char) | |
1114 t) | |
1115 (t | |
1116 nil)))))) | |
1117 (message "%s buffers marked" count)) | |
1118 (ibuffer-redisplay t)) | |
1119 | |
1120 (defun ibuffer-mark-forward (arg) | |
1121 "Mark the buffer on this line, and move forward ARG lines." | |
1122 (interactive "P") | |
1123 (ibuffer-mark-interactive arg ibuffer-marked-char 1)) | |
1124 | |
1125 (defun ibuffer-unmark-forward (arg) | |
1126 "Unmark the buffer on this line, and move forward ARG lines." | |
1127 (interactive "P") | |
1128 (ibuffer-mark-interactive arg ? 1)) | |
1129 | |
1130 (defun ibuffer-unmark-backward (arg) | |
1131 "Unmark the buffer on this line, and move backward ARG lines." | |
1132 (interactive "P") | |
1133 (ibuffer-mark-interactive arg ? -1)) | |
1134 | |
1135 (defun ibuffer-mark-interactive (arg mark movement) | |
1136 (assert (eq major-mode 'ibuffer-mode)) | |
1137 (unless arg | |
1138 (setq arg 1)) | |
1139 (while (and (get-text-property (line-beginning-position) | |
1140 'ibuffer-title) | |
1141 (not (eobp))) | |
1142 (forward-line 1)) | |
1143 | |
1144 (let ((inhibit-read-only t)) | |
1145 (while (> arg 0) | |
1146 (ibuffer-set-mark mark) | |
1147 (forward-line movement) | |
1148 (when (or (get-text-property (line-beginning-position) | |
1149 'ibuffer-title) | |
1150 (eobp)) | |
1151 (forward-line (- movement)) | |
1152 (setq arg 0)) | |
1153 (setq arg (1- arg))))) | |
1154 | |
1155 (defun ibuffer-set-mark (mark) | |
1156 (assert (eq major-mode 'ibuffer-mode)) | |
1157 (let ((inhibit-read-only t)) | |
1158 (ibuffer-set-mark-1 mark) | |
1159 (setq ibuffer-did-modification t) | |
1160 (ibuffer-redisplay-current))) | |
1161 | |
1162 (defun ibuffer-set-mark-1 (mark) | |
1163 (let ((beg (line-beginning-position)) | |
1164 (end (line-end-position))) | |
1165 (put-text-property beg end 'ibuffer-properties | |
1166 (list (ibuffer-current-buffer) | |
1167 mark)))) | |
1168 | |
1169 (defun ibuffer-mark-for-delete (arg) | |
1170 "Mark the buffers on ARG lines forward for deletion." | |
1171 (interactive "P") | |
1172 (ibuffer-mark-interactive arg ibuffer-deletion-char 1)) | |
1173 | |
1174 (defun ibuffer-mark-for-delete-backwards (arg) | |
1175 "Mark the buffers on ARG lines backward for deletion." | |
1176 (interactive "P") | |
1177 (ibuffer-mark-interactive arg ibuffer-deletion-char -1)) | |
1178 | |
1179 (defun ibuffer-current-buffer (&optional must-be-live) | |
1180 (let ((buf (car (get-text-property (line-beginning-position) | |
1181 'ibuffer-properties)))) | |
1182 (when (and must-be-live | |
1183 (not (buffer-live-p buf))) | |
1184 (error "Buffer %s has been killed!" buf)) | |
1185 buf)) | |
1186 | |
1187 (defun ibuffer-current-format () | |
1188 (when (null ibuffer-formats) | |
1189 (error "No format!")) | |
1190 (ibuffer-check-formats) | |
1191 (or ibuffer-current-format | |
1192 (setq ibuffer-current-format 0)) | |
1193 (nth ibuffer-current-format ibuffer-compiled-formats)) | |
1194 | |
1195 (defun ibuffer-expand-format-entry (form) | |
1196 (if (or (consp form) | |
1197 (symbolp form)) | |
1198 (let ((sym (intern (concat "ibuffer-make-column-" | |
1199 (symbol-name (if (consp form) | |
1200 (car form) | |
1201 form)))))) | |
1202 (unless (or (fboundp sym) | |
1203 (assq sym ibuffer-inline-columns)) | |
1204 (error "Unknown column %s in ibuffer-formats" form)) | |
1205 (let (min max align elide) | |
1206 (if (consp form) | |
1207 (setq min (or (nth 1 form) 0) | |
1208 max (or (nth 2 form) -1) | |
1209 align (or (nth 3 form) :left) | |
1210 elide (or (nth 4 form) nil)) | |
1211 (setq min 0 | |
1212 max -1 | |
1213 align :left | |
1214 elide nil)) | |
1215 (list sym min max align elide))) | |
1216 form)) | |
1217 | |
1218 (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p) | |
1219 (let ((ellipsis (if (ibuffer-use-fontification) | |
1220 (propertize ibuffer-eliding-string 'face 'bold) | |
1221 ibuffer-eliding-string))) | |
1222 (if (or elide ibuffer-elide-long-columns) | |
1223 `(if (> strlen 5) | |
1224 ,(if from-end-p | |
1225 `(concat ,ellipsis | |
1226 (substring ,strvar | |
1227 (length ibuffer-eliding-string))) | |
1228 `(concat | |
1229 (substring ,strvar 0 (- strlen ,(length ellipsis))) | |
1230 ,ellipsis)) | |
1231 ,strvar) | |
1232 strvar))) | |
1233 | |
1234 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p) | |
1235 (if from-end-p | |
1236 `(substring str | |
1237 (- strlen ,maxvar)) | |
1238 `(substring ,strvar 0 ,maxvar))) | |
1239 | |
1240 (defun ibuffer-compile-make-format-form (strvar widthform alignment) | |
1241 (let* ((left `(make-string tmp2 ? )) | |
1242 (right `(make-string (- tmp1 tmp2) ? ))) | |
1243 `(progn | |
1244 (setq tmp1 ,widthform | |
1245 tmp2 (/ tmp1 2)) | |
1246 ,(case alignment | |
1247 (:right `(concat ,left ,right ,strvar)) | |
1248 (:center `(concat ,left ,strvar ,right)) | |
1249 (:left `(concat ,strvar ,left ,right)) | |
1250 (t (error "Invalid alignment %s" alignment)))))) | |
1251 | |
1252 (defun ibuffer-compile-format (format) | |
1253 (let ((result nil) | |
1254 str-used | |
1255 tmp1-used tmp2-used global-strlen-used) | |
1256 (dolist (form format) | |
1257 (push | |
1258 (if (stringp form) | |
1259 `(insert ,form) | |
1260 (let* ((form (ibuffer-expand-format-entry form)) | |
1261 (sym (nth 0 form)) | |
1262 (min (nth 1 form)) | |
1263 (max (nth 2 form)) | |
1264 (align (nth 3 form)) | |
1265 (elide (nth 4 form))) | |
1266 (let* ((from-end-p (when (minusp min) | |
1267 (setq min (- min)) | |
1268 t)) | |
1269 (letbindings nil) | |
1270 (outforms nil) | |
1271 minform | |
1272 maxform | |
1273 min-used max-used strlen-used) | |
1274 (when (or (not (integerp min)) (>= min 0)) | |
1275 (setq min-used t) | |
1276 (setq str-used t strlen-used t global-strlen-used t | |
1277 tmp1-used t tmp2-used t) | |
1278 (setq minform `(progn | |
1279 (setq str | |
1280 ,(ibuffer-compile-make-format-form | |
1281 'str | |
1282 `(- ,(if (integerp min) | |
1283 min | |
1284 'min) | |
1285 strlen) | |
1286 align))))) | |
1287 (when (or (not (integerp max)) (> max 0)) | |
1288 (setq str-used t max-used t) | |
1289 (setq maxform `(progn | |
1290 (setq str | |
1291 ,(ibuffer-compile-make-substring-form | |
1292 'str | |
1293 (if (integerp max) | |
1294 max | |
1295 'max) | |
1296 from-end-p)) | |
1297 (setq strlen (length str)) | |
1298 (setq str | |
1299 ,(ibuffer-compile-make-eliding-form 'str | |
1300 elide | |
1301 from-end-p))))) | |
1302 (let ((callform (ibuffer-aif (assq sym ibuffer-inline-columns) | |
1303 (nth 1 it) | |
1304 `(,sym buffer mark))) | |
1305 (mincompform `(< strlen ,(if (integerp min) | |
1306 min | |
1307 'min))) | |
1308 (maxcompform `(> strlen ,(if (integerp max) | |
1309 max | |
1310 'max)))) | |
1311 (if (or min-used max-used) | |
1312 (progn | |
1313 (when (and min-used (not (integerp min))) | |
1314 (push `(min ,min) letbindings)) | |
1315 (when (and max-used (not (integerp max))) | |
1316 (push `(max ,max) letbindings)) | |
1317 (push | |
1318 (if (and min-used max-used) | |
1319 `(if ,mincompform | |
1320 ,minform | |
1321 (if ,maxcompform | |
1322 ,maxform)) | |
1323 (if min-used | |
1324 `(when ,mincompform | |
1325 ,minform) | |
1326 `(when ,maxcompform | |
1327 ,maxform))) | |
1328 outforms) | |
1329 (push (append | |
1330 `(setq str ,callform) | |
1331 (when strlen-used | |
1332 `(strlen (length str)))) | |
1333 outforms) | |
1334 (setq outforms | |
1335 (append outforms `((insert str))))) | |
1336 (push `(insert ,callform) outforms)) | |
1337 `(let ,letbindings | |
1338 ,@outforms))))) | |
1339 result)) | |
1340 (setq result | |
1341 (funcall (if (or ibuffer-always-compile-formats | |
1342 (featurep 'bytecomp)) | |
1343 #'byte-compile | |
1344 #'identity) | |
1345 (nconc (list 'lambda '(buffer mark)) | |
1346 `((let ,(append '(pt) | |
1347 (when str-used | |
1348 '(str)) | |
1349 (when global-strlen-used | |
1350 '(strlen)) | |
1351 (when tmp1-used | |
1352 '(tmp1)) | |
1353 (when tmp2-used | |
1354 '(tmp2))) | |
1355 ,@(nreverse result)))))))) | |
1356 | |
1357 (defvar ibuffer-compiled-formats nil) | |
1358 (defvar ibuffer-cached-formats nil) | |
1359 (defvar ibuffer-cached-eliding-string nil) | |
1360 (defvar ibuffer-cached-elide-long-columns 0) | |
1361 | |
1362 (defun ibuffer-recompile-formats () | |
1363 "Recompile `ibuffer-formats'." | |
1364 (interactive) | |
1365 (setq ibuffer-compiled-formats | |
1366 (mapcar #'ibuffer-compile-format ibuffer-formats))) | |
1367 | |
1368 (defun ibuffer-check-formats () | |
1369 (when (or (null ibuffer-compiled-formats) | |
1370 (null ibuffer-cached-formats) | |
1371 (not (equal ibuffer-cached-formats ibuffer-formats)) | |
1372 (null ibuffer-cached-eliding-string) | |
1373 (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string)) | |
1374 (eql 0 ibuffer-cached-elide-long-columns) | |
1375 (not (eql ibuffer-cached-elide-long-columns | |
1376 ibuffer-elide-long-columns))) | |
1377 (message "Formats have changed, recompiling...") | |
1378 (ibuffer-recompile-formats) | |
1379 (setq ibuffer-cached-formats ibuffer-formats | |
1380 ibuffer-cached-eliding-string ibuffer-eliding-string | |
1381 ibuffer-cached-elide-long-columns ibuffer-elide-long-columns) | |
1382 (message "Formats have changed, recompiling...done"))) | |
1383 | |
1384 (defvar ibuffer-inline-columns nil) | |
1385 | |
1386 (define-ibuffer-column mark (:name " " :inline t) | |
1387 (string mark)) | |
1388 | |
1389 (define-ibuffer-column read-only (:name "R" :inline t) | |
1390 (if buffer-read-only | |
1391 "%" | |
1392 " ")) | |
1393 | |
1394 (define-ibuffer-column modified (:name "M" :inline t) | |
1395 (if (buffer-modified-p) | |
1396 (string ibuffer-modified-char) | |
1397 " ")) | |
1398 | |
1399 (define-ibuffer-column name (:inline t | |
1400 :props | |
1401 ('mouse-face 'highlight 'keymap ibuffer-name-map | |
1402 'ibuffer-name-column t | |
1403 'help-echo "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer")) | |
1404 (buffer-name)) | |
1405 | |
1406 (define-ibuffer-column size (:inline t) | |
1407 (format "%s" (buffer-size))) | |
1408 | |
1409 (define-ibuffer-column mode (:inline t | |
1410 :props | |
1411 ('mouse-face 'highlight | |
1412 'keymap ibuffer-mode-name-map | |
1413 'help-echo "mouse-2: filter by this mode")) | |
1414 (format "%s" mode-name)) | |
1415 | |
1416 (define-ibuffer-column process () | |
1417 (let ((proc (get-buffer-process buffer))) | |
1418 (format "%s" (if proc | |
1419 (list proc (process-status proc)) | |
1420 "none")))) | |
1421 | |
1422 (define-ibuffer-column filename () | |
1423 (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist)) | |
1424 (abbreviate-file-name | |
1425 (or buffer-file-name | |
1426 (and (boundp 'dired-directory) | |
1427 dired-directory) | |
1428 "")))) | |
1429 | |
1430 (defun ibuffer-format-column (str width alignment) | |
1431 (let ((left (make-string (/ width 2) ? )) | |
1432 (right (make-string (- width (/ width 2)) ? ))) | |
1433 (case alignment | |
1434 (:right (concat left right str)) | |
1435 (:center (concat left str right)) | |
1436 (t (concat str left right))))) | |
1437 | |
1438 (defun ibuffer-fontify-region-function (beg end &optional verbose) | |
1439 (when verbose (message "Fontifying...")) | |
1440 (let ((inhibit-read-only t)) | |
1441 (save-excursion | |
1442 (goto-char beg) | |
1443 (beginning-of-line) | |
1444 (while (< (point) end) | |
1445 (if (get-text-property (point) 'ibuffer-title-header) | |
1446 (put-text-property (point) (line-end-position) 'face ibuffer-title-face) | |
1447 (unless (get-text-property (point) 'ibuffer-title) | |
1448 (multiple-value-bind (buf mark) | |
1449 (get-text-property (point) 'ibuffer-properties) | |
1450 (let* ((namebeg (next-single-property-change (point) 'ibuffer-name-column | |
1451 nil (line-end-position))) | |
1452 (nameend (next-single-property-change namebeg 'ibuffer-name-column | |
1453 nil (line-end-position)))) | |
1454 (put-text-property namebeg | |
1455 nameend | |
1456 'face | |
1457 (cond ((char-equal mark ibuffer-marked-char) | |
1458 ibuffer-marked-face) | |
1459 ((char-equal mark ibuffer-deletion-char) | |
1460 ibuffer-deletion-face) | |
1461 (t | |
1462 (let ((level -1) | |
1463 result) | |
1464 (dolist (e ibuffer-fontification-alist result) | |
1465 (when (and (> (car e) level) | |
1466 (with-current-buffer buf | |
1467 (eval (cadr e)))) | |
1468 (setq level (car e) | |
1469 result | |
1470 (if (symbolp (caddr e)) | |
1471 (if (facep (caddr e)) | |
1472 (caddr e) | |
1473 (symbol-value (caddr e))))))))))))))) | |
1474 (forward-line 1)))) | |
1475 (when verbose (message "Fontifying...done"))) | |
1476 | |
1477 (defun ibuffer-unfontify-region-function (beg end) | |
1478 (let ((inhibit-read-only t)) | |
1479 (remove-text-properties beg end '(face nil)))) | |
1480 | |
1481 (defun ibuffer-insert-buffer-line (buffer mark format) | |
1482 "Insert a line describing BUFFER and MARK using FORMAT." | |
1483 (assert (eq major-mode 'ibuffer-mode)) | |
1484 (let ((beg (point))) | |
1485 ;; Here we inhibit `syntax-ppss-after-change-function' and other | |
1486 ;; things font-lock uses. Otherwise, updating is slowed down dramatically. | |
1487 (funcall format buffer mark) | |
1488 (put-text-property beg (point) 'ibuffer-properties (list buffer mark)) | |
1489 (insert "\n") | |
1490 (goto-char beg))) | |
1491 | |
1492 (defun ibuffer-redisplay-current () | |
1493 (assert (eq major-mode 'ibuffer-mode)) | |
1494 (when (eobp) | |
1495 (forward-line -1)) | |
1496 (beginning-of-line) | |
1497 (let ((buf (ibuffer-current-buffer))) | |
1498 (when buf | |
1499 (let ((mark (ibuffer-current-mark))) | |
1500 (delete-region (point) (1+ (line-end-position))) | |
1501 (ibuffer-insert-buffer-line | |
1502 buf mark | |
1503 (ibuffer-current-format)) | |
1504 (when ibuffer-shrink-to-minimum-size | |
1505 (ibuffer-shrink-to-fit)))))) | |
1506 | |
1507 (defun ibuffer-map-on-mark (mark func) | |
1508 (ibuffer-map-lines | |
1509 #'(lambda (buf mk beg end) | |
1510 (if (char-equal mark mk) | |
1511 (funcall func buf mark beg end) | |
1512 nil)))) | |
1513 | |
1514 (defun ibuffer-map-lines (function &optional nomodify) | |
1515 "Call FUNCTION for each buffer in an ibuffer. | |
1516 Don't set the ibuffer modification flag iff NOMODIFY is non-nil. | |
1517 | |
1518 FUNCTION is called with four arguments: the buffer object itself, the | |
1519 current mark symbol, and the beginning and ending line positions." | |
1520 (assert (eq major-mode 'ibuffer-mode)) | |
1521 (let ((curline (count-lines (point-min) | |
1522 (line-beginning-position))) | |
1523 (deleted-lines-count 0) | |
1524 (ibuffer-map-lines-total 0) | |
1525 (ibuffer-map-lines-count 0)) | |
1526 (unwind-protect | |
1527 (progn | |
1528 (setq buffer-read-only nil) | |
1529 (goto-char (point-min)) | |
1530 (while (and (get-text-property (point) 'ibuffer-title) | |
1531 (not (eobp))) | |
1532 (forward-line 1)) | |
1533 (while (not (eobp)) | |
1534 (let ((result | |
1535 (if (buffer-live-p (ibuffer-current-buffer)) | |
1536 (save-excursion | |
1537 (funcall function | |
1538 (ibuffer-current-buffer) | |
1539 (ibuffer-current-mark) | |
1540 (line-beginning-position) | |
1541 (1+ (line-end-position)))) | |
1542 ;; Kill the line if the buffer is dead | |
1543 'kill))) | |
1544 ;; A given mapping function should return: | |
1545 ;; `nil' if it chose not to affect the buffer | |
1546 ;; `kill' means the remove line from the buffer list | |
1547 ;; `t' otherwise | |
1548 (incf ibuffer-map-lines-total) | |
1549 (cond ((null result) | |
1550 (forward-line 1)) | |
1551 ((eq result 'kill) | |
1552 (delete-region (line-beginning-position) | |
1553 (1+ (line-end-position))) | |
1554 (incf deleted-lines-count) | |
1555 (incf ibuffer-map-lines-count)) | |
1556 (t | |
1557 (incf ibuffer-map-lines-count) | |
1558 (forward-line 1))))) | |
1559 ibuffer-map-lines-count) | |
1560 (progn | |
1561 (setq buffer-read-only t) | |
1562 (unless nomodify | |
1563 (set-buffer-modified-p nil)) | |
1564 (goto-line (- (1+ curline) deleted-lines-count)))))) | |
1565 | |
1566 (defun ibuffer-get-marked-buffers () | |
1567 "Return a list of buffer objects currently marked." | |
1568 (delq nil | |
1569 (mapcar #'(lambda (e) | |
1570 (when (eq (cdr e) ibuffer-marked-char) | |
1571 (car e))) | |
1572 (ibuffer-current-state-list)))) | |
1573 | |
1574 (defun ibuffer-current-state-list (&optional include-lines) | |
1575 "Return a list like (BUF . MARK) of all buffers in an ibuffer. | |
1576 If optional argument INCLUDE-LINES is non-nil, return a list like | |
1577 (BUF MARK BEGPOS)." | |
1578 (let ((ibuffer-current-state-list-tmp '())) | |
1579 ;; ah, if only we had closures. I bet this will mysteriously | |
1580 ;; break later. Don't blame me. | |
1581 (ibuffer-map-lines-nomodify | |
1582 (if include-lines | |
1583 #'(lambda (buf mark beg end) | |
1584 (when (buffer-live-p buf) | |
1585 (push (list buf mark beg) ibuffer-current-state-list-tmp))) | |
1586 #'(lambda (buf mark beg end) | |
1587 (when (buffer-live-p buf) | |
1588 (push (cons buf mark) ibuffer-current-state-list-tmp))))) | |
1589 (nreverse ibuffer-current-state-list-tmp))) | |
1590 | |
1591 (defsubst ibuffer-canonicalize-state-list (bmarklist) | |
1592 "Order BMARKLIST in the same way as the current buffer list." | |
1593 (delq nil | |
1594 (mapcar #'(lambda (buf) (assq buf bmarklist)) (buffer-list)))) | |
1595 | |
1596 (defun ibuffer-current-buffers-with-marks () | |
1597 "Return a list like (BUF . MARK) of all open buffers." | |
1598 (let ((bufs (ibuffer-current-state-list))) | |
1599 (mapcar #'(lambda (buf) (let ((e (assq buf bufs))) | |
1600 (if e | |
1601 e | |
1602 (cons buf ? )))) | |
1603 (buffer-list)))) | |
1604 | |
1605 (defun ibuffer-buf-matches-predicates (buf predicates) | |
1606 (let ((hit nil) | |
1607 (name (buffer-name buf))) | |
1608 (dolist (pred predicates) | |
1609 (when (if (stringp pred) | |
1610 (string-match pred name) | |
1611 (funcall pred buf)) | |
1612 (setq hit t))) | |
1613 hit)) | |
1614 | |
1615 (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all) | |
1616 (let ((ext-loaded (featurep 'ibuf-ext))) | |
1617 (delq nil | |
1618 (mapcar | |
1619 ;; element should be like (BUFFER . MARK) | |
1620 #'(lambda (e) | |
1621 (let* ((buf (car e))) | |
1622 (when | |
1623 ;; This takes precedence over anything else | |
1624 (or (and ibuffer-always-show-last-buffer | |
1625 (eq last buf)) | |
1626 (funcall (if ext-loaded | |
1627 #'ibuffer-ext-visible-p | |
1628 #'ibuffer-visible-p) | |
1629 buf all ibuffer-buf)) | |
1630 e))) | |
1631 bmarklist)))) | |
1632 | |
1633 (defun ibuffer-visible-p (buf all &optional ibuffer-buf) | |
1634 (and (or all | |
1635 (not | |
1636 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates))) | |
1637 (or ibuffer-view-ibuffer | |
1638 (and ibuffer-buf | |
1639 (not (eq ibuffer-buf buf)))))) | |
1640 | |
1641 ;; This function is a special case; it's not defined by | |
1642 ;; `ibuffer-define-sorter'. | |
1643 (defun ibuffer-do-sort-by-recency () | |
1644 "Sort the buffers by last view time." | |
1645 (interactive) | |
1646 (setq ibuffer-sorting-mode 'recency) | |
1647 (ibuffer-redisplay t)) | |
1648 | |
1649 (defun ibuffer-update-format () | |
1650 (when (null ibuffer-current-format) | |
1651 (setq ibuffer-current-format 0)) | |
1652 (when (null ibuffer-formats) | |
1653 (error "Ibuffer error: no formats!"))) | |
1654 | |
1655 (defun ibuffer-switch-format () | |
1656 "Switch the current display format." | |
1657 (interactive) | |
1658 (assert (eq major-mode 'ibuffer-mode)) | |
1659 (unless (consp ibuffer-formats) | |
1660 (error "Ibuffer error: No formats!")) | |
1661 (setq ibuffer-current-format | |
1662 (if (>= ibuffer-current-format (1- (length ibuffer-formats))) | |
1663 0 | |
1664 (1+ ibuffer-current-format))) | |
1665 (ibuffer-update-format) | |
1666 (ibuffer-redisplay t)) | |
1667 | |
1668 (defun ibuffer-update-title (format) | |
1669 (assert (eq major-mode 'ibuffer-mode)) | |
1670 ;; Don't do funky font-lock stuff here | |
1671 (let ((after-change-functions nil)) | |
1672 (if (get-text-property (point-min) 'ibuffer-title) | |
1673 (delete-region (point-min) | |
1674 (next-single-property-change | |
1675 (point-min) 'ibuffer-title))) | |
1676 (goto-char (point-min)) | |
1677 (put-text-property | |
1678 (point) | |
1679 (progn | |
1680 (let ((opos (point))) | |
1681 ;; Insert the title names. | |
1682 (dolist (element (mapcar #'ibuffer-expand-format-entry format)) | |
1683 (insert | |
1684 (if (stringp element) | |
1685 element | |
1686 (let ((sym (car element)) | |
1687 (min (cadr element)) | |
1688 ;; (max (caddr element)) | |
1689 (align (cadddr element))) | |
1690 ;; Ignore a negative min when we're inserting the title | |
1691 (when (minusp min) | |
1692 (setq min (- min))) | |
1693 (let* ((name (or (get sym 'ibuffer-column-name) | |
1694 (error "Unknown column %s in ibuffer-formats" sym))) | |
1695 (len (length name))) | |
1696 (prog1 | |
1697 (if (< len min) | |
1698 (ibuffer-format-column name | |
1699 (- min len) | |
1700 align) | |
1701 name))))))) | |
1702 (put-text-property opos (point) 'ibuffer-title-header t) | |
1703 (insert "\n") | |
1704 ;; Add the underlines | |
1705 (let ((str (save-excursion | |
1706 (forward-line -1) | |
1707 (beginning-of-line) | |
1708 (buffer-substring (point) (line-end-position))))) | |
1709 (apply #'insert (mapcar | |
1710 #'(lambda (c) | |
1711 (if (not (or (char-equal c ? ) | |
1712 (char-equal c ?\n))) | |
1713 ?- | |
1714 ? )) | |
1715 str))) | |
1716 (insert "\n")) | |
1717 (point)) | |
1718 'ibuffer-title t))) | |
1719 | |
1720 (defun ibuffer-update-mode-name () | |
1721 (setq mode-name (format "Ibuffer by %s" (if ibuffer-sorting-mode | |
1722 ibuffer-sorting-mode | |
1723 "recency"))) | |
1724 (when ibuffer-sorting-reversep | |
1725 (setq mode-name (concat mode-name " [rev]"))) | |
1726 (when (and (featurep 'ibuf-ext) | |
1727 ibuffer-auto-mode) | |
1728 (setq mode-name (concat mode-name " (Auto)"))) | |
1729 (let ((result "")) | |
1730 (when (featurep 'ibuf-ext) | |
1731 (dolist (qualifier ibuffer-filtering-qualifiers) | |
1732 (setq result | |
1733 (concat result (ibuffer-format-qualifier qualifier)))) | |
1734 (if ibuffer-use-header-line | |
1735 (setq header-line-format | |
1736 (when ibuffer-filtering-qualifiers | |
1737 (replace-regexp-in-string "%" "%%" | |
1738 (concat mode-name result)))) | |
1739 (progn | |
1740 (setq mode-name (concat mode-name result)) | |
1741 (when (boundp 'header-line-format) | |
1742 (setq header-line-format nil))))))) | |
1743 | |
1744 (defun ibuffer-redisplay (&optional silent) | |
1745 "Redisplay the current list of buffers. | |
1746 | |
1747 This does not show new buffers; use `ibuffer-update' for that. | |
1748 | |
1749 If SILENT is non-`nil', do not generate progress messages." | |
1750 (interactive) | |
1751 (unless silent | |
1752 (message "Redisplaying current buffer list...")) | |
1753 (let ((blist (ibuffer-current-state-list))) | |
1754 (when (null blist) | |
1755 (if (and (featurep 'ibuf-ext) | |
1756 ibuffer-filtering-qualifiers) | |
1757 (message "No buffers! (note: filtering in effect)") | |
1758 (error "No buffers!"))) | |
1759 (ibuffer-insert-buffers-and-marks blist t) | |
1760 (ibuffer-update-mode-name) | |
1761 (unless silent | |
1762 (message "Redisplaying current buffer list...done")))) | |
1763 | |
1764 (defun ibuffer-update (arg &optional silent) | |
1765 "Regenerate the list of all buffers. | |
1766 | |
1767 Display buffers whose name matches one of `ibuffer-maybe-show-predicates' | |
1768 iff arg ARG is non-nil. | |
1769 | |
1770 Do not display messages if SILENT is non-nil." | |
1771 (interactive "P") | |
1772 (let* ((bufs (buffer-list)) | |
1773 (blist (ibuffer-filter-buffers | |
1774 (current-buffer) | |
1775 (if (and | |
1776 (cadr bufs) | |
1777 (eq ibuffer-always-show-last-buffer | |
1778 :nomini) | |
1779 ;; This is a hack. | |
1780 (string-match " \\*Minibuf" | |
1781 (buffer-name (cadr bufs)))) | |
1782 (caddr bufs) | |
1783 (cadr bufs)) | |
1784 (ibuffer-current-buffers-with-marks) | |
1785 arg))) | |
1786 (when (null blist) | |
1787 (if (and (featurep 'ibuf-ext) | |
1788 ibuffer-filtering-qualifiers) | |
1789 (message "No buffers! (note: filtering in effect)") | |
1790 (error "No buffers!"))) | |
1791 (unless silent | |
1792 (message "Updating buffer list...")) | |
1793 (ibuffer-insert-buffers-and-marks blist | |
1794 arg) | |
1795 (ibuffer-update-mode-name) | |
1796 (unless silent | |
1797 (message "Updating buffer list...done"))) | |
1798 (if (eq ibuffer-shrink-to-minimum-size 'onewindow) | |
1799 (ibuffer-shrink-to-fit t) | |
1800 (when ibuffer-shrink-to-minimum-size | |
1801 (ibuffer-shrink-to-fit))) | |
1802 (ibuffer-forward-line 0)) | |
1803 | |
1804 (defun ibuffer-insert-buffers-and-marks (bmarklist &optional all) | |
1805 (assert (eq major-mode 'ibuffer-mode)) | |
1806 (let ((--ibuffer-insert-buffers-and-marks-format | |
1807 (ibuffer-current-format)) | |
1808 (orig (count-lines (point-min) (point))) | |
1809 ;; Inhibit font-lock caching tricks, since we're modifying the | |
1810 ;; entire buffer at once | |
1811 (after-change-functions nil)) | |
1812 (unwind-protect | |
1813 (progn | |
1814 (setq buffer-read-only nil) | |
1815 (erase-buffer) | |
1816 (ibuffer-update-format) | |
1817 (let ((entries | |
1818 (let* ((sortdat (assq ibuffer-sorting-mode | |
1819 ibuffer-sorting-functions-alist)) | |
1820 (func (caddr sortdat))) | |
1821 (let ((result | |
1822 ;; actually sort the buffers | |
1823 (if (and sortdat func) | |
1824 (sort bmarklist func) | |
1825 bmarklist))) | |
1826 ;; perhaps reverse the sorted buffer list | |
1827 (if ibuffer-sorting-reversep | |
1828 result | |
1829 (nreverse result)))))) | |
1830 (dolist (entry entries) | |
1831 (ibuffer-insert-buffer-line | |
1832 (car entry) | |
1833 (cdr entry) | |
1834 --ibuffer-insert-buffers-and-marks-format))) | |
1835 (ibuffer-update-title (nth ibuffer-current-format ibuffer-formats))) | |
1836 (setq buffer-read-only t) | |
1837 (set-buffer-modified-p ibuffer-did-modification) | |
1838 (setq ibuffer-did-modification nil) | |
1839 (goto-line (1+ orig))))) | |
1840 | |
1841 (defun ibuffer-quit () | |
1842 "Quit this `ibuffer' session. | |
1843 Delete the current window iff `ibuffer-delete-window-on-quit' is non-nil." | |
1844 (interactive) | |
1845 (if ibuffer-delete-window-on-quit | |
1846 (progn | |
1847 (bury-buffer) | |
1848 (unless (= (count-windows) 1) | |
1849 (delete-window))) | |
1850 (bury-buffer))) | |
1851 | |
1852 ;;;###autoload | |
1853 (defun ibuffer-list-buffers (&optional files-only) | |
1854 "Display a list of buffers, in another window. | |
1855 If optional argument FILES-ONLY is non-nil, then add a filter for | |
1856 buffers which are visiting a file." | |
1857 (interactive "P") | |
1858 (ibuffer t nil (when files-only | |
1859 '((filename . ".*"))) t)) | |
1860 | |
1861 ;;;###autoload | |
1862 (defun ibuffer-other-window (&optional files-only) | |
1863 "Like `ibuffer', but displayed in another window by default. | |
1864 If optional argument FILES-ONLY is non-nil, then add a filter for | |
1865 buffers which are visiting a file." | |
1866 (interactive "P") | |
1867 (ibuffer t nil (when files-only | |
1868 '((filename . ".*"))))) | |
1869 | |
1870 ;;;###autoload | |
1871 (defun ibuffer (&optional other-window-p name qualifiers noselect shrink) | |
1872 "Begin using `ibuffer' to edit a list of buffers. | |
1873 Type 'h' after entering ibuffer for more information. | |
1874 | |
1875 Optional argument OTHER-WINDOW-P says to use another window. | |
1876 Optional argument NAME specifies the name of the buffer; it defaults | |
1877 to \"*Ibuffer*\". | |
1878 Optional argument QUALIFIERS is an initial set of filtering qualifiers | |
1879 to use; see `ibuffer-filtering-qualifiers'. | |
1880 Optional argument NOSELECT means don't select the Ibuffer buffer. | |
1881 Optional argument SHRINK means shrink the buffer to minimal size. The | |
1882 special value `onewindow' means always use another window." | |
1883 (interactive "P") | |
42884
5abd84afe99c
Don't require ibuf-ext at load time.
Richard M. Stallman <rms@gnu.org>
parents:
42873
diff
changeset
|
1884 |
5abd84afe99c
Don't require ibuf-ext at load time.
Richard M. Stallman <rms@gnu.org>
parents:
42873
diff
changeset
|
1885 ;; The individual functions are lazy-loaded, via byte-compile-dynamic, |
5abd84afe99c
Don't require ibuf-ext at load time.
Richard M. Stallman <rms@gnu.org>
parents:
42873
diff
changeset
|
1886 ;; so we may as well load the file unconditionally now. |
5abd84afe99c
Don't require ibuf-ext at load time.
Richard M. Stallman <rms@gnu.org>
parents:
42873
diff
changeset
|
1887 (require 'ibuf-ext) |
5abd84afe99c
Don't require ibuf-ext at load time.
Richard M. Stallman <rms@gnu.org>
parents:
42873
diff
changeset
|
1888 |
42702 | 1889 (when ibuffer-use-other-window |
1890 (setq other-window-p (not other-window-p))) | |
1891 (let* ((buf (get-buffer-create (or name "*Ibuffer*"))) | |
1892 (already-in (eq (current-buffer) buf)) | |
1893 (need-update nil)) | |
1894 (if other-window-p | |
1895 (funcall (if noselect #'(lambda (buf) (display-buffer buf t)) #'pop-to-buffer) buf) | |
1896 (funcall (if noselect #'display-buffer #'switch-to-buffer) buf)) | |
1897 (with-current-buffer buf | |
1898 (let ((owin (selected-window))) | |
1899 (unwind-protect | |
1900 (progn | |
1901 ;; We switch to the buffer's window in order to be able | |
1902 ;; to modify the value of point | |
1903 (select-window (get-buffer-window buf)) | |
1904 (unless (eq major-mode 'ibuffer-mode) | |
1905 (ibuffer-mode) | |
1906 (setq need-update t)) | |
1907 (when (ibuffer-use-fontification) | |
1908 (require 'font-lock)) | |
1909 (setq ibuffer-delete-window-on-quit other-window-p) | |
1910 (when shrink | |
1911 (setq ibuffer-shrink-to-minimum-size shrink)) | |
1912 (when qualifiers | |
1913 (setq ibuffer-filtering-qualifiers qualifiers)) | |
1914 (ibuffer-update nil) | |
1915 (unwind-protect | |
1916 (progn | |
1917 (setq buffer-read-only nil) | |
1918 (run-hooks 'ibuffer-hooks)) | |
1919 (setq buffer-read-only t)) | |
1920 (unless ibuffer-expert | |
1921 (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))) | |
1922 (select-window owin)))))) | |
1923 | |
1924 (defun ibuffer-mode () | |
1925 "A major mode for viewing a list of buffers. | |
1926 In ibuffer, you can conveniently perform many operations on the | |
1927 currently open buffers, in addition to filtering your view to a | |
1928 particular subset of them, and sorting by various criteria. | |
1929 | |
1930 Operations on marked buffers: | |
1931 | |
1932 '\\[ibuffer-do-save]' - Save the marked buffers | |
1933 '\\[ibuffer-do-view]' - View the marked buffers in this frame. | |
1934 '\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame. | |
1935 '\\[ibuffer-do-revert]' - Revert the marked buffers. | |
1936 '\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers. | |
1937 '\\[ibuffer-do-delete]' - Kill the marked buffers. | |
1938 '\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked | |
1939 buffers. | |
1940 '\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers. | |
1941 '\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression. | |
1942 '\\[ibuffer-do-print]' - Print the marked buffers. | |
1943 '\\[ibuffer-do-occur]' - List lines in all marked buffers which match | |
1944 a given regexp (like the function `occur'). | |
1945 '\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked | |
1946 buffers to a shell command. | |
1947 '\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked | |
1948 buffers with the output of a shell command. | |
1949 '\\[ibuffer-do-shell-command-file]' - Run a shell command with the | |
1950 buffer's file as an argument. | |
1951 '\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This | |
1952 is a very flexible command. For example, if you want to make all | |
1953 of the marked buffers read only, try using (toggle-read-only 1) as | |
1954 the input form. | |
1955 '\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form | |
1956 is evaluated. | |
1957 '\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer, | |
1958 but don't kill the associated buffer. | |
1959 '\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion. | |
1960 | |
1961 Marking commands: | |
1962 | |
1963 '\\[ibuffer-mark-forward]' - Mark the buffer at point. | |
1964 '\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark | |
1965 all unmarked buffers. | |
1966 '\\[ibuffer-unmark-forward]' - Unmark the buffer at point. | |
1967 '\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the | |
1968 previous line. | |
1969 '\\[ibuffer-unmark-all]' - Unmark all marked buffers. | |
1970 '\\[ibuffer-mark-by-mode]' - Mark buffers by major mode. | |
1971 '\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers. | |
1972 This means that the buffer is modified, and has an associated file. | |
1973 '\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers, | |
1974 regardless of whether or not they have an associated file. | |
1975 '\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and | |
1976 ends with '*'. | |
1977 '\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have | |
1978 an associated file, but that file doesn't currently exist. | |
1979 '\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers. | |
1980 '\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode. | |
1981 '\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc. | |
1982 '\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'. | |
1983 '\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion. | |
1984 '\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp. | |
1985 '\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp. | |
1986 '\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp. | |
1987 | |
1988 Filtering commands: | |
1989 | |
1990 '\\[ibuffer-filter-by-mode]' - Add a filter by major mode. | |
1991 '\\[ibuffer-filter-by-name]' - Add a filter by buffer name. | |
1992 '\\[ibuffer-filter-by-content]' - Add a filter by buffer content. | |
1993 '\\[ibuffer-filter-by-filename]' - Add a filter by filename. | |
1994 '\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size. | |
1995 '\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size. | |
1996 '\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate. | |
1997 '\\[ibuffer-save-filters]' - Save the current filters with a name. | |
1998 '\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters. | |
1999 '\\[ibuffer-add-saved-filters]' - Add saved filters to current filters. | |
2000 '\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR. | |
2001 '\\[ibuffer-pop-filter]' - Remove the top filter. | |
2002 '\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter. | |
2003 '\\[ibuffer-decompose-filter]' - Break down the topmost filter. | |
2004 '\\[ibuffer-filter-disable]' - Remove all filtering currently in effect. | |
2005 | |
2006 Sorting commands: | |
2007 | |
2008 '\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes. | |
2009 '\\[ibuffer-invert-sorting]' - Reverse the current sorting order. | |
2010 '\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically. | |
2011 '\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time. | |
2012 '\\[ibuffer-do-sort-by-size]' - Sort the buffers by size. | |
2013 '\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode. | |
2014 | |
2015 Other commands: | |
2016 | |
2017 '\\[ibuffer-switch-format]' - Change the current display format. | |
2018 '\\[forward-line]' - Move point to the next line. | |
2019 '\\[previous-line]' - Move point to the previous line. | |
2020 '\\[ibuffer-update]' - As above, but add new buffers to the list. | |
2021 '\\[ibuffer-quit]' - Bury the Ibuffer buffer. | |
2022 '\\[describe-mode]' - This help. | |
2023 '\\[ibuffer-diff-with-file]' - View the differences between this buffer | |
2024 and its associated file. | |
2025 '\\[ibuffer-visit-buffer]' - View the buffer on this line. | |
2026 '\\[ibuffer-visit-buffer-other-window]' - As above, but in another window. | |
2027 '\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select | |
2028 the new window. | |
2029 '\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line. | |
2030 | |
2031 Information on Filtering: | |
2032 | |
2033 You can filter your ibuffer view via different critera. Each Ibuffer | |
2034 buffer has its own stack of active filters. For example, suppose you | |
2035 are working on an Emacs Lisp project. You can create an Ibuffer | |
2036 buffer displays buffers in just `emacs-lisp' modes via | |
2037 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there | |
2038 is just one entry on the filtering stack. | |
2039 | |
2040 You can also combine filters. The various filtering commands push a | |
2041 new filter onto the stack, and the filters combine to show just | |
2042 buffers which satisfy ALL criteria on the stack. For example, suppose | |
2043 you only want to see buffers in `emacs-lisp' mode, whose names begin | |
2044 with \"gnus\". You can accomplish this via: | |
2045 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET | |
2046 \\[ibuffer-filter-by-name] ^gnus RET'. | |
2047 | |
2048 Additionally, you can OR the top two filters together with | |
2049 '\\[ibuffer-or-filters]'. To see all buffers in either | |
2050 `emacs-lisp-mode' or `lisp-interaction-mode', type: | |
2051 | |
2052 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filter-by-mode] lisp-interaction-mode RET \\[ibuffer-or-filters]'. | |
2053 | |
2054 Filters can also be saved and restored using mnemonic names: see the | |
2055 functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'. | |
2056 | |
2057 To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and | |
2058 to disable all filtering currently in effect, use | |
2059 '\\[ibuffer-filter-disable]'." | |
2060 (kill-all-local-variables) | |
2061 (use-local-map ibuffer-mode-map) | |
2062 (setq major-mode 'ibuffer-mode) | |
2063 (setq mode-name "Ibuffer") | |
2064 (setq buffer-read-only t) | |
2065 (buffer-disable-undo) | |
2066 (setq truncate-lines t) | |
2067 ;; This makes things less ugly for Emacs 21 users with a non-nil | |
2068 ;; `show-trailing-whitespace'. | |
2069 (setq show-trailing-whitespace nil) | |
2070 ;; Dummy font-lock-defaults to make font-lock turn on. We want this | |
2071 ;; so we know when to enable ibuffer's internal fontification. | |
2072 (set (make-local-variable 'font-lock-defaults) | |
2073 '(nil t nil nil nil | |
2074 (font-lock-fontify-region-function . ibuffer-fontify-region-function) | |
2075 (font-lock-unfontify-region-function . ibuffer-unfontify-region-function))) | |
2076 (set (make-local-variable 'revert-buffer-function) | |
2077 #'ibuffer-update) | |
2078 (set (make-local-variable 'ibuffer-sorting-mode) | |
2079 ibuffer-default-sorting-mode) | |
2080 (set (make-local-variable 'ibuffer-sorting-reversep) | |
2081 ibuffer-default-sorting-reversep) | |
2082 (set (make-local-variable 'ibuffer-shrink-to-minimum-size) | |
2083 ibuffer-default-shrink-to-minimum-size) | |
2084 (set (make-local-variable 'ibuffer-filtering-qualifiers) nil) | |
2085 (set (make-local-variable 'ibuffer-compiled-formats) nil) | |
2086 (set (make-local-variable 'ibuffer-cached-formats) nil) | |
2087 (set (make-local-variable 'ibuffer-cached-eliding-string) nil) | |
2088 (set (make-local-variable 'ibuffer-cached-elide-long-columns) nil) | |
2089 (set (make-local-variable 'ibuffer-current-format) nil) | |
2090 (set (make-local-variable 'ibuffer-did-modifiction) nil) | |
2091 (set (make-local-variable 'ibuffer-delete-window-on-quit) nil) | |
2092 (set (make-local-variable 'ibuffer-did-modification) nil) | |
2093 (when (featurep 'ibuf-ext) | |
2094 (set (make-local-variable 'ibuffer-tmp-hide-regexps) nil) | |
2095 (set (make-local-variable 'ibuffer-tmp-show-regexps) nil)) | |
2096 (define-key ibuffer-mode-map [menu-bar edit] 'undefined) | |
2097 (define-key ibuffer-mode-map [menu-bar operate] (cons "Operate" ibuffer-mode-operate-map)) | |
2098 (ibuffer-update-format) | |
2099 (when ibuffer-default-directory | |
2100 (setq default-directory ibuffer-default-directory)) | |
2101 (run-hooks 'ibuffer-mode-hooks) | |
2102 ;; called after mode hooks to allow the user to add filters | |
2103 (ibuffer-update-mode-name)) | |
2104 | |
2105 (provide 'ibuffer) | |
2106 | |
2107 ;; Local Variables: | |
2108 ;; coding: iso-8859-1 | |
2109 ;; End: | |
2110 | |
2111 ;;; ibuffer.el ends here |