Commit | Line | Data |
---|---|---|
25d2f683 CW |
1 | ;;; ibuffer.el --- operate on buffers like dired |
2 | ||
0d30b337 | 3 | ;; Copyright (C) 2000, 2001, 2002, 2003, 2004, |
409cc4a3 | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
25d2f683 CW |
5 | |
6 | ;; Author: Colin Walters <walters@verbum.org> | |
4e4a724c | 7 | ;; Maintainer: John Paul Wallington <jpw@gnu.org> |
25d2f683 | 8 | ;; Created: 8 Sep 2000 |
25d2f683 | 9 | ;; Keywords: buffer, convenience |
25d2f683 | 10 | |
b5cd37ea | 11 | ;; This file is part of GNU Emacs. |
25d2f683 | 12 | |
eb3fa2cf GM |
13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
14 | ;; it under the terms of the GNU General Public License as published by | |
15 | ;; the Free Software Foundation, either version 3 of the License, or | |
16 | ;; (at your option) any later version. | |
25d2f683 | 17 | |
eb3fa2cf GM |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
25d2f683 CW |
22 | |
23 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
25d2f683 CW |
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 | ||
730da5b2 | 39 | (require 'font-core) |
fd225d80 | 40 | |
735d7026 JB |
41 | ;; These come from ibuf-ext.el, which can not be require'd at compile time |
42 | ;; because it has a recursive dependency on ibuffer.el | |
43 | (defvar ibuffer-auto-mode) | |
44 | (defvar ibuffer-cached-filter-formats) | |
45 | (defvar ibuffer-compiled-filter-formats) | |
46 | (defvar ibuffer-filter-format-alist) | |
47 | (defvar ibuffer-filter-group-kill-ring) | |
48 | (defvar ibuffer-filter-groups) | |
49 | (defvar ibuffer-filtering-qualifiers) | |
6d11a78b | 50 | (defvar ibuffer-header-line-format) |
735d7026 JB |
51 | (defvar ibuffer-hidden-filter-groups) |
52 | (defvar ibuffer-inline-columns) | |
53 | (defvar ibuffer-show-empty-filter-groups) | |
54 | (defvar ibuffer-tmp-hide-regexps) | |
55 | (defvar ibuffer-tmp-show-regexps) | |
63f0a166 | 56 | |
004a00f4 DN |
57 | (declare-function ibuffer-mark-on-buffer "ibuf-ext" |
58 | (func &optional ibuffer-mark-on-buffer-mark group)) | |
59 | (declare-function ibuffer-format-qualifier "ibuf-ext" (qualifier)) | |
60 | (declare-function ibuffer-generate-filter-groups "ibuf-ext" | |
61 | (bmarklist &optional noempty nodefault)) | |
62 | (declare-function ibuffer-format-filter-group-data "ibuf-ext" (filter)) | |
63 | ||
25d2f683 CW |
64 | (defgroup ibuffer nil |
65 | "An advanced replacement for `buffer-menu'. | |
66 | ||
67 | Ibuffer allows you to operate on buffers in a manner much like Dired. | |
68 | Operations include sorting, marking by regular expression, and | |
69 | the ability to filter the displayed buffers by various criteria." | |
bf247b6e | 70 | :version "22.1" |
25d2f683 CW |
71 | :group 'convenience) |
72 | ||
ac3c7293 JPW |
73 | (defcustom ibuffer-formats '((mark modified read-only " " (name 18 18 :left :elide) |
74 | " " (size 9 -1 :right) | |
b9debd54 | 75 | " " (mode 16 16 :left :elide) " " filename-and-process) |
25d2f683 CW |
76 | (mark " " (name 16 -1) " " filename)) |
77 | "A list of ways to display buffer lines. | |
78 | ||
79 | With Ibuffer, you are not limited to displaying just certain | |
80 | attributes of a buffer such as size, name, and mode in a particular | |
cba63a2d | 81 | order. Through this variable, you can completely customize and |
25d2f683 CW |
82 | control the appearance of an Ibuffer buffer. See also |
83 | `define-ibuffer-column', which allows you to define your own columns | |
84 | for display. | |
85 | ||
86 | This variable has the form | |
2e4fae7d | 87 | ((COLUMN COLUMN ...) (COLUMN COLUMN ...) ...) |
25d2f683 CW |
88 | Each element in `ibuffer-formats' should be a list containing COLUMN |
89 | specifiers. A COLUMN can be any of the following: | |
90 | ||
91 | SYMBOL - A symbol naming the column. Predefined columns are: | |
92 | mark modified read-only name size mode process filename | |
93 | When you define your own columns using `define-ibuffer-column', just | |
94 | use their name like the predefined columns here. This entry can | |
95 | also be a function of two arguments, which should return a string. | |
96 | The first argument is the buffer object, and the second is the mark | |
97 | on that buffer. | |
98 | or | |
99 | \"STRING\" - A literal string to display. | |
100 | or | |
101 | (SYMBOL MIN-SIZE MAX-SIZE &optional ALIGN ELIDE) - SYMBOL is a | |
102 | symbol naming the column, and MIN-SIZE and MAX-SIZE are integers (or | |
103 | functions of no arguments returning an integer) which constrict the | |
104 | size of a column. If MAX-SIZE is -1, there is no upper bound. The | |
105 | default values are 0 and -1, respectively. If MIN-SIZE is negative, | |
106 | use the end of the string. The optional element ALIGN describes the | |
107 | alignment of the column; it can be :left, :center or :right. The | |
108 | optional element ELIDE describes whether or not to elide the column | |
109 | if it is too long; valid values are :elide and nil. The default is | |
110 | nil (don't elide). | |
111 | ||
112 | Some example of valid entries in `ibuffer-formats', with | |
113 | description (also, feel free to try them out, and experiment with your | |
114 | own!): | |
115 | ||
116 | (mark \" \" name) | |
117 | This format just displays the current mark (if any) and the name of | |
118 | the buffer, separated by a space. | |
119 | (mark modified read-only \" \" (name 16 16 :left) \" \" (size 6 -1 :right)) | |
120 | This format displays the current mark (if any), its modification and | |
121 | read-only status, as well as the name of the buffer and its size. In | |
122 | this format, the name is restricted to 16 characters (longer names | |
523304ed | 123 | will be truncated, and shorter names will be padded with spaces), and |
cba63a2d | 124 | the name is also aligned to the left. The size of the buffer will |
25d2f683 CW |
125 | be padded with spaces up to a minimum of six characters, but there is |
126 | no upper limit on its size. The size will also be aligned to the | |
127 | right. | |
128 | ||
129 | Thus, if you wanted to use these two formats, add | |
130 | ||
131 | (setq ibuffer-formats '((mark \" \" name) | |
132 | (mark modified read-only | |
133 | (name 16 16 :left) (size 6 -1 :right)))) | |
134 | ||
135 | to your ~/.emacs file. | |
136 | ||
137 | Using \\[ibuffer-switch-format], you can rotate the display between | |
138 | the specified formats in the list." | |
139 | :type '(repeat sexp) | |
140 | :group 'ibuffer) | |
141 | ||
142 | (defcustom ibuffer-always-compile-formats (featurep 'bytecomp) | |
143 | "If non-nil, then use the byte-compiler to optimize `ibuffer-formats'. | |
144 | This will increase the redisplay speed, at the cost of loading the | |
145 | elisp byte-compiler." | |
146 | :type 'boolean | |
147 | :group 'ibuffer) | |
148 | ||
149 | (defcustom ibuffer-fontification-alist | |
40c10465 | 150 | `((10 buffer-read-only font-lock-constant-face) |
9fe14abe JPW |
151 | (15 (and buffer-file-name |
152 | (string-match ibuffer-compressed-file-name-regexp | |
153 | buffer-file-name)) | |
154 | font-lock-doc-face) | |
155 | (20 (string-match "^*" (buffer-name)) font-lock-keyword-face) | |
156 | (25 (and (string-match "^ " (buffer-name)) | |
da337a28 JPW |
157 | (null buffer-file-name)) |
158 | italic) | |
9fe14abe JPW |
159 | (30 (memq major-mode ibuffer-help-buffer-modes) font-lock-comment-face) |
160 | (35 (eq major-mode 'dired-mode) font-lock-function-name-face)) | |
25d2f683 CW |
161 | "An alist describing how to fontify buffers. |
162 | Each element should be of the form (PRIORITY FORM FACE), where | |
163 | PRIORITY is an integer, FORM is an arbitrary form to evaluate in the | |
164 | buffer, and FACE is the face to use for fontification. If the FORM | |
165 | evaluates to non-nil, then FACE will be put on the buffer name. The | |
fd225d80 CW |
166 | element with the highest PRIORITY takes precedence. |
167 | ||
4e4a724c | 168 | If you change this variable, you must kill the Ibuffer buffer and |
fd225d80 | 169 | recreate it for the change to take effect." |
25d2f683 CW |
170 | :type '(repeat |
171 | (list (integer :tag "Priority") | |
172 | (sexp :tag "Test Form") | |
173 | face)) | |
174 | :group 'ibuffer) | |
175 | ||
176 | (defcustom ibuffer-use-other-window nil | |
7ad5b902 | 177 | "If non-nil, display Ibuffer in another window by default." |
25d2f683 CW |
178 | :type 'boolean |
179 | :group 'ibuffer) | |
180 | ||
181 | (defcustom ibuffer-default-shrink-to-minimum-size nil | |
182 | "If non-nil, minimize the size of the Ibuffer window by default." | |
183 | :type 'boolean | |
184 | :group 'ibuffer) | |
185 | (defvar ibuffer-shrink-to-minimum-size nil) | |
186 | ||
0740098c JPW |
187 | (defcustom ibuffer-display-summary t |
188 | "If non-nil, summarize Ibuffer columns." | |
189 | :type 'boolean | |
190 | :group 'ibuffer) | |
191 | ||
3eda3649 CW |
192 | (defcustom ibuffer-truncate-lines t |
193 | "If non-nil, do not display continuation lines." | |
194 | :type 'boolean | |
195 | :group 'ibuffer) | |
196 | ||
25d2f683 CW |
197 | (defcustom ibuffer-case-fold-search case-fold-search |
198 | "If non-nil, ignore case when searching." | |
199 | :type 'boolean | |
200 | :group 'ibuffer) | |
201 | ||
202 | (defcustom ibuffer-default-sorting-mode 'recency | |
203 | "The criteria by which to sort the buffers. | |
204 | ||
4e4a724c JPW |
205 | Note that this variable is local to each Ibuffer buffer. Thus, you |
206 | can have multiple Ibuffer buffers open, each with a different sorted | |
25d2f683 CW |
207 | view of the buffers." |
208 | :type '(choice (const :tag "Last view time" :value recency) | |
209 | (const :tag "Lexicographic" :value alphabetic) | |
210 | (const :tag "Buffer size" :value size) | |
d5794180 | 211 | (const :tag "File name" :value filename/process) |
25d2f683 CW |
212 | (const :tag "Major mode" :value major-mode)) |
213 | :group 'ibuffer) | |
214 | (defvar ibuffer-sorting-mode nil) | |
e7820654 | 215 | (defvar ibuffer-last-sorting-mode nil) |
25d2f683 CW |
216 | |
217 | (defcustom ibuffer-default-sorting-reversep nil | |
218 | "If non-nil, reverse the default sorting order." | |
219 | :type 'boolean | |
220 | :group 'ibuffer) | |
221 | (defvar ibuffer-sorting-reversep nil) | |
222 | ||
223 | (defcustom ibuffer-elide-long-columns nil | |
972b8f82 | 224 | "If non-nil, then elide column entries which exceed their max length." |
25d2f683 CW |
225 | :type 'boolean |
226 | :group 'ibuffer) | |
972b8f82 JB |
227 | (make-obsolete-variable 'ibuffer-elide-long-columns |
228 | "use the :elide argument of `ibuffer-formats'." | |
229 | "22.1") | |
25d2f683 CW |
230 | |
231 | (defcustom ibuffer-eliding-string "..." | |
232 | "The string to use for eliding long columns." | |
233 | :type 'string | |
234 | :group 'ibuffer) | |
235 | ||
236 | (defcustom ibuffer-maybe-show-predicates `(,(lambda (buf) | |
237 | (and (string-match "^ " (buffer-name buf)) | |
238 | (null buffer-file-name)))) | |
4e4a724c JPW |
239 | "A list of predicates for buffers to display conditionally. |
240 | ||
241 | A predicate can be a regexp or a function. | |
25d2f683 CW |
242 | If a regexp, then it will be matched against the buffer's name. |
243 | If a function, it will be called with the buffer as an argument, and | |
244 | should return non-nil if this buffer should be shown. | |
245 | ||
957237cb | 246 | Viewing of buffers hidden because of these predicates may be customized |
bf247b6e | 247 | via `ibuffer-default-display-maybe-show-predicates' and is toggled by |
957237cb JPW |
248 | giving a non-nil prefix argument to `ibuffer-update'. |
249 | Note that this specialized filtering occurs before real filtering." | |
25d2f683 CW |
250 | :type '(repeat (choice regexp function)) |
251 | :group 'ibuffer) | |
252 | ||
957237cb JPW |
253 | (defcustom ibuffer-default-display-maybe-show-predicates nil |
254 | "Non-nil means show buffers that match `ibuffer-maybe-show-predicates'." | |
255 | :type 'boolean | |
256 | :group 'ibuffer) | |
257 | ||
258 | (defvar ibuffer-display-maybe-show-predicates nil) | |
259 | ||
25d2f683 CW |
260 | (defvar ibuffer-current-format nil) |
261 | ||
0ce780e1 CW |
262 | (defcustom ibuffer-movement-cycle t |
263 | "If non-nil, then forward and backwards movement commands cycle." | |
264 | :type 'boolean | |
265 | :group 'ibuffer) | |
266 | ||
25d2f683 CW |
267 | (defcustom ibuffer-modified-char ?* |
268 | "The character to display for modified buffers." | |
269 | :type 'character | |
270 | :group 'ibuffer) | |
271 | ||
272 | (defcustom ibuffer-read-only-char ?% | |
273 | "The character to display for read-only buffers." | |
274 | :type 'character | |
275 | :group 'ibuffer) | |
276 | ||
277 | (defcustom ibuffer-marked-char ?> | |
278 | "The character to display for marked buffers." | |
279 | :type 'character | |
280 | :group 'ibuffer) | |
281 | ||
282 | (defcustom ibuffer-deletion-char ?D | |
283 | "The character to display for buffers marked for deletion." | |
284 | :type 'character | |
285 | :group 'ibuffer) | |
286 | ||
287 | (defcustom ibuffer-expert nil | |
288 | "If non-nil, don't ask for confirmation of \"dangerous\" operations." | |
289 | :type 'boolean | |
290 | :group 'ibuffer) | |
291 | ||
292 | (defcustom ibuffer-view-ibuffer nil | |
293 | "If non-nil, display the current Ibuffer buffer itself. | |
294 | Note that this has a drawback - the data about the current Ibuffer | |
295 | buffer will most likely be inaccurate. This includes modification | |
296 | state, size, etc." | |
297 | :type 'boolean | |
298 | :group 'ibuffer) | |
299 | ||
300 | (defcustom ibuffer-always-show-last-buffer nil | |
4e4a724c JPW |
301 | "If non-nil, always display the previous buffer. |
302 | This variable takes precedence over filtering, and even | |
25d2f683 CW |
303 | `ibuffer-never-show-predicates'." |
304 | :type '(choice (const :tag "Always" :value t) | |
305 | (const :tag "Never" :value nil) | |
306 | (const :tag "Always except minibuffer" :value :nomini)) | |
307 | :group 'ibuffer) | |
308 | ||
0bdd7ae4 JPW |
309 | (defcustom ibuffer-jump-offer-only-visible-buffers nil |
310 | "If non-nil, only offer buffers visible in the Ibuffer buffer | |
311 | in completion lists of the `ibuffer-jump-to-buffer' command." | |
312 | :type 'boolean | |
313 | :group 'ibuffer) | |
314 | ||
25d2f683 | 315 | (defcustom ibuffer-use-header-line (boundp 'header-line-format) |
7ad5b902 | 316 | "If non-nil, display a header line containing current filters." |
25d2f683 CW |
317 | :type 'boolean |
318 | :group 'ibuffer) | |
319 | ||
320 | (defcustom ibuffer-default-directory nil | |
4e4a724c | 321 | "The default directory to use for a new Ibuffer buffer. |
2e4fae7d | 322 | If nil, inherit the directory of the buffer in which `ibuffer' was |
25d2f683 CW |
323 | called. Otherwise, this variable should be a string naming a |
324 | directory, like `default-directory'." | |
325 | :type '(choice (const :tag "Inherit" :value nil) | |
326 | string) | |
327 | :group 'ibuffer) | |
328 | ||
4e4a724c JPW |
329 | (defcustom ibuffer-help-buffer-modes |
330 | '(help-mode apropos-mode Info-mode Info-edit-mode) | |
60356fb5 CW |
331 | "List of \"Help\" major modes." |
332 | :type '(repeat function) | |
333 | :group 'ibuffer) | |
334 | ||
9fe14abe | 335 | (defcustom ibuffer-compressed-file-name-regexp |
fe99056f | 336 | "\\.\\(arj\\|bgz\\|bz2\\|gz\\|lzh\\|taz\\|tgz\\|zip\\|z\\)$" |
9fe14abe JPW |
337 | "Regexp to match compressed file names." |
338 | :type 'regexp | |
c7f5c0a8 | 339 | :group 'ibuffer) |
9fe14abe | 340 | |
cd6ef82d GM |
341 | (define-obsolete-variable-alias 'ibuffer-hooks 'ibuffer-hook "22.1") |
342 | ||
e9e96ba0 | 343 | (defcustom ibuffer-hook nil |
4e4a724c | 344 | "Hook run when `ibuffer' is called." |
25d2f683 CW |
345 | :type 'hook |
346 | :group 'ibuffer) | |
cd6ef82d GM |
347 | |
348 | (define-obsolete-variable-alias 'ibuffer-mode-hooks 'ibuffer-mode-hook "22.1") | |
25d2f683 | 349 | |
e9e96ba0 | 350 | (defcustom ibuffer-mode-hook nil |
4e4a724c | 351 | "Hook run upon entry into `ibuffer-mode'." |
25d2f683 CW |
352 | :type 'hook |
353 | :group 'ibuffer) | |
354 | ||
4e4a724c JPW |
355 | (defcustom ibuffer-load-hook nil |
356 | "Hook run when Ibuffer is loaded." | |
357 | :type 'hook | |
358 | :group 'ibuffer) | |
359 | ||
25d2f683 CW |
360 | (defcustom ibuffer-marked-face 'font-lock-warning-face |
361 | "Face used for displaying marked buffers." | |
362 | :type 'face | |
363 | :group 'ibuffer) | |
364 | ||
365 | (defcustom ibuffer-deletion-face 'font-lock-type-face | |
366 | "Face used for displaying buffers marked for deletion." | |
367 | :type 'face | |
368 | :group 'ibuffer) | |
369 | ||
370 | (defcustom ibuffer-title-face 'font-lock-type-face | |
371 | "Face used for the title string." | |
372 | :type 'face | |
373 | :group 'ibuffer) | |
374 | ||
b5cd37ea CW |
375 | (defcustom ibuffer-filter-group-name-face 'bold |
376 | "Face used for displaying filtering group names." | |
377 | :type 'face | |
378 | :group 'ibuffer) | |
379 | ||
25d2f683 CW |
380 | (defcustom ibuffer-directory-abbrev-alist nil |
381 | "An alist of file name abbreviations like `directory-abbrev-alist'." | |
382 | :type '(repeat (cons :format "%v" | |
383 | :value ("" . "") | |
384 | (regexp :tag "From") | |
385 | (regexp :tag "To"))) | |
386 | :group 'ibuffer) | |
387 | ||
4e4a724c | 388 | |
25d2f683 CW |
389 | (defvar ibuffer-mode-map nil) |
390 | (defvar ibuffer-mode-operate-map nil) | |
b5e80d1a | 391 | (defvar ibuffer-mode-groups-popup nil) |
25d2f683 CW |
392 | (unless ibuffer-mode-map |
393 | (let ((map (make-sparse-keymap)) | |
b5e80d1a CW |
394 | (operate-map (make-sparse-keymap "Operate")) |
395 | (groups-map (make-sparse-keymap "Filter Groups"))) | |
25d2f683 CW |
396 | (define-key map (kbd "0") 'digit-argument) |
397 | (define-key map (kbd "1") 'digit-argument) | |
398 | (define-key map (kbd "2") 'digit-argument) | |
399 | (define-key map (kbd "3") 'digit-argument) | |
400 | (define-key map (kbd "4") 'digit-argument) | |
401 | (define-key map (kbd "5") 'digit-argument) | |
402 | (define-key map (kbd "6") 'digit-argument) | |
403 | (define-key map (kbd "7") 'digit-argument) | |
404 | (define-key map (kbd "8") 'digit-argument) | |
405 | (define-key map (kbd "9") 'digit-argument) | |
406 | ||
407 | (define-key map (kbd "m") 'ibuffer-mark-forward) | |
408 | (define-key map (kbd "t") 'ibuffer-toggle-marks) | |
409 | (define-key map (kbd "u") 'ibuffer-unmark-forward) | |
410 | (define-key map (kbd "=") 'ibuffer-diff-with-file) | |
411 | (define-key map (kbd "j") 'ibuffer-jump-to-buffer) | |
0bdd7ae4 | 412 | (define-key map (kbd "M-g") 'ibuffer-jump-to-buffer) |
25d2f683 CW |
413 | (define-key map (kbd "DEL") 'ibuffer-unmark-backward) |
414 | (define-key map (kbd "M-DEL") 'ibuffer-unmark-all) | |
415 | (define-key map (kbd "* *") 'ibuffer-unmark-all) | |
416 | (define-key map (kbd "* M") 'ibuffer-mark-by-mode) | |
417 | (define-key map (kbd "* m") 'ibuffer-mark-modified-buffers) | |
418 | (define-key map (kbd "* u") 'ibuffer-mark-unsaved-buffers) | |
419 | (define-key map (kbd "* s") 'ibuffer-mark-special-buffers) | |
420 | (define-key map (kbd "* r") 'ibuffer-mark-read-only-buffers) | |
421 | (define-key map (kbd "* /") 'ibuffer-mark-dired-buffers) | |
422 | (define-key map (kbd "* e") 'ibuffer-mark-dissociated-buffers) | |
423 | (define-key map (kbd "* h") 'ibuffer-mark-help-buffers) | |
9fe14abe | 424 | (define-key map (kbd "* z") 'ibuffer-mark-compressed-file-buffers) |
25d2f683 | 425 | (define-key map (kbd ".") 'ibuffer-mark-old-buffers) |
71296446 | 426 | |
25d2f683 CW |
427 | (define-key map (kbd "d") 'ibuffer-mark-for-delete) |
428 | (define-key map (kbd "C-d") 'ibuffer-mark-for-delete-backwards) | |
429 | (define-key map (kbd "k") 'ibuffer-mark-for-delete) | |
430 | (define-key map (kbd "x") 'ibuffer-do-kill-on-deletion-marks) | |
71296446 | 431 | |
25d2f683 CW |
432 | ;; immediate operations |
433 | (define-key map (kbd "n") 'ibuffer-forward-line) | |
b5cd37ea | 434 | (define-key map (kbd "<down>") 'ibuffer-forward-line) |
25d2f683 CW |
435 | (define-key map (kbd "SPC") 'forward-line) |
436 | (define-key map (kbd "p") 'ibuffer-backward-line) | |
cba63a2d | 437 | (define-key map (kbd "<up>") 'ibuffer-backward-line) |
25d2f683 CW |
438 | (define-key map (kbd "M-}") 'ibuffer-forward-next-marked) |
439 | (define-key map (kbd "M-{") 'ibuffer-backwards-next-marked) | |
440 | (define-key map (kbd "l") 'ibuffer-redisplay) | |
441 | (define-key map (kbd "g") 'ibuffer-update) | |
442 | (define-key map "`" 'ibuffer-switch-format) | |
443 | (define-key map "-" 'ibuffer-add-to-tmp-hide) | |
444 | (define-key map "+" 'ibuffer-add-to-tmp-show) | |
445 | (define-key map "b" 'ibuffer-bury-buffer) | |
446 | (define-key map (kbd ",") 'ibuffer-toggle-sorting-mode) | |
447 | (define-key map (kbd "s i") 'ibuffer-invert-sorting) | |
448 | (define-key map (kbd "s a") 'ibuffer-do-sort-by-alphabetic) | |
449 | (define-key map (kbd "s v") 'ibuffer-do-sort-by-recency) | |
450 | (define-key map (kbd "s s") 'ibuffer-do-sort-by-size) | |
d5794180 | 451 | (define-key map (kbd "s f") 'ibuffer-do-sort-by-filename/process) |
25d2f683 CW |
452 | (define-key map (kbd "s m") 'ibuffer-do-sort-by-major-mode) |
453 | ||
454 | (define-key map (kbd "/ m") 'ibuffer-filter-by-mode) | |
5bc06df9 | 455 | (define-key map (kbd "/ M") 'ibuffer-filter-by-used-mode) |
25d2f683 CW |
456 | (define-key map (kbd "/ n") 'ibuffer-filter-by-name) |
457 | (define-key map (kbd "/ c") 'ibuffer-filter-by-content) | |
458 | (define-key map (kbd "/ e") 'ibuffer-filter-by-predicate) | |
459 | (define-key map (kbd "/ f") 'ibuffer-filter-by-filename) | |
460 | (define-key map (kbd "/ >") 'ibuffer-filter-by-size-gt) | |
461 | (define-key map (kbd "/ <") 'ibuffer-filter-by-size-lt) | |
462 | (define-key map (kbd "/ r") 'ibuffer-switch-to-saved-filters) | |
463 | (define-key map (kbd "/ a") 'ibuffer-add-saved-filters) | |
464 | (define-key map (kbd "/ x") 'ibuffer-delete-saved-filters) | |
465 | (define-key map (kbd "/ d") 'ibuffer-decompose-filter) | |
466 | (define-key map (kbd "/ s") 'ibuffer-save-filters) | |
467 | (define-key map (kbd "/ p") 'ibuffer-pop-filter) | |
468 | (define-key map (kbd "/ !") 'ibuffer-negate-filter) | |
469 | (define-key map (kbd "/ t") 'ibuffer-exchange-filters) | |
470 | (define-key map (kbd "/ TAB") 'ibuffer-exchange-filters) | |
471 | (define-key map (kbd "/ o") 'ibuffer-or-filter) | |
b5cd37ea CW |
472 | (define-key map (kbd "/ g") 'ibuffer-filters-to-filter-group) |
473 | (define-key map (kbd "/ P") 'ibuffer-pop-filter-group) | |
2bd26a6f | 474 | (define-key map (kbd "/ D") 'ibuffer-decompose-filter-group) |
25d2f683 | 475 | (define-key map (kbd "/ /") 'ibuffer-filter-disable) |
b5cd37ea CW |
476 | |
477 | (define-key map (kbd "M-n") 'ibuffer-forward-filter-group) | |
478 | (define-key map (kbd "<right>") 'ibuffer-forward-filter-group) | |
479 | (define-key map (kbd "M-p") 'ibuffer-backward-filter-group) | |
480 | (define-key map (kbd "<left>") 'ibuffer-backward-filter-group) | |
481 | (define-key map (kbd "M-j") 'ibuffer-jump-to-filter-group) | |
cba63a2d CW |
482 | (define-key map (kbd "C-k") 'ibuffer-kill-line) |
483 | (define-key map (kbd "C-y") 'ibuffer-yank) | |
484 | (define-key map (kbd "/ S") 'ibuffer-save-filter-groups) | |
485 | (define-key map (kbd "/ R") 'ibuffer-switch-to-saved-filter-groups) | |
486 | (define-key map (kbd "/ X") 'ibuffer-delete-saved-filter-groups) | |
487 | (define-key map (kbd "/ \\") 'ibuffer-clear-filter-groups) | |
71296446 | 488 | |
25d2f683 CW |
489 | (define-key map (kbd "q") 'ibuffer-quit) |
490 | (define-key map (kbd "h") 'describe-mode) | |
491 | (define-key map (kbd "?") 'describe-mode) | |
492 | ||
493 | (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp) | |
494 | (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp) | |
495 | (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp) | |
71296446 | 496 | |
25d2f683 CW |
497 | (define-key map (kbd "C-t") 'ibuffer-visit-tags-table) |
498 | ||
499 | (define-key map (kbd "|") 'ibuffer-do-shell-command-pipe) | |
500 | (define-key map (kbd "!") 'ibuffer-do-shell-command-file) | |
501 | (define-key map (kbd "~") 'ibuffer-do-toggle-modified) | |
502 | ;; marked operations | |
503 | (define-key map (kbd "A") 'ibuffer-do-view) | |
504 | (define-key map (kbd "D") 'ibuffer-do-delete) | |
505 | (define-key map (kbd "E") 'ibuffer-do-eval) | |
506 | (define-key map (kbd "F") 'ibuffer-do-shell-command-file) | |
507 | (define-key map (kbd "I") 'ibuffer-do-query-replace-regexp) | |
508 | (define-key map (kbd "H") 'ibuffer-do-view-other-frame) | |
509 | (define-key map (kbd "N") 'ibuffer-do-shell-command-pipe-replace) | |
510 | (define-key map (kbd "M") 'ibuffer-do-toggle-modified) | |
511 | (define-key map (kbd "O") 'ibuffer-do-occur) | |
512 | (define-key map (kbd "P") 'ibuffer-do-print) | |
513 | (define-key map (kbd "Q") 'ibuffer-do-query-replace) | |
514 | (define-key map (kbd "R") 'ibuffer-do-rename-uniquely) | |
515 | (define-key map (kbd "S") 'ibuffer-do-save) | |
516 | (define-key map (kbd "T") 'ibuffer-do-toggle-read-only) | |
517 | (define-key map (kbd "U") 'ibuffer-do-replace-regexp) | |
518 | (define-key map (kbd "V") 'ibuffer-do-revert) | |
519 | (define-key map (kbd "W") 'ibuffer-do-view-and-eval) | |
520 | (define-key map (kbd "X") 'ibuffer-do-shell-command-pipe) | |
71296446 | 521 | |
25d2f683 CW |
522 | (define-key map (kbd "k") 'ibuffer-do-kill-lines) |
523 | (define-key map (kbd "w") 'ibuffer-copy-filename-as-kill) | |
524 | ||
525 | (define-key map (kbd "RET") 'ibuffer-visit-buffer) | |
526 | (define-key map (kbd "e") 'ibuffer-visit-buffer) | |
527 | (define-key map (kbd "f") 'ibuffer-visit-buffer) | |
528 | (define-key map (kbd "C-x C-f") 'ibuffer-find-file) | |
529 | (define-key map (kbd "o") 'ibuffer-visit-buffer-other-window) | |
530 | (define-key map (kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect) | |
531 | (define-key map (kbd "M-o") 'ibuffer-visit-buffer-1-window) | |
532 | (define-key map (kbd "v") 'ibuffer-do-view) | |
533 | (define-key map (kbd "C-x v") 'ibuffer-do-view-horizontally) | |
534 | (define-key map (kbd "C-c C-a") 'ibuffer-auto-mode) | |
535 | (define-key map (kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window) | |
536 | (define-key map (kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame) | |
537 | ||
538 | (define-key map [menu-bar view] | |
539 | (cons "View" (make-sparse-keymap "View"))) | |
540 | ||
541 | (define-key-after map [menu-bar view visit-buffer] | |
542 | '(menu-item "View this buffer" ibuffer-visit-buffer)) | |
543 | (define-key-after map [menu-bar view visit-buffer-other-window] | |
544 | '(menu-item "View (other window)" ibuffer-visit-buffer-other-window)) | |
545 | (define-key-after map [menu-bar view visit-buffer-other-frame] | |
546 | '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame)) | |
547 | (define-key-after map [menu-bar view ibuffer-update] | |
548 | '(menu-item "Update" ibuffer-update | |
549 | :help "Regenerate the list of buffers")) | |
550 | (define-key-after map [menu-bar view switch-format] | |
551 | '(menu-item "Switch display format" ibuffer-switch-format | |
552 | :help "Toggle between available values of `ibuffer-formats'")) | |
553 | ||
554 | (define-key-after map [menu-bar view dashes] | |
555 | '("--")) | |
556 | ||
557 | (define-key-after map [menu-bar view sort] | |
558 | (cons "Sort" (make-sparse-keymap "Sort"))) | |
559 | ||
560 | (define-key-after map [menu-bar view sort do-sort-by-major-mode] | |
cba63a2d | 561 | '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode)) |
25d2f683 | 562 | (define-key-after map [menu-bar view sort do-sort-by-size] |
cba63a2d | 563 | '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size)) |
25d2f683 CW |
564 | (define-key-after map [menu-bar view sort do-sort-by-alphabetic] |
565 | '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic | |
566 | :help "Sort by the alphabetic order of buffer name")) | |
567 | (define-key-after map [menu-bar view sort do-sort-by-recency] | |
568 | '(menu-item "Sort by view time" ibuffer-do-sort-by-recency | |
569 | :help "Sort by the last time the buffer was displayed")) | |
4e4a724c JPW |
570 | (define-key-after map [menu-bar view sort dashes] |
571 | '("--")) | |
25d2f683 CW |
572 | (define-key-after map [menu-bar view sort invert-sorting] |
573 | '(menu-item "Reverse sorting order" ibuffer-invert-sorting)) | |
574 | (define-key-after map [menu-bar view sort toggle-sorting-mode] | |
575 | '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode | |
576 | :help "Switch between the various sorting criteria")) | |
577 | ||
578 | (define-key-after map [menu-bar view filter] | |
579 | (cons "Filter" (make-sparse-keymap "Filter"))) | |
580 | ||
581 | (define-key-after map [menu-bar view filter filter-disable] | |
05cc03af CW |
582 | '(menu-item "Disable all filtering" ibuffer-filter-disable |
583 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers))) | |
25d2f683 | 584 | (define-key-after map [menu-bar view filter filter-by-mode] |
cba63a2d | 585 | '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode)) |
5bc06df9 CW |
586 | (define-key-after map [menu-bar view filter filter-by-mode] |
587 | '(menu-item "Add filter by major mode in use..." ibuffer-filter-by-used-mode)) | |
25d2f683 | 588 | (define-key-after map [menu-bar view filter filter-by-name] |
cba63a2d | 589 | '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name)) |
25d2f683 | 590 | (define-key-after map [menu-bar view filter filter-by-filename] |
cba63a2d | 591 | '(menu-item "Add filter by filename..." ibuffer-filter-by-filename)) |
25d2f683 | 592 | (define-key-after map [menu-bar view filter filter-by-size-lt] |
cba63a2d | 593 | '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt)) |
25d2f683 | 594 | (define-key-after map [menu-bar view filter filter-by-size-gt] |
cba63a2d | 595 | '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt)) |
25d2f683 | 596 | (define-key-after map [menu-bar view filter filter-by-content] |
cba63a2d | 597 | '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content)) |
25d2f683 | 598 | (define-key-after map [menu-bar view filter filter-by-predicate] |
cba63a2d | 599 | '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate)) |
25d2f683 | 600 | (define-key-after map [menu-bar view filter pop-filter] |
05cc03af CW |
601 | '(menu-item "Remove top filter" ibuffer-pop-filter |
602 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers))) | |
25d2f683 CW |
603 | (define-key-after map [menu-bar view filter or-filter] |
604 | '(menu-item "OR top two filters" ibuffer-or-filter | |
717339e5 CW |
605 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers |
606 | (cdr ibuffer-filtering-qualifiers)) | |
25d2f683 CW |
607 | :help "Create a new filter which is the logical OR of the top two filters")) |
608 | (define-key-after map [menu-bar view filter negate-filter] | |
05cc03af CW |
609 | '(menu-item "Negate top filter" ibuffer-negate-filter |
610 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers))) | |
25d2f683 CW |
611 | (define-key-after map [menu-bar view filter decompose-filter] |
612 | '(menu-item "Decompose top filter" ibuffer-decompose-filter | |
717339e5 | 613 | :enable (and (featurep 'ibuf-ext) (memq (car ibuffer-filtering-qualifiers) '(or saved not))) |
25d2f683 CW |
614 | :help "Break down a complex filter like OR or NOT")) |
615 | (define-key-after map [menu-bar view filter exchange-filters] | |
05cc03af | 616 | '(menu-item "Swap top two filters" ibuffer-exchange-filters |
717339e5 CW |
617 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers |
618 | (cdr ibuffer-filtering-qualifiers)))) | |
25d2f683 CW |
619 | (define-key-after map [menu-bar view filter save-filters] |
620 | '(menu-item "Save current filters permanently..." ibuffer-save-filters | |
4e4a724c | 621 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers) |
25d2f683 CW |
622 | :help "Use a mnemnonic name to store current filter stack")) |
623 | (define-key-after map [menu-bar view filter switch-to-saved-filters] | |
624 | '(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters | |
05cc03af | 625 | :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters) |
25d2f683 CW |
626 | :help "Replace current filters with a saved stack")) |
627 | (define-key-after map [menu-bar view filter add-saved-filters] | |
628 | '(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters | |
05cc03af | 629 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers) |
cba63a2d | 630 | :help "Include already saved stack with current filters")) |
25d2f683 | 631 | (define-key-after map [menu-bar view filter delete-saved-filters] |
cba63a2d | 632 | '(menu-item "Delete permanently saved filters..." |
05cc03af CW |
633 | ibuffer-delete-saved-filters |
634 | :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters))) | |
cba63a2d | 635 | |
b5e80d1a | 636 | ;; Filter groups |
cba63a2d | 637 | |
b5e80d1a | 638 | (define-key-after groups-map [filters-to-filter-group] |
cba63a2d | 639 | '(menu-item "Create filter group from current filters..." |
2bd26a6f CW |
640 | ibuffer-filters-to-filter-group |
641 | :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers))) | |
b5e80d1a | 642 | (define-key-after groups-map [forward-filter-group] |
cba63a2d | 643 | '(menu-item "Move point to the next filter group" |
4e4a724c | 644 | ibuffer-forward-filter-group)) |
b5e80d1a | 645 | (define-key-after groups-map [backward-filter-group] |
cba63a2d CW |
646 | '(menu-item "Move point to the previous filter group" |
647 | ibuffer-backward-filter-group)) | |
b5e80d1a | 648 | (define-key-after groups-map [jump-to-filter-group] |
cba63a2d CW |
649 | '(menu-item "Move point to a specific filter group..." |
650 | ibuffer-jump-to-filter-group)) | |
b5e80d1a CW |
651 | (define-key-after groups-map [kill-filter-group] |
652 | '(menu-item "Kill filter group named..." | |
653 | ibuffer-kill-filter-group | |
654 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups))) | |
655 | (define-key-after groups-map [yank-filter-group] | |
656 | '(menu-item "Yank last killed filter group before..." | |
657 | ibuffer-yank-filter-group | |
658 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-group-kill-ring))) | |
659 | (define-key-after groups-map [pop-filter-group] | |
b5cd37ea | 660 | '(menu-item "Remove top filter group" |
b5e80d1a | 661 | ibuffer-pop-filter-group |
2bd26a6f | 662 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups))) |
b5e80d1a | 663 | (define-key-after groups-map [clear-filter-groups] |
cba63a2d | 664 | '(menu-item "Remove all filter groups" |
b5e80d1a | 665 | ibuffer-clear-filter-groups |
2bd26a6f CW |
666 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups))) |
667 | (define-key-after groups-map [pop-filter-group] | |
668 | '(menu-item "Decompose filter group..." | |
669 | ibuffer-pop-filter-group | |
670 | :help "\"Unmake\" a filter group" | |
671 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups))) | |
b5e80d1a | 672 | (define-key-after groups-map [save-filter-groups] |
cba63a2d CW |
673 | '(menu-item "Save current filter groups permanently..." |
674 | ibuffer-save-filter-groups | |
05cc03af | 675 | :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups) |
cba63a2d | 676 | :help "Use a mnemnonic name to store current filter groups")) |
b5e80d1a | 677 | (define-key-after groups-map [switch-to-saved-filter-groups] |
cba63a2d CW |
678 | '(menu-item "Restore permanently saved filters..." |
679 | ibuffer-switch-to-saved-filter-groups | |
05cc03af | 680 | :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups) |
4e4a724c | 681 | :help "Replace current filters with a saved stack")) |
b5e80d1a | 682 | (define-key-after groups-map [delete-saved-filter-groups] |
cba63a2d | 683 | '(menu-item "Delete permanently saved filter groups..." |
05cc03af CW |
684 | ibuffer-delete-saved-filter-groups |
685 | :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups))) | |
b5e80d1a | 686 | (define-key-after groups-map [set-filter-groups-by-mode] |
cba63a2d CW |
687 | '(menu-item "Set current filter groups to filter by mode" |
688 | ibuffer-set-filter-groups-by-mode)) | |
689 | ||
b5e80d1a CW |
690 | (define-key-after map [menu-bar view filter-groups] |
691 | (cons "Filter Groups" groups-map)) | |
692 | ||
25d2f683 CW |
693 | (define-key-after map [menu-bar view dashes2] |
694 | '("--")) | |
695 | (define-key-after map [menu-bar view diff-with-file] | |
696 | '(menu-item "Diff with file" ibuffer-diff-with-file | |
697 | :help "View the differences between this buffer and its file")) | |
698 | (define-key-after map [menu-bar view auto-mode] | |
699 | '(menu-item "Toggle Auto Mode" ibuffer-auto-mode | |
700 | :help "Attempt to automatically update the Ibuffer buffer")) | |
701 | (define-key-after map [menu-bar view customize] | |
4e4a724c | 702 | '(menu-item "Customize Ibuffer" ibuffer-customize |
25d2f683 CW |
703 | :help "Use Custom to customize Ibuffer")) |
704 | ||
705 | (define-key-after map [menu-bar mark] | |
706 | (cons "Mark" (make-sparse-keymap "Mark"))) | |
707 | ||
708 | (define-key-after map [menu-bar mark toggle-marks] | |
709 | '(menu-item "Toggle marks" ibuffer-toggle-marks | |
710 | :help "Unmark marked buffers, and mark unmarked buffers")) | |
711 | (define-key-after map [menu-bar mark mark-forward] | |
712 | '(menu-item "Mark" ibuffer-mark-forward | |
713 | :help "Mark the buffer at point")) | |
714 | (define-key-after map [menu-bar mark unmark-forward] | |
715 | '(menu-item "Unmark" ibuffer-unmark-forward | |
716 | :help "Unmark the buffer at point")) | |
717 | (define-key-after map [menu-bar mark mark-by-mode] | |
718 | '(menu-item "Mark by mode..." ibuffer-mark-by-mode | |
719 | :help "Mark all buffers in a particular major mode")) | |
720 | (define-key-after map [menu-bar mark mark-modified-buffers] | |
721 | '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers | |
722 | :help "Mark all buffers which have been modified")) | |
723 | (define-key-after map [menu-bar mark mark-unsaved-buffers] | |
724 | '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers | |
725 | :help "Mark all buffers which have a file and are modified")) | |
726 | (define-key-after map [menu-bar mark mark-read-only-buffers] | |
727 | '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers | |
728 | :help "Mark all buffers which are read-only")) | |
729 | (define-key-after map [menu-bar mark mark-special-buffers] | |
730 | '(menu-item "Mark special buffers" ibuffer-mark-special-buffers | |
731 | :help "Mark all buffers whose name begins with a *")) | |
732 | (define-key-after map [menu-bar mark mark-dired-buffers] | |
733 | '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers | |
734 | :help "Mark buffers in dired-mode")) | |
735 | (define-key-after map [menu-bar mark mark-dissociated-buffers] | |
736 | '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers | |
737 | :help "Mark buffers with a non-existent associated file")) | |
738 | (define-key-after map [menu-bar mark mark-help-buffers] | |
739 | '(menu-item "Mark help buffers" ibuffer-mark-help-buffers | |
740 | :help "Mark buffers in help-mode")) | |
9fe14abe JPW |
741 | (define-key-after map [menu-bar mark mark-compressed-file-buffers] |
742 | '(menu-item "Mark compressed file buffers" ibuffer-mark-compressed-file-buffers | |
743 | :help "Mark buffers which have a file that is compressed")) | |
25d2f683 CW |
744 | (define-key-after map [menu-bar mark mark-old-buffers] |
745 | '(menu-item "Mark old buffers" ibuffer-mark-old-buffers | |
746 | :help "Mark buffers which have not been viewed recently")) | |
747 | (define-key-after map [menu-bar mark unmark-all] | |
748 | '(menu-item "Unmark All" ibuffer-unmark-all)) | |
71296446 | 749 | |
25d2f683 CW |
750 | (define-key-after map [menu-bar mark dashes] |
751 | '("--")) | |
71296446 | 752 | |
25d2f683 CW |
753 | (define-key-after map [menu-bar mark mark-by-name-regexp] |
754 | '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp | |
755 | :help "Mark buffers whose name matches a regexp")) | |
756 | (define-key-after map [menu-bar mark mark-by-mode-regexp] | |
757 | '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp | |
758 | :help "Mark buffers whose major mode name matches a regexp")) | |
759 | (define-key-after map [menu-bar mark mark-by-file-name-regexp] | |
760 | '(menu-item "Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp | |
761 | :help "Mark buffers whose file name matches a regexp")) | |
762 | ||
763 | ;; Operate map is added later | |
764 | ||
765 | (define-key-after operate-map [do-view] | |
766 | '(menu-item "View" ibuffer-do-view)) | |
767 | (define-key-after operate-map [do-view-other-frame] | |
768 | '(menu-item "View (separate frame)" ibuffer-do-view-other-frame)) | |
769 | (define-key-after operate-map [do-save] | |
770 | '(menu-item "Save" ibuffer-do-save)) | |
771 | (define-key-after operate-map [do-replace-regexp] | |
772 | '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp | |
773 | :help "Replace text inside marked buffers")) | |
774 | (define-key-after operate-map [do-query-replace] | |
775 | '(menu-item "Query Replace..." ibuffer-do-query-replace | |
776 | :help "Replace text in marked buffers, asking each time")) | |
777 | (define-key-after operate-map [do-query-replace-regexp] | |
778 | '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp | |
779 | :help "Replace text in marked buffers by regexp, asking each time")) | |
780 | (define-key-after operate-map [do-print] | |
781 | '(menu-item "Print" ibuffer-do-print)) | |
782 | (define-key-after operate-map [do-toggle-modified] | |
783 | '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified)) | |
784 | (define-key-after operate-map [do-revert] | |
785 | '(menu-item "Revert" ibuffer-do-revert | |
786 | :help "Revert marked buffers to their associated file")) | |
787 | (define-key-after operate-map [do-rename-uniquely] | |
788 | '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely | |
789 | :help "Rename marked buffers to a new, unique name")) | |
790 | (define-key-after operate-map [do-delete] | |
791 | '(menu-item "Kill" ibuffer-do-delete)) | |
792 | (define-key-after operate-map [do-occur] | |
793 | '(menu-item "List lines matching..." ibuffer-do-occur | |
794 | :help "View all lines in marked buffers matching a regexp")) | |
795 | (define-key-after operate-map [do-shell-command-pipe] | |
796 | '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe | |
797 | :help "For each marked buffer, send its contents to a shell command")) | |
798 | (define-key-after operate-map [do-shell-command-pipe-replace] | |
799 | '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace | |
800 | :help "For each marked buffer, replace its contents with output of shell command")) | |
801 | (define-key-after operate-map [do-shell-command-file] | |
802 | '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file | |
803 | :help "For each marked buffer, run a shell command with its file as argument")) | |
804 | (define-key-after operate-map [do-eval] | |
805 | '(menu-item "Eval..." ibuffer-do-eval | |
806 | :help "Evaluate a Lisp form in each marked buffer")) | |
807 | (define-key-after operate-map [do-view-and-eval] | |
808 | '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval | |
809 | :help "Evaluate a Lisp form in each marked buffer while viewing it")) | |
71296446 | 810 | |
25d2f683 | 811 | (setq ibuffer-mode-map map |
b5e80d1a | 812 | ibuffer-mode-operate-map operate-map |
2bd26a6f CW |
813 | ibuffer-mode-groups-popup (copy-keymap groups-map)))) |
814 | ||
815 | (define-key ibuffer-mode-groups-popup [kill-filter-group] | |
4e4a724c JPW |
816 | '(menu-item "Kill filter group" |
817 | ibuffer-kill-line | |
34a4faa0 JPW |
818 | :enable (and (featurep 'ibuf-ext) |
819 | ibuffer-filter-groups))) | |
545aad2f | 820 | (define-key ibuffer-mode-groups-popup [yank-filter-group] |
4e4a724c JPW |
821 | '(menu-item "Yank last killed filter group" |
822 | ibuffer-yank | |
34a4faa0 JPW |
823 | :enable (and (featurep 'ibuf-ext) |
824 | ibuffer-filter-group-kill-ring))) | |
4e4a724c | 825 | |
acf88897 | 826 | (defvar ibuffer-name-map |
25d2f683 | 827 | (let ((map (make-sparse-keymap))) |
25d2f683 CW |
828 | (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark) |
829 | (define-key map [(mouse-2)] 'ibuffer-mouse-visit-buffer) | |
830 | (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu) | |
acf88897 | 831 | map)) |
25d2f683 | 832 | |
d5794180 DN |
833 | (defvar ibuffer-filename/process-header-map |
834 | (let ((map (make-sparse-keymap))) | |
835 | (define-key map [(mouse-1)] 'ibuffer-do-sort-by-filename/process) | |
836 | map)) | |
837 | ||
acf88897 | 838 | (defvar ibuffer-mode-name-map |
25d2f683 | 839 | (let ((map (make-sparse-keymap))) |
25d2f683 CW |
840 | (define-key map [(mouse-2)] 'ibuffer-mouse-filter-by-mode) |
841 | (define-key map (kbd "RET") 'ibuffer-interactive-filter-by-mode) | |
acf88897 | 842 | map)) |
25d2f683 | 843 | |
f0b31589 DN |
844 | (defvar ibuffer-name-header-map |
845 | (let ((map (make-sparse-keymap))) | |
846 | (define-key map [(mouse-1)] 'ibuffer-do-sort-by-alphabetic) | |
847 | map)) | |
848 | ||
849 | (defvar ibuffer-size-header-map | |
850 | (let ((map (make-sparse-keymap))) | |
851 | (define-key map [(mouse-1)] 'ibuffer-do-sort-by-size) | |
852 | map)) | |
853 | ||
854 | (defvar ibuffer-mode-header-map | |
855 | (let ((map (make-sparse-keymap))) | |
856 | (define-key map [(mouse-1)] 'ibuffer-do-sort-by-major-mode) | |
857 | map)) | |
858 | ||
acf88897 | 859 | (defvar ibuffer-mode-filter-group-map |
b5cd37ea | 860 | (let ((map (make-sparse-keymap))) |
b5cd37ea CW |
861 | (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark) |
862 | (define-key map [(mouse-2)] 'ibuffer-mouse-toggle-filter-group) | |
863 | (define-key map (kbd "RET") 'ibuffer-toggle-filter-group) | |
b5e80d1a | 864 | (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu) |
acf88897 | 865 | map)) |
b5cd37ea | 866 | |
4ed1f829 JPW |
867 | (defvar ibuffer-restore-window-config-on-quit nil |
868 | "If non-nil, restore previous window configuration upon exiting `ibuffer'.") | |
869 | ||
870 | (defvar ibuffer-prev-window-config nil | |
871 | "Window configuration before starting Ibuffer.") | |
25d2f683 CW |
872 | |
873 | (defvar ibuffer-did-modification nil) | |
874 | ||
63f0a166 JB |
875 | (defvar ibuffer-compiled-formats nil) |
876 | (defvar ibuffer-cached-formats nil) | |
877 | (defvar ibuffer-cached-eliding-string nil) | |
878 | (defvar ibuffer-cached-elide-long-columns 0) | |
879 | ||
25d2f683 CW |
880 | (defvar ibuffer-sorting-functions-alist nil |
881 | "An alist of functions which describe how to sort buffers. | |
882 | ||
883 | Note: You most likely do not want to modify this variable directly; | |
884 | use `define-ibuffer-sorter' instead. | |
885 | ||
886 | The alist elements are constructed like (NAME DESCRIPTION FUNCTION) | |
887 | Where NAME is a symbol describing the sorting method, DESCRIPTION is a | |
888 | short string which will be displayed in the minibuffer and menu, and | |
889 | FUNCTION is a function of two arguments, which will be the buffers to | |
890 | compare.") | |
891 | ||
892 | ;;; Utility functions | |
893 | (defun ibuffer-columnize-and-insert-list (list &optional pad-width) | |
894 | "Insert LIST into the current buffer in as many columns as possible. | |
895 | The maximum number of columns is determined by the current window | |
896 | width and the longest string in LIST." | |
897 | (unless pad-width | |
898 | (setq pad-width 3)) | |
899 | (let ((width (window-width)) | |
900 | (max (+ (apply #'max (mapcar #'length list)) | |
901 | pad-width))) | |
902 | (let ((columns (/ width max))) | |
903 | (when (zerop columns) | |
904 | (setq columns 1)) | |
905 | (while list | |
906 | (dotimes (i (1- columns)) | |
907 | (insert (concat (car list) (make-string (- max (length (car list))) | |
972b8f82 | 908 | ?\s))) |
25d2f683 CW |
909 | (setq list (cdr list))) |
910 | (when (not (null list)) | |
911 | (insert (pop list))) | |
912 | (insert "\n"))))) | |
913 | ||
25d2f683 CW |
914 | (defsubst ibuffer-current-mark () |
915 | (cadr (get-text-property (line-beginning-position) | |
916 | 'ibuffer-properties))) | |
917 | ||
918 | (defun ibuffer-mouse-toggle-mark (event) | |
919 | "Toggle the marked status of the buffer chosen with the mouse." | |
920 | (interactive "e") | |
921 | (unwind-protect | |
b5cd37ea CW |
922 | (let ((pt (save-excursion |
923 | (mouse-set-point event) | |
924 | (point)))) | |
925 | (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name) | |
926 | (ibuffer-toggle-marks it) | |
927 | (goto-char pt) | |
928 | (let ((mark (ibuffer-current-mark))) | |
929 | (setq buffer-read-only nil) | |
930 | (if (eq mark ibuffer-marked-char) | |
972b8f82 | 931 | (ibuffer-set-mark ?\s) |
b5cd37ea | 932 | (ibuffer-set-mark ibuffer-marked-char))))) |
25d2f683 CW |
933 | (setq buffer-read-only t))) |
934 | ||
935 | (defun ibuffer-find-file (file &optional wildcards) | |
936 | "Like `find-file', but default to the directory of the buffer at point." | |
937 | (interactive | |
938 | (let ((default-directory (let ((buf (ibuffer-current-buffer))) | |
939 | (if (buffer-live-p buf) | |
940 | (with-current-buffer buf | |
941 | default-directory) | |
942 | default-directory)))) | |
943 | (list (read-file-name "Find file: " default-directory) | |
fe78af29 JPW |
944 | t))) |
945 | (find-file file wildcards)) | |
25d2f683 CW |
946 | |
947 | (defun ibuffer-mouse-visit-buffer (event) | |
948 | "Visit the buffer chosen with the mouse." | |
949 | (interactive "e") | |
950 | (switch-to-buffer | |
951 | (save-excursion | |
952 | (mouse-set-point event) | |
b5cd37ea | 953 | (ibuffer-current-buffer t)))) |
25d2f683 CW |
954 | |
955 | (defun ibuffer-mouse-popup-menu (event) | |
956 | "Display a menu of operations." | |
957 | (interactive "e") | |
a1793b2d JPW |
958 | (let ((eventpt (posn-point (event-end event))) |
959 | (origpt (point))) | |
25d2f683 | 960 | (unwind-protect |
51922c04 | 961 | (if (get-text-property eventpt 'ibuffer-filter-group-name) |
a1793b2d JPW |
962 | (progn |
963 | (goto-char eventpt) | |
964 | (popup-menu ibuffer-mode-groups-popup)) | |
51922c04 | 965 | (let ((inhibit-read-only t)) |
b5e80d1a | 966 | (ibuffer-save-marks |
4e4a724c JPW |
967 | ;; hm. we could probably do this in a better fashion |
968 | (ibuffer-unmark-all ?\r) | |
969 | (save-excursion | |
970 | (goto-char eventpt) | |
971 | (ibuffer-set-mark ibuffer-marked-char)) | |
972 | (save-excursion | |
973 | (popup-menu ibuffer-mode-operate-map))))) | |
a1793b2d | 974 | (setq buffer-read-only t) |
4ba16127 | 975 | (if (= eventpt (point)) |
a1793b2d | 976 | (goto-char origpt))))) |
51922c04 | 977 | |
b5cd37ea CW |
978 | (defun ibuffer-skip-properties (props direction) |
979 | (while (and (not (eobp)) | |
980 | (let ((hit nil)) | |
981 | (dolist (prop props hit) | |
982 | (when (get-text-property (point) prop) | |
983 | (setq hit t))))) | |
984 | (forward-line direction) | |
985 | (beginning-of-line))) | |
25d2f683 | 986 | |
4e4a724c JPW |
987 | (defun ibuffer-customize () |
988 | "Begin customizing Ibuffer interactively." | |
989 | (interactive) | |
990 | (customize-group 'ibuffer)) | |
991 | ||
b5cd37ea | 992 | (defun ibuffer-backward-line (&optional arg skip-group-names) |
25d2f683 CW |
993 | "Move backwards ARG lines, wrapping around the list if necessary." |
994 | (interactive "P") | |
34a4faa0 | 995 | (or arg (setq arg 1)) |
25d2f683 CW |
996 | (beginning-of-line) |
997 | (while (> arg 0) | |
998 | (forward-line -1) | |
0ce780e1 CW |
999 | (when (and ibuffer-movement-cycle |
1000 | (or (get-text-property (point) 'ibuffer-title) | |
1001 | (and skip-group-names | |
34a4faa0 JPW |
1002 | (get-text-property (point) |
1003 | 'ibuffer-filter-group-name)))) | |
25d2f683 | 1004 | (goto-char (point-max)) |
60356fb5 | 1005 | (beginning-of-line)) |
b5cd37ea CW |
1006 | (ibuffer-skip-properties (append '(ibuffer-summary) |
1007 | (when skip-group-names | |
1008 | '(ibuffer-filter-group-name))) | |
1009 | -1) | |
60356fb5 CW |
1010 | ;; Handle the special case of no buffers. |
1011 | (when (get-text-property (point) 'ibuffer-title) | |
1012 | (forward-line 1) | |
1013 | (setq arg 1)) | |
1014 | (decf arg))) | |
25d2f683 | 1015 | |
b5cd37ea | 1016 | (defun ibuffer-forward-line (&optional arg skip-group-names) |
25d2f683 CW |
1017 | "Move forward ARG lines, wrapping around the list if necessary." |
1018 | (interactive "P") | |
34a4faa0 | 1019 | (or arg (setq arg 1)) |
25d2f683 | 1020 | (beginning-of-line) |
0ce780e1 CW |
1021 | (when (and ibuffer-movement-cycle |
1022 | (or (eobp) | |
1023 | (get-text-property (point) 'ibuffer-summary))) | |
214b39be | 1024 | (goto-char (point-min))) |
b5cd37ea CW |
1025 | (when (or (get-text-property (point) 'ibuffer-title) |
1026 | (and skip-group-names | |
1027 | (get-text-property (point) 'ibuffer-filter-group-name))) | |
1028 | (when (> arg 0) | |
1029 | (decf arg)) | |
1030 | (ibuffer-skip-properties (append '(ibuffer-title) | |
1031 | (when skip-group-names | |
1032 | '(ibuffer-filter-group-name))) | |
1033 | 1)) | |
25d2f683 CW |
1034 | (if (< arg 0) |
1035 | (ibuffer-backward-line (- arg)) | |
60356fb5 CW |
1036 | (while (> arg 0) |
1037 | (forward-line 1) | |
0ce780e1 CW |
1038 | (when (and ibuffer-movement-cycle |
1039 | (or (eobp) | |
1040 | (get-text-property (point) 'ibuffer-summary))) | |
60356fb5 | 1041 | (goto-char (point-min))) |
b5cd37ea CW |
1042 | (decf arg) |
1043 | (ibuffer-skip-properties (append '(ibuffer-title) | |
1044 | (when skip-group-names | |
1045 | '(ibuffer-filter-group-name))) | |
1046 | 1)))) | |
25d2f683 | 1047 | |
d246cabf CW |
1048 | (defun ibuffer-visit-buffer (&optional single) |
1049 | "Visit the buffer on this line. | |
d246cabf CW |
1050 | If optional argument SINGLE is non-nil, then also ensure there is only |
1051 | one window." | |
1052 | (interactive "P") | |
b5cd37ea | 1053 | (let ((buf (ibuffer-current-buffer t))) |
25d2f683 | 1054 | (bury-buffer (current-buffer)) |
d246cabf CW |
1055 | (switch-to-buffer buf) |
1056 | (when single | |
1057 | (delete-other-windows)))) | |
25d2f683 CW |
1058 | |
1059 | (defun ibuffer-visit-buffer-other-window (&optional noselect) | |
1060 | "Visit the buffer on this line in another window." | |
1061 | (interactive) | |
b5cd37ea | 1062 | (let ((buf (ibuffer-current-buffer t))) |
25d2f683 CW |
1063 | (bury-buffer (current-buffer)) |
1064 | (if noselect | |
1065 | (let ((curwin (selected-window))) | |
1066 | (pop-to-buffer buf) | |
1067 | (select-window curwin)) | |
1068 | (switch-to-buffer-other-window buf)))) | |
1069 | ||
1070 | (defun ibuffer-visit-buffer-other-window-noselect () | |
1071 | "Visit the buffer on this line in another window, but don't select it." | |
1072 | (interactive) | |
1073 | (ibuffer-visit-buffer-other-window t)) | |
1074 | ||
1075 | (defun ibuffer-visit-buffer-other-frame () | |
1076 | "Visit the buffer on this line in another frame." | |
1077 | (interactive) | |
b5cd37ea | 1078 | (let ((buf (ibuffer-current-buffer t))) |
25d2f683 CW |
1079 | (bury-buffer (current-buffer)) |
1080 | (switch-to-buffer-other-frame buf))) | |
1081 | ||
1082 | (defun ibuffer-visit-buffer-1-window () | |
1083 | "Visit the buffer on this line, and delete other windows." | |
1084 | (interactive) | |
d246cabf | 1085 | (ibuffer-visit-buffer t)) |
25d2f683 CW |
1086 | |
1087 | (defun ibuffer-bury-buffer () | |
1088 | "Bury the buffer on this line." | |
1089 | (interactive) | |
b5cd37ea | 1090 | (let ((buf (ibuffer-current-buffer t)) |
25d2f683 | 1091 | (line (+ 1 (count-lines 1 (point))))) |
25d2f683 CW |
1092 | (bury-buffer buf) |
1093 | (ibuffer-update nil t) | |
1094 | (goto-line line))) | |
1095 | ||
1096 | (defun ibuffer-visit-tags-table () | |
1097 | "Visit the tags table in the buffer on this line. See `visit-tags-table'." | |
1098 | (interactive) | |
b5cd37ea | 1099 | (let ((file (buffer-file-name (ibuffer-current-buffer t)))) |
25d2f683 CW |
1100 | (if file |
1101 | (visit-tags-table file) | |
1102 | (error "Specified buffer has no file")))) | |
1103 | ||
1104 | (defun ibuffer-do-view (&optional other-frame) | |
1105 | "View marked buffers, or the buffer on the current line. | |
1106 | If optional argument OTHER-FRAME is non-nil, then display each | |
1107 | marked buffer in a new frame. Otherwise, display each buffer as | |
1108 | a new window in the current frame, splitting vertically." | |
1109 | (interactive) | |
1110 | (ibuffer-do-view-1 (if other-frame 'other-frame 'vertically))) | |
1111 | ||
1112 | (defun ibuffer-do-view-horizontally (&optional other-frame) | |
1113 | "As `ibuffer-do-view', but split windows horizontally." | |
1114 | (interactive) | |
1115 | (ibuffer-do-view-1 (if other-frame 'other-frame 'horizontally))) | |
1116 | ||
1117 | (defun ibuffer-do-view-1 (type) | |
1118 | (let ((marked-bufs (ibuffer-get-marked-buffers))) | |
1119 | (when (null marked-bufs) | |
b5cd37ea | 1120 | (setq marked-bufs (list (ibuffer-current-buffer t)))) |
25d2f683 CW |
1121 | (unless (and (eq type 'other-frame) |
1122 | (not ibuffer-expert) | |
1123 | (> (length marked-bufs) 3) | |
1124 | (not (y-or-n-p (format "Really create a new frame for %s buffers? " | |
1125 | (length marked-bufs))))) | |
4e4a724c | 1126 | (set-buffer-modified-p nil) |
25d2f683 CW |
1127 | (delete-other-windows) |
1128 | (switch-to-buffer (pop marked-bufs)) | |
1129 | (let ((height (/ (1- (if (eq type 'horizontally) (frame-width) | |
4e4a724c | 1130 | (frame-height))) |
25d2f683 CW |
1131 | (1+ (length marked-bufs))))) |
1132 | (mapcar (if (eq type 'other-frame) | |
1133 | #'(lambda (buf) | |
1134 | (let ((curframe (selected-frame))) | |
acf88897 | 1135 | (select-frame (make-frame)) |
25d2f683 CW |
1136 | (switch-to-buffer buf) |
1137 | (select-frame curframe))) | |
1138 | #'(lambda (buf) | |
1139 | (split-window nil height (eq type 'horizontally)) | |
1140 | (other-window 1) | |
1141 | (switch-to-buffer buf))) | |
1142 | marked-bufs))))) | |
1143 | ||
1144 | (defun ibuffer-do-view-other-frame () | |
1145 | "View each of the marked buffers in a separate frame." | |
1146 | (interactive) | |
1147 | (ibuffer-do-view t)) | |
1148 | ||
1149 | (defsubst ibuffer-map-marked-lines (func) | |
1150 | (prog1 (ibuffer-map-on-mark ibuffer-marked-char func) | |
1151 | (ibuffer-redisplay t))) | |
1152 | ||
1153 | (defun ibuffer-shrink-to-fit (&optional owin) | |
1154 | (fit-window-to-buffer nil (when owin (/ (frame-height) | |
1155 | (length (window-list (selected-frame))))))) | |
1156 | ||
1157 | (defun ibuffer-confirm-operation-on (operation names) | |
1158 | "Display a buffer asking whether to perform OPERATION on NAMES." | |
1159 | (or ibuffer-expert | |
1160 | (if (= (length names) 1) | |
1161 | (y-or-n-p (format "Really %s buffer %s? " operation (car names))) | |
1162 | (let ((buf (get-buffer-create "*Ibuffer confirmation*"))) | |
1163 | (with-current-buffer buf | |
1164 | (setq buffer-read-only nil) | |
1165 | (erase-buffer) | |
1166 | (ibuffer-columnize-and-insert-list names) | |
1167 | (goto-char (point-min)) | |
1168 | (setq buffer-read-only t)) | |
4e4a724c | 1169 | (let ((lastwin (car (last (window-list nil 'nomini))))) |
25d2f683 CW |
1170 | ;; Now attempt to display the buffer... |
1171 | (save-window-excursion | |
1172 | (select-window lastwin) | |
1173 | ;; The window might be too small to split; in that case, | |
7ad5b902 | 1174 | ;; try a few times to increase its size before giving up. |
25d2f683 CW |
1175 | (let ((attempts 0) |
1176 | (trying t)) | |
1177 | (while trying | |
1178 | (condition-case err | |
1179 | (progn | |
1180 | (split-window) | |
1181 | (setq trying nil)) | |
1182 | (error | |
1183 | ;; Handle a failure | |
1184 | (if (or (> (incf attempts) 4) | |
1185 | (and (stringp (cadr err)) | |
71296446 | 1186 | ;; This definitely falls in the |
4e4a724c | 1187 | ;; ghetto hack category... |
25d2f683 CW |
1188 | (not (string-match "too small" (cadr err))))) |
1189 | (apply #'signal err) | |
1190 | (enlarge-window 3)))))) | |
25d2f683 CW |
1191 | (select-window (next-window)) |
1192 | (switch-to-buffer buf) | |
1193 | (unwind-protect | |
1194 | (progn | |
1195 | (fit-window-to-buffer) | |
1196 | (y-or-n-p (format "Really %s %d buffers? " | |
1197 | operation (length names)))) | |
1198 | (kill-buffer buf)))))))) | |
1199 | ||
1200 | (defsubst ibuffer-map-lines-nomodify (function) | |
1201 | "As `ibuffer-map-lines', but don't set the modification flag." | |
1202 | (ibuffer-map-lines function t)) | |
1203 | ||
1204 | (defun ibuffer-buffer-names-with-mark (mark) | |
1205 | (let ((ibuffer-buffer-names-with-mark-result nil)) | |
1206 | (ibuffer-map-lines-nomodify | |
4e4a724c | 1207 | #'(lambda (buf mk) |
25d2f683 CW |
1208 | (when (char-equal mark mk) |
1209 | (push (buffer-name buf) | |
1210 | ibuffer-buffer-names-with-mark-result)))) | |
1211 | ibuffer-buffer-names-with-mark-result)) | |
1212 | ||
1213 | (defsubst ibuffer-marked-buffer-names () | |
1214 | (ibuffer-buffer-names-with-mark ibuffer-marked-char)) | |
1215 | ||
1216 | (defsubst ibuffer-deletion-marked-buffer-names () | |
1217 | (ibuffer-buffer-names-with-mark ibuffer-deletion-char)) | |
1218 | ||
1219 | (defun ibuffer-count-marked-lines (&optional all) | |
1220 | (if all | |
1221 | (ibuffer-map-lines-nomodify | |
57c9cc3e | 1222 | #'(lambda (buf mark) |
972b8f82 | 1223 | (not (char-equal mark ?\s)))) |
25d2f683 | 1224 | (ibuffer-map-lines-nomodify |
57c9cc3e | 1225 | #'(lambda (buf mark) |
25d2f683 CW |
1226 | (char-equal mark ibuffer-marked-char))))) |
1227 | ||
1228 | (defsubst ibuffer-count-deletion-lines () | |
1229 | (ibuffer-map-lines-nomodify | |
57c9cc3e | 1230 | #'(lambda (buf mark) |
25d2f683 CW |
1231 | (char-equal mark ibuffer-deletion-char)))) |
1232 | ||
1233 | (defsubst ibuffer-map-deletion-lines (func) | |
1234 | (ibuffer-map-on-mark ibuffer-deletion-char func)) | |
1235 | ||
87a6a53a JPW |
1236 | (defsubst ibuffer-assert-ibuffer-mode () |
1237 | (assert (derived-mode-p 'ibuffer-mode))) | |
1238 | ||
92cb2eaf JPW |
1239 | (defun ibuffer-buffer-file-name () |
1240 | (or buffer-file-name | |
1241 | (let ((dirname (or (and (boundp 'dired-directory) | |
1242 | (if (stringp dired-directory) | |
1243 | dired-directory | |
1244 | (car dired-directory))) | |
414408cd | 1245 | (bound-and-true-p list-buffers-directory)))) |
92cb2eaf JPW |
1246 | (and dirname (expand-file-name dirname))) |
1247 | "")) | |
1248 | ||
fd225d80 | 1249 | (define-ibuffer-op ibuffer-do-save () |
25d2f683 CW |
1250 | "Save marked buffers as with `save-buffer'." |
1251 | (:complex t | |
1252 | :opstring "saved" | |
1253 | :modifier-p :maybe) | |
1254 | (when (buffer-modified-p buf) | |
1255 | (if (not (with-current-buffer buf | |
1256 | buffer-file-name)) | |
1257 | ;; handle the case where we're prompted | |
1258 | ;; for a file name | |
1259 | (save-window-excursion | |
1260 | (switch-to-buffer buf) | |
1261 | (save-buffer)) | |
1262 | (with-current-buffer buf | |
1263 | (save-buffer)))) | |
1264 | t) | |
1265 | ||
fd225d80 | 1266 | (define-ibuffer-op ibuffer-do-toggle-modified () |
25d2f683 CW |
1267 | "Toggle modification flag of marked buffers." |
1268 | (:opstring "(un)marked as modified" | |
1269 | :modifier-p t) | |
1270 | (set-buffer-modified-p (not (buffer-modified-p)))) | |
1271 | ||
92be491c RW |
1272 | (define-ibuffer-op ibuffer-do-toggle-read-only (&optional arg) |
1273 | "Toggle read only status in marked buffers. | |
320d3e68 | 1274 | With optional ARG, make read-only only if ARG is positive." |
25d2f683 | 1275 | (:opstring "toggled read only status in" |
92be491c | 1276 | :interactive "P" |
25d2f683 | 1277 | :modifier-p t) |
92be491c | 1278 | (toggle-read-only arg)) |
25d2f683 | 1279 | |
fd225d80 | 1280 | (define-ibuffer-op ibuffer-do-delete () |
25d2f683 CW |
1281 | "Kill marked buffers as with `kill-this-buffer'." |
1282 | (:opstring "killed" | |
1283 | :active-opstring "kill" | |
1284 | :dangerous t | |
1285 | :complex t | |
1286 | :modifier-p t) | |
1287 | (if (kill-buffer buf) | |
1288 | 'kill | |
1289 | nil)) | |
1290 | ||
fd225d80 | 1291 | (define-ibuffer-op ibuffer-do-kill-on-deletion-marks () |
25d2f683 CW |
1292 | "Kill buffers marked for deletion as with `kill-this-buffer'." |
1293 | (:opstring "killed" | |
1294 | :active-opstring "kill" | |
1295 | :dangerous t | |
1296 | :complex t | |
1297 | :mark :deletion | |
1298 | :modifier-p t) | |
1299 | (if (kill-buffer buf) | |
1300 | 'kill | |
1301 | nil)) | |
1302 | ||
1303 | (defun ibuffer-unmark-all (mark) | |
1304 | "Unmark all buffers with mark MARK." | |
1305 | (interactive "cRemove marks (RET means all):") | |
1306 | (if (= (ibuffer-count-marked-lines t) 0) | |
1307 | (message "No buffers marked; use 'm' to mark a buffer") | |
1308 | (cond | |
1309 | ((char-equal mark ibuffer-marked-char) | |
1310 | (ibuffer-map-marked-lines | |
57c9cc3e | 1311 | #'(lambda (buf mark) |
972b8f82 | 1312 | (ibuffer-set-mark-1 ?\s) |
25d2f683 CW |
1313 | t))) |
1314 | ((char-equal mark ibuffer-deletion-char) | |
1315 | (ibuffer-map-deletion-lines | |
57c9cc3e | 1316 | #'(lambda (buf mark) |
972b8f82 | 1317 | (ibuffer-set-mark-1 ?\s) |
25d2f683 CW |
1318 | t))) |
1319 | (t | |
1320 | (ibuffer-map-lines | |
57c9cc3e | 1321 | #'(lambda (buf mark) |
972b8f82 JB |
1322 | (when (not (char-equal mark ?\s)) |
1323 | (ibuffer-set-mark-1 ?\s)) | |
25d2f683 CW |
1324 | t))))) |
1325 | (ibuffer-redisplay t)) | |
1326 | ||
b5cd37ea | 1327 | (defun ibuffer-toggle-marks (&optional group) |
25d2f683 CW |
1328 | "Toggle which buffers are marked. |
1329 | In other words, unmarked buffers become marked, and marked buffers | |
cba63a2d CW |
1330 | become unmarked. |
1331 | If point is on a group name, then this function operates on that | |
1332 | group." | |
25d2f683 | 1333 | (interactive) |
cba63a2d CW |
1334 | (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name) |
1335 | (setq group it)) | |
25d2f683 CW |
1336 | (let ((count |
1337 | (ibuffer-map-lines | |
57c9cc3e | 1338 | #'(lambda (buf mark) |
25d2f683 | 1339 | (cond ((eq mark ibuffer-marked-char) |
972b8f82 | 1340 | (ibuffer-set-mark-1 ?\s) |
25d2f683 | 1341 | nil) |
972b8f82 | 1342 | ((eq mark ?\s) |
25d2f683 CW |
1343 | (ibuffer-set-mark-1 ibuffer-marked-char) |
1344 | t) | |
1345 | (t | |
b5cd37ea CW |
1346 | nil))) |
1347 | nil group))) | |
25d2f683 CW |
1348 | (message "%s buffers marked" count)) |
1349 | (ibuffer-redisplay t)) | |
1350 | ||
1351 | (defun ibuffer-mark-forward (arg) | |
cba63a2d CW |
1352 | "Mark the buffer on this line, and move forward ARG lines. |
1353 | If point is on a group name, this function operates on that group." | |
25d2f683 CW |
1354 | (interactive "P") |
1355 | (ibuffer-mark-interactive arg ibuffer-marked-char 1)) | |
1356 | ||
1357 | (defun ibuffer-unmark-forward (arg) | |
cba63a2d CW |
1358 | "Unmark the buffer on this line, and move forward ARG lines. |
1359 | If point is on a group name, this function operates on that group." | |
25d2f683 | 1360 | (interactive "P") |
972b8f82 | 1361 | (ibuffer-mark-interactive arg ?\s 1)) |
25d2f683 CW |
1362 | |
1363 | (defun ibuffer-unmark-backward (arg) | |
cba63a2d CW |
1364 | "Unmark the buffer on this line, and move backward ARG lines. |
1365 | If point is on a group name, this function operates on that group." | |
25d2f683 | 1366 | (interactive "P") |
972b8f82 | 1367 | (ibuffer-mark-interactive arg ?\s -1)) |
25d2f683 CW |
1368 | |
1369 | (defun ibuffer-mark-interactive (arg mark movement) | |
87a6a53a | 1370 | (ibuffer-assert-ibuffer-mode) |
34a4faa0 | 1371 | (or arg (setq arg 1)) |
cba63a2d CW |
1372 | (ibuffer-forward-line 0) |
1373 | (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name) | |
1374 | (progn | |
1375 | (require 'ibuf-ext) | |
1376 | (ibuffer-mark-on-buffer #'identity mark it)) | |
4e4a724c | 1377 | (ibuffer-forward-line 0 t) |
cba63a2d CW |
1378 | (let ((inhibit-read-only t)) |
1379 | (while (> arg 0) | |
1380 | (ibuffer-set-mark mark) | |
1381 | (ibuffer-forward-line movement t) | |
1382 | (setq arg (1- arg)))))) | |
25d2f683 CW |
1383 | |
1384 | (defun ibuffer-set-mark (mark) | |
87a6a53a | 1385 | (ibuffer-assert-ibuffer-mode) |
25d2f683 CW |
1386 | (let ((inhibit-read-only t)) |
1387 | (ibuffer-set-mark-1 mark) | |
1388 | (setq ibuffer-did-modification t) | |
559ac4c1 CW |
1389 | (ibuffer-redisplay-current) |
1390 | (beginning-of-line))) | |
25d2f683 CW |
1391 | |
1392 | (defun ibuffer-set-mark-1 (mark) | |
1393 | (let ((beg (line-beginning-position)) | |
1394 | (end (line-end-position))) | |
1395 | (put-text-property beg end 'ibuffer-properties | |
1396 | (list (ibuffer-current-buffer) | |
1397 | mark)))) | |
1398 | ||
1399 | (defun ibuffer-mark-for-delete (arg) | |
cba63a2d CW |
1400 | "Mark the buffers on ARG lines forward for deletion. |
1401 | If point is on a group name, this function operates on that group." | |
25d2f683 CW |
1402 | (interactive "P") |
1403 | (ibuffer-mark-interactive arg ibuffer-deletion-char 1)) | |
1404 | ||
1405 | (defun ibuffer-mark-for-delete-backwards (arg) | |
cba63a2d CW |
1406 | "Mark the buffers on ARG lines backward for deletion. |
1407 | If point is on a group name, this function operates on that group." | |
25d2f683 CW |
1408 | (interactive "P") |
1409 | (ibuffer-mark-interactive arg ibuffer-deletion-char -1)) | |
1410 | ||
1411 | (defun ibuffer-current-buffer (&optional must-be-live) | |
1412 | (let ((buf (car (get-text-property (line-beginning-position) | |
1413 | 'ibuffer-properties)))) | |
b5cd37ea CW |
1414 | (when must-be-live |
1415 | (if (bufferp buf) | |
1416 | (unless (buffer-live-p buf) | |
1388485d | 1417 | (error "Buffer %s has been killed; %s" buf (substitute-command-keys "use `\\[ibuffer-update]' to update"))) |
b5cd37ea | 1418 | (error "No buffer on this line"))) |
25d2f683 | 1419 | buf)) |
523304ed CW |
1420 | |
1421 | (defun ibuffer-active-formats-name () | |
1422 | (if (boundp 'ibuffer-filter-format-alist) | |
1423 | (let ((ret nil)) | |
1424 | (dolist (filter ibuffer-filtering-qualifiers ret) | |
1425 | (let ((val (assq (car filter) ibuffer-filter-format-alist))) | |
1426 | (when val | |
1427 | (setq ret (car filter))))) | |
1428 | (if ret | |
1429 | ret | |
1430 | :ibuffer-formats)) | |
1431 | :ibuffer-formats)) | |
1432 | ||
1433 | (defun ibuffer-current-formats (uncompiledp) | |
1434 | (let* ((name (ibuffer-active-formats-name))) | |
1435 | (ibuffer-check-formats) | |
1436 | (if (eq name :ibuffer-formats) | |
1437 | (if uncompiledp | |
1438 | ibuffer-formats | |
1439 | ibuffer-compiled-formats) | |
1440 | (cadr (assq name | |
1441 | (if uncompiledp | |
1442 | ibuffer-filter-format-alist | |
1443 | ibuffer-compiled-filter-formats)))))) | |
71296446 | 1444 | |
523304ed | 1445 | (defun ibuffer-current-format (&optional uncompiledp) |
25d2f683 CW |
1446 | (or ibuffer-current-format |
1447 | (setq ibuffer-current-format 0)) | |
4e4a724c | 1448 | (nth ibuffer-current-format (ibuffer-current-formats uncompiledp))) |
25d2f683 CW |
1449 | |
1450 | (defun ibuffer-expand-format-entry (form) | |
1451 | (if (or (consp form) | |
1452 | (symbolp form)) | |
4e4a724c JPW |
1453 | (let ((sym (intern (concat "ibuffer-make-column-" |
1454 | (symbol-name (if (consp form) | |
1455 | (car form) | |
1456 | form)))))) | |
1457 | (unless (or (fboundp sym) | |
1458 | (assq sym ibuffer-inline-columns)) | |
1459 | (error "Unknown column %s in ibuffer-formats" form)) | |
1460 | (let (min max align elide) | |
1461 | (if (consp form) | |
1462 | (setq min (or (nth 1 form) 0) | |
1463 | max (or (nth 2 form) -1) | |
1464 | align (or (nth 3 form) :left) | |
1465 | elide (or (nth 4 form) nil)) | |
1466 | (setq min 0 | |
1467 | max -1 | |
1468 | align :left | |
1469 | elide nil)) | |
1470 | (list sym min max align elide))) | |
25d2f683 | 1471 | form)) |
71296446 | 1472 | |
25d2f683 | 1473 | (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p) |
545aad2f | 1474 | (let ((ellipsis (propertize ibuffer-eliding-string 'font-lock-face 'bold))) |
63f0a166 | 1475 | (if (or elide (with-no-warnings ibuffer-elide-long-columns)) |
25d2f683 CW |
1476 | `(if (> strlen 5) |
1477 | ,(if from-end-p | |
1478 | `(concat ,ellipsis | |
1479 | (substring ,strvar | |
1480 | (length ibuffer-eliding-string))) | |
1481 | `(concat | |
1482 | (substring ,strvar 0 (- strlen ,(length ellipsis))) | |
1483 | ,ellipsis)) | |
1484 | ,strvar) | |
1485 | strvar))) | |
1486 | ||
1487 | (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p) | |
1488 | (if from-end-p | |
1489 | `(substring str | |
1490 | (- strlen ,maxvar)) | |
1491 | `(substring ,strvar 0 ,maxvar))) | |
1492 | ||
1493 | (defun ibuffer-compile-make-format-form (strvar widthform alignment) | |
972b8f82 JB |
1494 | (let* ((left `(make-string tmp2 ?\s)) |
1495 | (right `(make-string (- tmp1 tmp2) ?\s))) | |
25d2f683 CW |
1496 | `(progn |
1497 | (setq tmp1 ,widthform | |
1498 | tmp2 (/ tmp1 2)) | |
1499 | ,(case alignment | |
1500 | (:right `(concat ,left ,right ,strvar)) | |
1501 | (:center `(concat ,left ,strvar ,right)) | |
1502 | (:left `(concat ,strvar ,left ,right)) | |
1503 | (t (error "Invalid alignment %s" alignment)))))) | |
1504 | ||
1505 | (defun ibuffer-compile-format (format) | |
1506 | (let ((result nil) | |
cb059426 CW |
1507 | ;; We use these variables to keep track of which variables |
1508 | ;; inside the generated function we need to bind, since | |
1509 | ;; binding variables in Emacs takes time. | |
1510 | str-used tmp1-used tmp2-used global-strlen-used) | |
25d2f683 CW |
1511 | (dolist (form format) |
1512 | (push | |
cb059426 CW |
1513 | ;; Generate a form based on a particular format entry, like |
1514 | ;; " ", mark, or (mode 16 16 :right). | |
25d2f683 | 1515 | (if (stringp form) |
cb059426 | 1516 | ;; It's a string; all we need to do is insert it. |
25d2f683 CW |
1517 | `(insert ,form) |
1518 | (let* ((form (ibuffer-expand-format-entry form)) | |
1519 | (sym (nth 0 form)) | |
1520 | (min (nth 1 form)) | |
1521 | (max (nth 2 form)) | |
1522 | (align (nth 3 form)) | |
1523 | (elide (nth 4 form))) | |
1524 | (let* ((from-end-p (when (minusp min) | |
1525 | (setq min (- min)) | |
1526 | t)) | |
1527 | (letbindings nil) | |
1528 | (outforms nil) | |
1529 | minform | |
1530 | maxform | |
1531 | min-used max-used strlen-used) | |
1532 | (when (or (not (integerp min)) (>= min 0)) | |
cb059426 CW |
1533 | ;; This is a complex case; they want it limited to a |
1534 | ;; minimum size. | |
25d2f683 CW |
1535 | (setq min-used t) |
1536 | (setq str-used t strlen-used t global-strlen-used t | |
1537 | tmp1-used t tmp2-used t) | |
cb059426 | 1538 | ;; Generate code to limit the string to a minimum size. |
25d2f683 CW |
1539 | (setq minform `(progn |
1540 | (setq str | |
1541 | ,(ibuffer-compile-make-format-form | |
1542 | 'str | |
1543 | `(- ,(if (integerp min) | |
1544 | min | |
1545 | 'min) | |
1546 | strlen) | |
1547 | align))))) | |
1548 | (when (or (not (integerp max)) (> max 0)) | |
1549 | (setq str-used t max-used t) | |
cb059426 | 1550 | ;; Generate code to limit the string to a maximum size. |
25d2f683 CW |
1551 | (setq maxform `(progn |
1552 | (setq str | |
1553 | ,(ibuffer-compile-make-substring-form | |
1554 | 'str | |
1555 | (if (integerp max) | |
1556 | max | |
1557 | 'max) | |
1558 | from-end-p)) | |
1559 | (setq strlen (length str)) | |
1560 | (setq str | |
1561 | ,(ibuffer-compile-make-eliding-form 'str | |
1562 | elide | |
1563 | from-end-p))))) | |
cb059426 CW |
1564 | ;; Now, put these forms together with the rest of the code. |
1565 | (let ((callform | |
1566 | ;; Is this an "inline" column? This means we have | |
1567 | ;; to get the code from the | |
1568 | ;; `ibuffer-inline-columns' alist and insert it | |
1569 | ;; into our generated code. Otherwise, we just | |
1570 | ;; generate a call to the column function. | |
1571 | (ibuffer-aif (assq sym ibuffer-inline-columns) | |
4e4a724c JPW |
1572 | (nth 1 it) |
1573 | `(,sym buffer mark))) | |
cb059426 CW |
1574 | ;; You're not expected to understand this. Hell, I |
1575 | ;; don't even understand it, and I wrote it five | |
1576 | ;; minutes ago. | |
1577 | (insertgenfn (ibuffer-aif (get sym 'ibuffer-column-summarizer) | |
4e4a724c JPW |
1578 | ;; I really, really wish Emacs Lisp had closures. |
1579 | (lambda (arg sym) | |
1580 | `(insert | |
1581 | (let ((ret ,arg)) | |
1582 | (put ',sym 'ibuffer-column-summary | |
1583 | (cons ret (get ',sym 'ibuffer-column-summary))) | |
1584 | ret))) | |
545aad2f CW |
1585 | (lambda (arg sym) |
1586 | `(insert ,arg)))) | |
25d2f683 CW |
1587 | (mincompform `(< strlen ,(if (integerp min) |
1588 | min | |
1589 | 'min))) | |
1590 | (maxcompform `(> strlen ,(if (integerp max) | |
1591 | max | |
1592 | 'max)))) | |
4e4a724c JPW |
1593 | (if (or min-used max-used) |
1594 | ;; The complex case, where we have to limit the | |
1595 | ;; form to a maximum or minimum size. | |
1596 | (progn | |
1597 | (when (and min-used (not (integerp min))) | |
1598 | (push `(min ,min) letbindings)) | |
1599 | (when (and max-used (not (integerp max))) | |
1600 | (push `(max ,max) letbindings)) | |
1601 | (push | |
1602 | (if (and min-used max-used) | |
1603 | `(if ,mincompform | |
1604 | ,minform | |
1605 | (if ,maxcompform | |
1606 | ,maxform)) | |
1607 | (if min-used | |
1608 | `(when ,mincompform | |
1609 | ,minform) | |
1610 | `(when ,maxcompform | |
1611 | ,maxform))) | |
1612 | outforms) | |
1613 | (push (append | |
1614 | `(setq str ,callform) | |
1615 | (when strlen-used | |
1616 | `(strlen (length str)))) | |
1617 | outforms) | |
1618 | (setq outforms | |
1619 | (append outforms (list (funcall insertgenfn 'str sym))))) | |
1620 | ;; The simple case; just insert the string. | |
1621 | (push (funcall insertgenfn callform sym) outforms)) | |
1622 | ;; Finally, return a `let' form which binds the | |
1623 | ;; variables in `letbindings', and contains all the | |
1624 | ;; code in `outforms'. | |
1625 | `(let ,letbindings | |
1626 | ,@outforms))))) | |
25d2f683 CW |
1627 | result)) |
1628 | (setq result | |
cb059426 | 1629 | ;; We don't want to unconditionally load the byte-compiler. |
25d2f683 CW |
1630 | (funcall (if (or ibuffer-always-compile-formats |
1631 | (featurep 'bytecomp)) | |
1632 | #'byte-compile | |
1633 | #'identity) | |
cb059426 CW |
1634 | ;; Here, we actually create a lambda form which |
1635 | ;; inserts all the generated forms for each entry | |
1636 | ;; in the format string. | |
25d2f683 | 1637 | (nconc (list 'lambda '(buffer mark)) |
d99b259b | 1638 | `((let ,(append (when str-used |
25d2f683 CW |
1639 | '(str)) |
1640 | (when global-strlen-used | |
1641 | '(strlen)) | |
1642 | (when tmp1-used | |
1643 | '(tmp1)) | |
1644 | (when tmp2-used | |
1645 | '(tmp2))) | |
1646 | ,@(nreverse result)))))))) | |
1647 | ||
25d2f683 CW |
1648 | (defun ibuffer-recompile-formats () |
1649 | "Recompile `ibuffer-formats'." | |
1650 | (interactive) | |
1651 | (setq ibuffer-compiled-formats | |
4e4a724c | 1652 | (mapcar #'ibuffer-compile-format ibuffer-formats)) |
523304ed CW |
1653 | (when (boundp 'ibuffer-filter-format-alist) |
1654 | (setq ibuffer-compiled-filter-formats | |
1655 | (mapcar #'(lambda (entry) | |
1656 | (cons (car entry) | |
1657 | (mapcar #'(lambda (formats) | |
1658 | (mapcar #'ibuffer-compile-format formats)) | |
1659 | (cdr entry)))) | |
1660 | ibuffer-filter-format-alist)))) | |
25d2f683 | 1661 | |
cb059426 CW |
1662 | (defun ibuffer-clear-summary-columns (format) |
1663 | (dolist (form format) | |
1664 | (ibuffer-awhen (and (consp form) | |
1665 | (get (car form) 'ibuffer-column-summarizer)) | |
1666 | (put (car form) 'ibuffer-column-summary nil)))) | |
71296446 | 1667 | |
25d2f683 | 1668 | (defun ibuffer-check-formats () |
523304ed CW |
1669 | (when (null ibuffer-formats) |
1670 | (error "No formats!")) | |
b5cd37ea CW |
1671 | (let ((ext-loaded (featurep 'ibuf-ext))) |
1672 | (when (or (null ibuffer-compiled-formats) | |
1673 | (null ibuffer-cached-formats) | |
1674 | (not (eq ibuffer-cached-formats ibuffer-formats)) | |
1675 | (null ibuffer-cached-eliding-string) | |
1676 | (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string)) | |
1677 | (eql 0 ibuffer-cached-elide-long-columns) | |
1678 | (not (eql ibuffer-cached-elide-long-columns | |
63f0a166 | 1679 | (with-no-warnings ibuffer-elide-long-columns))) |
b5cd37ea CW |
1680 | (and ext-loaded |
1681 | (not (eq ibuffer-cached-filter-formats | |
1682 | ibuffer-filter-format-alist)) | |
1683 | (and ibuffer-filter-format-alist | |
1684 | (null ibuffer-compiled-filter-formats)))) | |
1685 | (message "Formats have changed, recompiling...") | |
1686 | (ibuffer-recompile-formats) | |
1687 | (setq ibuffer-cached-formats ibuffer-formats | |
1688 | ibuffer-cached-eliding-string ibuffer-eliding-string | |
63f0a166 | 1689 | ibuffer-cached-elide-long-columns (with-no-warnings ibuffer-elide-long-columns)) |
b5cd37ea CW |
1690 | (when ext-loaded |
1691 | (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist)) | |
1692 | (message "Formats have changed, recompiling...done")))) | |
25d2f683 CW |
1693 | |
1694 | (defvar ibuffer-inline-columns nil) | |
1695 | ||
1696 | (define-ibuffer-column mark (:name " " :inline t) | |
1697 | (string mark)) | |
1698 | ||
1699 | (define-ibuffer-column read-only (:name "R" :inline t) | |
1700 | (if buffer-read-only | |
34a4faa0 | 1701 | (string ibuffer-read-only-char) |
25d2f683 CW |
1702 | " ")) |
1703 | ||
1704 | (define-ibuffer-column modified (:name "M" :inline t) | |
1705 | (if (buffer-modified-p) | |
1706 | (string ibuffer-modified-char) | |
1707 | " ")) | |
1708 | ||
34a4faa0 JPW |
1709 | (define-ibuffer-column name |
1710 | (:inline t | |
f0b31589 | 1711 | :header-mouse-map ibuffer-name-header-map |
34a4faa0 JPW |
1712 | :props |
1713 | ('mouse-face 'highlight 'keymap ibuffer-name-map | |
1714 | 'ibuffer-name-column t | |
1715 | 'help-echo '(if tooltip-mode | |
1716 | "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer" | |
1717 | "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate")) | |
1718 | :summarizer | |
1719 | (lambda (strings) | |
1720 | (let ((bufs (length strings))) | |
1721 | (cond ((zerop bufs) "No buffers") | |
1722 | ((= 1 bufs) "1 buffer") | |
1723 | (t (format "%s buffers" bufs)))))) | |
545aad2f | 1724 | (propertize (buffer-name) 'font-lock-face (ibuffer-buffer-name-face buffer mark))) |
71296446 | 1725 | |
34a4faa0 JPW |
1726 | (define-ibuffer-column size |
1727 | (:inline t | |
f0b31589 | 1728 | :header-mouse-map ibuffer-size-header-map |
34a4faa0 JPW |
1729 | :summarizer |
1730 | (lambda (column-strings) | |
1731 | (let ((total 0)) | |
1732 | (dolist (string column-strings) | |
1733 | (setq total | |
1734 | ;; like, ewww ... | |
7ad938e7 | 1735 | (+ (float (string-to-number string)) |
34a4faa0 JPW |
1736 | total))) |
1737 | (format "%.0f" total)))) | |
25d2f683 CW |
1738 | (format "%s" (buffer-size))) |
1739 | ||
7ad938e7 JPW |
1740 | (define-ibuffer-column mode |
1741 | (:inline t | |
f0b31589 | 1742 | :header-mouse-map ibuffer-mode-header-map |
7ad938e7 JPW |
1743 | :props |
1744 | ('mouse-face 'highlight | |
1745 | 'keymap ibuffer-mode-name-map | |
1746 | 'help-echo "mouse-2: filter by this mode")) | |
23eabff6 | 1747 | (format-mode-line mode-name nil nil (current-buffer))) |
25d2f683 | 1748 | |
34a4faa0 JPW |
1749 | (define-ibuffer-column process |
1750 | (:summarizer | |
1751 | (lambda (strings) | |
1752 | (let ((total (length (delete "" strings)))) | |
1753 | (cond ((zerop total) "No processes") | |
1754 | ((= 1 total) "1 process") | |
1755 | (t (format "%d processes" total)))))) | |
96777edb CW |
1756 | (ibuffer-aif (get-buffer-process buffer) |
1757 | (format "(%s %s)" it (process-status it)) | |
34a4faa0 JPW |
1758 | "")) |
1759 | ||
1760 | (define-ibuffer-column filename | |
1761 | (:summarizer | |
1762 | (lambda (strings) | |
1763 | (let ((total (length (delete "" strings)))) | |
1764 | (cond ((zerop total) "No files") | |
1765 | ((= 1 total) "1 file") | |
1766 | (t (format "%d files" total)))))) | |
25d2f683 CW |
1767 | (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist)) |
1768 | (abbreviate-file-name | |
92cb2eaf | 1769 | (ibuffer-buffer-file-name)))) |
25d2f683 | 1770 | |
34a4faa0 JPW |
1771 | (define-ibuffer-column filename-and-process |
1772 | (:name "Filename/Process" | |
d5794180 | 1773 | :header-mouse-map ibuffer-filename/process-header-map |
34a4faa0 JPW |
1774 | :summarizer |
1775 | (lambda (strings) | |
1776 | (setq strings (delete "" strings)) | |
1777 | (let ((procs 0) | |
1778 | (files 0)) | |
1779 | (dolist (string strings) | |
1780 | (if (string-match "\\(\?:\\`(\[\[:ascii:\]\]\+)\\)" string) | |
1781 | (progn (setq procs (1+ procs)) | |
1782 | (if (< (match-end 0) (length string)) | |
1783 | (setq files (1+ files)))) | |
1784 | (setq files (1+ files)))) | |
1785 | (concat (cond ((zerop files) "No files") | |
1786 | ((= 1 files) "1 file") | |
1787 | (t (format "%d files" files))) | |
1788 | ", " | |
1789 | (cond ((zerop procs) "no processes") | |
1790 | ((= 1 procs) "1 process") | |
1791 | (t (format "%d processes" procs))))))) | |
fd225d80 | 1792 | (let ((proc (get-buffer-process buffer)) |
63e0bf5e | 1793 | (filename (ibuffer-make-column-filename buffer mark))) |
fd225d80 | 1794 | (if proc |
34a4faa0 | 1795 | (concat (propertize (format "(%s %s)" proc (process-status proc)) |
545aad2f | 1796 | 'font-lock-face 'italic) |
34a4faa0 JPW |
1797 | (if (> (length filename) 0) |
1798 | (format " %s" filename) | |
1799 | "")) | |
fd225d80 CW |
1800 | filename))) |
1801 | ||
25d2f683 | 1802 | (defun ibuffer-format-column (str width alignment) |
972b8f82 JB |
1803 | (let ((left (make-string (/ width 2) ?\s)) |
1804 | (right (make-string (- width (/ width 2)) ?\s))) | |
25d2f683 CW |
1805 | (case alignment |
1806 | (:right (concat left right str)) | |
1807 | (:center (concat left str right)) | |
1808 | (t (concat str left right))))) | |
1809 | ||
545aad2f | 1810 | (defun ibuffer-buffer-name-face (buf mark) |
fd225d80 | 1811 | (cond ((char-equal mark ibuffer-marked-char) |
545aad2f | 1812 | ibuffer-marked-face) |
fd225d80 | 1813 | ((char-equal mark ibuffer-deletion-char) |
545aad2f | 1814 | ibuffer-deletion-face) |
fd225d80 CW |
1815 | (t |
1816 | (let ((level -1) | |
fd225d80 CW |
1817 | result) |
1818 | (dolist (e ibuffer-fontification-alist result) | |
1819 | (when (and (> (car e) level) | |
1820 | (with-current-buffer buf | |
545aad2f | 1821 | (eval (nth 1 e)))) |
fd225d80 | 1822 | (setq level (car e) |
545aad2f | 1823 | result (nth 2 e)))))))) |
25d2f683 CW |
1824 | |
1825 | (defun ibuffer-insert-buffer-line (buffer mark format) | |
1826 | "Insert a line describing BUFFER and MARK using FORMAT." | |
87a6a53a | 1827 | (ibuffer-assert-ibuffer-mode) |
25d2f683 | 1828 | (let ((beg (point))) |
25d2f683 | 1829 | (funcall format buffer mark) |
cb059426 CW |
1830 | (put-text-property beg (point) 'ibuffer-properties (list buffer mark))) |
1831 | (insert "\n")) | |
25d2f683 | 1832 | |
cb059426 | 1833 | ;; This function knows a bit too much of the internals. It would be |
b5cd37ea | 1834 | ;; nice if it was all abstracted away. |
25d2f683 | 1835 | (defun ibuffer-redisplay-current () |
87a6a53a | 1836 | (ibuffer-assert-ibuffer-mode) |
25d2f683 CW |
1837 | (when (eobp) |
1838 | (forward-line -1)) | |
1839 | (beginning-of-line) | |
cb059426 CW |
1840 | (let ((curformat (mapcar #'ibuffer-expand-format-entry |
1841 | (ibuffer-current-format t)))) | |
1842 | (ibuffer-clear-summary-columns curformat) | |
1843 | (let ((buf (ibuffer-current-buffer))) | |
1844 | (when buf | |
1845 | (let ((mark (ibuffer-current-mark))) | |
ed233dd8 CW |
1846 | (save-excursion |
1847 | (delete-region (point) (1+ (line-end-position))) | |
1848 | (ibuffer-insert-buffer-line | |
1849 | buf mark | |
1850 | (ibuffer-current-format))) | |
cb059426 CW |
1851 | (when ibuffer-shrink-to-minimum-size |
1852 | (ibuffer-shrink-to-fit))))))) | |
71296446 | 1853 | |
25d2f683 CW |
1854 | (defun ibuffer-map-on-mark (mark func) |
1855 | (ibuffer-map-lines | |
57c9cc3e | 1856 | #'(lambda (buf mk) |
25d2f683 | 1857 | (if (char-equal mark mk) |
57c9cc3e | 1858 | (funcall func buf mark) |
25d2f683 CW |
1859 | nil)))) |
1860 | ||
b5cd37ea CW |
1861 | (defun ibuffer-map-lines (function &optional nomodify group) |
1862 | "Call FUNCTION for each buffer. | |
4837b516 | 1863 | Set the ibuffer modification flag unless NOMODIFY is non-nil. |
25d2f683 | 1864 | |
b5cd37ea CW |
1865 | If optional argument GROUP is non-nil, then only call FUNCTION on |
1866 | buffers in filtering group GROUP. | |
1867 | ||
4e4a724c JPW |
1868 | FUNCTION is called with two arguments: |
1869 | the buffer object itself and the current mark symbol." | |
87a6a53a | 1870 | (ibuffer-assert-ibuffer-mode) |
b5cd37ea CW |
1871 | (ibuffer-forward-line 0) |
1872 | (let* ((orig-target-line (1+ (count-lines (save-excursion | |
1873 | (goto-char (point-min)) | |
1874 | (ibuffer-forward-line 0) | |
1875 | (point)) | |
1876 | (point)))) | |
1877 | (target-line-offset orig-target-line) | |
1878 | (ibuffer-map-lines-total 0) | |
1879 | (ibuffer-map-lines-count 0)) | |
25d2f683 | 1880 | (unwind-protect |
57c9cc3e CW |
1881 | (progn |
1882 | (setq buffer-read-only nil) | |
1883 | (goto-char (point-min)) | |
4e4a724c | 1884 | (ibuffer-forward-line 0 t) |
57c9cc3e | 1885 | (while (and (not (eobp)) |
b5cd37ea CW |
1886 | (not (get-text-property (point) 'ibuffer-summary)) |
1887 | (progn | |
1888 | (ibuffer-forward-line 0 t) | |
1889 | (and (not (eobp)) | |
1890 | (not (get-text-property (point) 'ibuffer-summary))))) | |
57c9cc3e CW |
1891 | (let ((result |
1892 | (if (buffer-live-p (ibuffer-current-buffer)) | |
b5cd37ea CW |
1893 | (when (or (null group) |
1894 | (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group) | |
1895 | (equal group it))) | |
1896 | (save-excursion | |
1897 | (funcall function | |
1898 | (ibuffer-current-buffer) | |
1899 | (ibuffer-current-mark)))) | |
57c9cc3e CW |
1900 | ;; Kill the line if the buffer is dead |
1901 | 'kill))) | |
1902 | ;; A given mapping function should return: | |
1903 | ;; `nil' if it chose not to affect the buffer | |
1904 | ;; `kill' means the remove line from the buffer list | |
1905 | ;; `t' otherwise | |
1906 | (incf ibuffer-map-lines-total) | |
1907 | (cond ((null result) | |
1908 | (forward-line 1)) | |
1909 | ((eq result 'kill) | |
1910 | (delete-region (line-beginning-position) | |
1911 | (1+ (line-end-position))) | |
1912 | (incf ibuffer-map-lines-count) | |
1913 | (when (< ibuffer-map-lines-total | |
4e4a724c | 1914 | orig-target-line) |
b5cd37ea | 1915 | (decf target-line-offset))) |
57c9cc3e CW |
1916 | (t |
1917 | (incf ibuffer-map-lines-count) | |
1918 | (forward-line 1))))) | |
1919 | ibuffer-map-lines-count) | |
25d2f683 CW |
1920 | (progn |
1921 | (setq buffer-read-only t) | |
1922 | (unless nomodify | |
1923 | (set-buffer-modified-p nil)) | |
57c9cc3e CW |
1924 | (goto-char (point-min)) |
1925 | (ibuffer-forward-line 0) | |
b5cd37ea | 1926 | (ibuffer-forward-line (1- target-line-offset)))))) |
25d2f683 CW |
1927 | |
1928 | (defun ibuffer-get-marked-buffers () | |
1929 | "Return a list of buffer objects currently marked." | |
1930 | (delq nil | |
1931 | (mapcar #'(lambda (e) | |
1932 | (when (eq (cdr e) ibuffer-marked-char) | |
1933 | (car e))) | |
1934 | (ibuffer-current-state-list)))) | |
1935 | ||
d246cabf CW |
1936 | (defun ibuffer-current-state-list (&optional pos) |
1937 | "Return a list like (BUF . MARK) of all buffers in an ibuffer. | |
1938 | If POS is non-nil, return a list like (BUF MARK POINT), where POINT is | |
1939 | the value of point at the beginning of the line for that buffer." | |
25d2f683 CW |
1940 | (let ((ibuffer-current-state-list-tmp '())) |
1941 | ;; ah, if only we had closures. I bet this will mysteriously | |
1942 | ;; break later. Don't blame me. | |
d246cabf CW |
1943 | (if pos |
1944 | (ibuffer-map-lines-nomodify | |
1945 | #'(lambda (buf mark) | |
1946 | (when (buffer-live-p buf) | |
1947 | (push (list buf mark (point)) ibuffer-current-state-list-tmp)))) | |
1948 | (ibuffer-map-lines-nomodify | |
1949 | #'(lambda (buf mark) | |
1950 | (when (buffer-live-p buf) | |
1951 | (push (cons buf mark) ibuffer-current-state-list-tmp))))) | |
25d2f683 CW |
1952 | (nreverse ibuffer-current-state-list-tmp))) |
1953 | ||
851476d4 | 1954 | (defun ibuffer-current-buffers-with-marks (curbufs) |
25d2f683 CW |
1955 | "Return a list like (BUF . MARK) of all open buffers." |
1956 | (let ((bufs (ibuffer-current-state-list))) | |
1957 | (mapcar #'(lambda (buf) (let ((e (assq buf bufs))) | |
1958 | (if e | |
1959 | e | |
972b8f82 | 1960 | (cons buf ?\s)))) |
851476d4 | 1961 | curbufs))) |
25d2f683 CW |
1962 | |
1963 | (defun ibuffer-buf-matches-predicates (buf predicates) | |
1964 | (let ((hit nil) | |
1965 | (name (buffer-name buf))) | |
1966 | (dolist (pred predicates) | |
1967 | (when (if (stringp pred) | |
1968 | (string-match pred name) | |
1969 | (funcall pred buf)) | |
1970 | (setq hit t))) | |
1971 | hit)) | |
71296446 | 1972 | |
25d2f683 CW |
1973 | (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all) |
1974 | (let ((ext-loaded (featurep 'ibuf-ext))) | |
1975 | (delq nil | |
b5cd37ea CW |
1976 | (mapcar |
1977 | ;; element should be like (BUFFER . MARK) | |
1978 | #'(lambda (e) | |
1979 | (let* ((buf (car e))) | |
1980 | (when | |
1981 | ;; This takes precedence over anything else | |
1982 | (or (and ibuffer-always-show-last-buffer | |
4e4a724c JPW |
1983 | (eq last buf)) |
1984 | (funcall (if ext-loaded | |
1985 | #'ibuffer-ext-visible-p | |
1986 | #'ibuffer-visible-p) | |
1987 | buf all ibuffer-buf)) | |
b5cd37ea CW |
1988 | e))) |
1989 | bmarklist)))) | |
25d2f683 CW |
1990 | |
1991 | (defun ibuffer-visible-p (buf all &optional ibuffer-buf) | |
1992 | (and (or all | |
1993 | (not | |
1994 | (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates))) | |
1995 | (or ibuffer-view-ibuffer | |
4e4a724c | 1996 | (and ibuffer-buf |
25d2f683 CW |
1997 | (not (eq ibuffer-buf buf)))))) |
1998 | ||
1999 | ;; This function is a special case; it's not defined by | |
6081889e | 2000 | ;; `define-ibuffer-sorter'. |
25d2f683 CW |
2001 | (defun ibuffer-do-sort-by-recency () |
2002 | "Sort the buffers by last view time." | |
2003 | (interactive) | |
2004 | (setq ibuffer-sorting-mode 'recency) | |
e7820654 JPW |
2005 | (when (eq ibuffer-last-sorting-mode 'recency) |
2006 | (setq ibuffer-sorting-reversep (not ibuffer-sorting-reversep))) | |
2007 | (ibuffer-update nil t) | |
2008 | (setq ibuffer-last-sorting-mode 'recency)) | |
25d2f683 CW |
2009 | |
2010 | (defun ibuffer-update-format () | |
2011 | (when (null ibuffer-current-format) | |
2012 | (setq ibuffer-current-format 0)) | |
2013 | (when (null ibuffer-formats) | |
2014 | (error "Ibuffer error: no formats!"))) | |
2015 | ||
2016 | (defun ibuffer-switch-format () | |
2017 | "Switch the current display format." | |
2018 | (interactive) | |
87a6a53a | 2019 | (ibuffer-assert-ibuffer-mode) |
25d2f683 CW |
2020 | (unless (consp ibuffer-formats) |
2021 | (error "Ibuffer error: No formats!")) | |
2022 | (setq ibuffer-current-format | |
80a06d64 | 2023 | (if (>= ibuffer-current-format (1- (length (ibuffer-current-formats nil)))) |
25d2f683 CW |
2024 | 0 |
2025 | (1+ ibuffer-current-format))) | |
2026 | (ibuffer-update-format) | |
2027 | (ibuffer-redisplay t)) | |
2028 | ||
cb059426 | 2029 | (defun ibuffer-update-title-and-summary (format) |
87a6a53a | 2030 | (ibuffer-assert-ibuffer-mode) |
25d2f683 CW |
2031 | ;; Don't do funky font-lock stuff here |
2032 | (let ((after-change-functions nil)) | |
2033 | (if (get-text-property (point-min) 'ibuffer-title) | |
2034 | (delete-region (point-min) | |
2035 | (next-single-property-change | |
2036 | (point-min) 'ibuffer-title))) | |
2037 | (goto-char (point-min)) | |
fd225d80 | 2038 | (add-text-properties |
25d2f683 CW |
2039 | (point) |
2040 | (progn | |
2041 | (let ((opos (point))) | |
2042 | ;; Insert the title names. | |
cb059426 | 2043 | (dolist (element format) |
25d2f683 CW |
2044 | (insert |
2045 | (if (stringp element) | |
2046 | element | |
2047 | (let ((sym (car element)) | |
2048 | (min (cadr element)) | |
2049 | ;; (max (caddr element)) | |
2050 | (align (cadddr element))) | |
4e4a724c | 2051 | ;; Ignore a negative min when we're inserting the title |
25d2f683 CW |
2052 | (when (minusp min) |
2053 | (setq min (- min))) | |
2054 | (let* ((name (or (get sym 'ibuffer-column-name) | |
2055 | (error "Unknown column %s in ibuffer-formats" sym))) | |
f0b31589 DN |
2056 | (len (length name)) |
2057 | (hmap (get sym 'header-mouse-map)) | |
2058 | (strname (if (< len min) | |
2059 | (ibuffer-format-column name | |
2060 | (- min len) | |
2061 | align) | |
2062 | name))) | |
2063 | (when hmap | |
2064 | (setq | |
2065 | strname | |
2066 | (propertize strname 'mouse-face 'highlight 'keymap hmap))) | |
2067 | strname))))) | |
fd225d80 | 2068 | (add-text-properties opos (point) `(ibuffer-title-header t)) |
25d2f683 CW |
2069 | (insert "\n") |
2070 | ;; Add the underlines | |
2071 | (let ((str (save-excursion | |
2072 | (forward-line -1) | |
2073 | (beginning-of-line) | |
2074 | (buffer-substring (point) (line-end-position))))) | |
2075 | (apply #'insert (mapcar | |
2076 | #'(lambda (c) | |
972b8f82 | 2077 | (if (not (or (char-equal c ?\s) |
25d2f683 CW |
2078 | (char-equal c ?\n))) |
2079 | ?- | |
972b8f82 | 2080 | ?\s)) |
25d2f683 CW |
2081 | str))) |
2082 | (insert "\n")) | |
2083 | (point)) | |
545aad2f | 2084 | `(ibuffer-title t font-lock-face ,ibuffer-title-face)) |
cb059426 CW |
2085 | ;; Now, insert the summary columns. |
2086 | (goto-char (point-max)) | |
2087 | (if (get-text-property (1- (point-max)) 'ibuffer-summary) | |
2088 | (delete-region (previous-single-property-change | |
2089 | (point-max) 'ibuffer-summary) | |
2090 | (point-max))) | |
0740098c JPW |
2091 | (if ibuffer-display-summary |
2092 | (add-text-properties | |
2093 | (point) | |
2094 | (progn | |
2095 | (insert "\n") | |
2096 | (dolist (element format) | |
2097 | (insert | |
2098 | (if (stringp element) | |
972b8f82 | 2099 | (make-string (length element) ?\s) |
0740098c JPW |
2100 | (let ((sym (car element))) |
2101 | (let ((min (cadr element)) | |
2102 | ;; (max (caddr element)) | |
2103 | (align (cadddr element))) | |
2104 | ;; Ignore a negative min when we're inserting the title | |
2105 | (when (minusp min) | |
2106 | (setq min (- min))) | |
2107 | (let* ((summary (if (get sym 'ibuffer-column-summarizer) | |
2108 | (funcall (get sym 'ibuffer-column-summarizer) | |
2109 | (get sym 'ibuffer-column-summary)) | |
2110 | (make-string (length (get sym 'ibuffer-column-name)) | |
972b8f82 | 2111 | ?\s))) |
0740098c JPW |
2112 | (len (length summary))) |
2113 | (if (< len min) | |
2114 | (ibuffer-format-column summary | |
2115 | (- min len) | |
2116 | align) | |
2117 | summary))))))) | |
2118 | (point)) | |
2119 | `(ibuffer-summary t))))) | |
25d2f683 | 2120 | |
25d2f683 CW |
2121 | |
2122 | (defun ibuffer-redisplay (&optional silent) | |
2123 | "Redisplay the current list of buffers. | |
25d2f683 CW |
2124 | This does not show new buffers; use `ibuffer-update' for that. |
2125 | ||
7ad5b902 | 2126 | If optional arg SILENT is non-nil, do not display progress messages." |
25d2f683 | 2127 | (interactive) |
57c9cc3e | 2128 | (ibuffer-forward-line 0) |
25d2f683 CW |
2129 | (unless silent |
2130 | (message "Redisplaying current buffer list...")) | |
2131 | (let ((blist (ibuffer-current-state-list))) | |
2132 | (when (null blist) | |
2133 | (if (and (featurep 'ibuf-ext) | |
cba63a2d | 2134 | (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups)) |
25d2f683 CW |
2135 | (message "No buffers! (note: filtering in effect)") |
2136 | (error "No buffers!"))) | |
b5cd37ea | 2137 | (ibuffer-redisplay-engine blist t) |
25d2f683 | 2138 | (unless silent |
57c9cc3e CW |
2139 | (message "Redisplaying current buffer list...done")) |
2140 | (ibuffer-forward-line 0))) | |
25d2f683 CW |
2141 | |
2142 | (defun ibuffer-update (arg &optional silent) | |
2143 | "Regenerate the list of all buffers. | |
957237cb JPW |
2144 | |
2145 | Prefix arg non-nil means to toggle whether buffers that match | |
2146 | `ibuffer-maybe-show-predicates' should be displayed. | |
25d2f683 | 2147 | |
7ad5b902 | 2148 | If optional arg SILENT is non-nil, do not display progress messages." |
25d2f683 | 2149 | (interactive "P") |
957237cb JPW |
2150 | (if arg |
2151 | (setq ibuffer-display-maybe-show-predicates | |
2152 | (not ibuffer-display-maybe-show-predicates))) | |
57c9cc3e | 2153 | (ibuffer-forward-line 0) |
25d2f683 CW |
2154 | (let* ((bufs (buffer-list)) |
2155 | (blist (ibuffer-filter-buffers | |
94394914 JPW |
2156 | (current-buffer) |
2157 | (if (and | |
2158 | (cadr bufs) | |
2159 | (eq ibuffer-always-show-last-buffer | |
2160 | :nomini) | |
8e7dbfdb | 2161 | (minibufferp (cadr bufs))) |
da337a28 | 2162 | (caddr bufs) |
94394914 JPW |
2163 | (cadr bufs)) |
2164 | (ibuffer-current-buffers-with-marks bufs) | |
957237cb | 2165 | ibuffer-display-maybe-show-predicates))) |
25d2f683 CW |
2166 | (when (null blist) |
2167 | (if (and (featurep 'ibuf-ext) | |
2168 | ibuffer-filtering-qualifiers) | |
2169 | (message "No buffers! (note: filtering in effect)") | |
2170 | (error "No buffers!"))) | |
2171 | (unless silent | |
2172 | (message "Updating buffer list...")) | |
b5cd37ea | 2173 | (ibuffer-redisplay-engine blist arg) |
25d2f683 CW |
2174 | (unless silent |
2175 | (message "Updating buffer list...done"))) | |
2176 | (if (eq ibuffer-shrink-to-minimum-size 'onewindow) | |
2177 | (ibuffer-shrink-to-fit t) | |
2178 | (when ibuffer-shrink-to-minimum-size | |
2179 | (ibuffer-shrink-to-fit))) | |
6d11a78b SM |
2180 | (ibuffer-forward-line 0) |
2181 | ;; I tried to update this automatically from the mode-line-process format, | |
2182 | ;; but changing nil-ness of header-line-format while computing | |
2183 | ;; mode-line-format is asking a bit too much it seems. --Stef | |
2184 | (setq header-line-format | |
2185 | (and ibuffer-use-header-line | |
2186 | ibuffer-filtering-qualifiers | |
2187 | ibuffer-header-line-format))) | |
25d2f683 | 2188 | |
b5cd37ea CW |
2189 | (defun ibuffer-sort-bufferlist (bmarklist) |
2190 | (let* ((sortdat (assq ibuffer-sorting-mode | |
2191 | ibuffer-sorting-functions-alist)) | |
2192 | (func (caddr sortdat))) | |
2193 | (let ((result | |
2194 | ;; actually sort the buffers | |
2195 | (if (and sortdat func) | |
2196 | (sort bmarklist func) | |
2197 | bmarklist))) | |
2198 | ;; perhaps reverse the sorted buffer list | |
2199 | (if ibuffer-sorting-reversep | |
2200 | (nreverse result) | |
2201 | result)))) | |
2202 | ||
7fbac645 | 2203 | (defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist) |
b5cd37ea CW |
2204 | (add-text-properties |
2205 | (point) | |
2206 | (progn | |
2207 | (insert "[ " display-name " ]") | |
2208 | (point)) | |
fd225d80 CW |
2209 | `(ibuffer-filter-group-name |
2210 | ,name | |
545aad2f | 2211 | font-lock-face ,ibuffer-filter-group-name-face |
fd225d80 CW |
2212 | keymap ,ibuffer-mode-filter-group-map |
2213 | mouse-face highlight | |
1cd7affa JPW |
2214 | help-echo ,(let ((echo '(if tooltip-mode |
2215 | "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group" | |
ce3a4c83 | 2216 | "mouse-1: toggle marks mouse-2: hide/show"))) |
1cd7affa | 2217 | (if (> (length filter-string) 0) |
ce3a4c83 JPW |
2218 | `(concat ,filter-string |
2219 | (if tooltip-mode "\n" " ") | |
2220 | ,echo) | |
1cd7affa | 2221 | echo)))) |
b5cd37ea CW |
2222 | (insert "\n") |
2223 | (when bmarklist | |
2224 | (put-text-property | |
2225 | (point) | |
2226 | (progn | |
2227 | (dolist (entry bmarklist) | |
2228 | (ibuffer-insert-buffer-line (car entry) (cdr entry) format)) | |
2229 | (point)) | |
2230 | 'ibuffer-filter-group | |
2231 | name))) | |
2232 | ||
957237cb | 2233 | (defun ibuffer-redisplay-engine (bmarklist &optional ignore) |
87a6a53a | 2234 | (ibuffer-assert-ibuffer-mode) |
b5cd37ea CW |
2235 | (let* ((--ibuffer-insert-buffers-and-marks-format |
2236 | (ibuffer-current-format)) | |
2237 | (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry | |
2238 | (ibuffer-current-format t))) | |
2239 | (orig (count-lines (point-min) (point))) | |
2240 | ;; Inhibit font-lock caching tricks, since we're modifying the | |
2241 | ;; entire buffer at once | |
2242 | (after-change-functions nil) | |
2243 | (ext-loaded (featurep 'ibuf-ext)) | |
2244 | (bgroups (if ext-loaded | |
2245 | (ibuffer-generate-filter-groups bmarklist) | |
2246 | (list (cons "Default" bmarklist))))) | |
cb059426 | 2247 | (ibuffer-clear-summary-columns --ibuffer-expanded-format) |
25d2f683 CW |
2248 | (unwind-protect |
2249 | (progn | |
2250 | (setq buffer-read-only nil) | |
2251 | (erase-buffer) | |
2252 | (ibuffer-update-format) | |
b5cd37ea CW |
2253 | (dolist (group (nreverse bgroups)) |
2254 | (let* ((name (car group)) | |
2255 | (disabled (and ext-loaded | |
cba63a2d | 2256 | (member name ibuffer-hidden-filter-groups))) |
b5cd37ea | 2257 | (bmarklist (cdr group))) |
cba63a2d | 2258 | (unless (and (null bmarklist) |
b90a6a12 | 2259 | (not disabled) |
cba63a2d CW |
2260 | ext-loaded |
2261 | (null ibuffer-show-empty-filter-groups)) | |
2262 | (ibuffer-insert-filter-group | |
2263 | name | |
2264 | (if disabled (concat name " ...") name) | |
7fbac645 CW |
2265 | (if ext-loaded |
2266 | (ibuffer-format-filter-group-data name) | |
2267 | "") | |
cba63a2d CW |
2268 | --ibuffer-insert-buffers-and-marks-format |
2269 | (if disabled | |
2270 | nil | |
2271 | (ibuffer-sort-bufferlist bmarklist)))))) | |
cb059426 | 2272 | (ibuffer-update-title-and-summary --ibuffer-expanded-format)) |
25d2f683 CW |
2273 | (setq buffer-read-only t) |
2274 | (set-buffer-modified-p ibuffer-did-modification) | |
2275 | (setq ibuffer-did-modification nil) | |
2276 | (goto-line (1+ orig))))) | |
2277 | ||
2278 | (defun ibuffer-quit () | |
2279 | "Quit this `ibuffer' session. | |
4837b516 | 2280 | Try to restore the previous window configuration if |
4ed1f829 | 2281 | `ibuffer-restore-window-config-on-quit' is non-nil." |
25d2f683 | 2282 | (interactive) |
4ed1f829 | 2283 | (if ibuffer-restore-window-config-on-quit |
7ad938e7 | 2284 | (progn |
25d2f683 CW |
2285 | (bury-buffer) |
2286 | (unless (= (count-windows) 1) | |
4ed1f829 | 2287 | (set-window-configuration ibuffer-prev-window-config))) |
25d2f683 CW |
2288 | (bury-buffer))) |
2289 | ||
2290 | ;;;###autoload | |
2291 | (defun ibuffer-list-buffers (&optional files-only) | |
2292 | "Display a list of buffers, in another window. | |
2293 | If optional argument FILES-ONLY is non-nil, then add a filter for | |
2294 | buffers which are visiting a file." | |
2295 | (interactive "P") | |
2296 | (ibuffer t nil (when files-only | |
2297 | '((filename . ".*"))) t)) | |
2298 | ||
2299 | ;;;###autoload | |
2300 | (defun ibuffer-other-window (&optional files-only) | |
2301 | "Like `ibuffer', but displayed in another window by default. | |
2302 | If optional argument FILES-ONLY is non-nil, then add a filter for | |
2303 | buffers which are visiting a file." | |
2304 | (interactive "P") | |
2305 | (ibuffer t nil (when files-only | |
2306 | '((filename . ".*"))))) | |
2307 | ||
2308 | ;;;###autoload | |
b5cd37ea | 2309 | (defun ibuffer (&optional other-window-p name qualifiers noselect |
fd225d80 | 2310 | shrink filter-groups formats) |
972b8f82 | 2311 | "Begin using Ibuffer to edit a list of buffers. |
25d2f683 CW |
2312 | Type 'h' after entering ibuffer for more information. |
2313 | ||
972b8f82 JB |
2314 | All arguments are optional. |
2315 | OTHER-WINDOW-P says to use another window. | |
2316 | NAME specifies the name of the buffer (defaults to \"*Ibuffer*\"). | |
2317 | QUALIFIERS is an initial set of filtering qualifiers to use; | |
2318 | see `ibuffer-filtering-qualifiers'. | |
2319 | NOSELECT means don't select the Ibuffer buffer. | |
2320 | SHRINK means shrink the buffer to minimal size. The special | |
2321 | value `onewindow' means always use another window. | |
2322 | FILTER-GROUPS is an initial set of filtering groups to use; | |
2323 | see `ibuffer-filter-groups'. | |
2324 | FORMATS is the value to use for `ibuffer-formats'. | |
2325 | If specified, then the variable `ibuffer-formats' will have | |
2326 | that value locally in this buffer." | |
25d2f683 CW |
2327 | (interactive "P") |
2328 | (when ibuffer-use-other-window | |
34b8f593 | 2329 | (setq other-window-p t)) |
4ed1f829 | 2330 | (setq ibuffer-prev-window-config (current-window-configuration)) |
34a4faa0 | 2331 | (let ((buf (get-buffer-create (or name "*Ibuffer*")))) |
25d2f683 CW |
2332 | (if other-window-p |
2333 | (funcall (if noselect #'(lambda (buf) (display-buffer buf t)) #'pop-to-buffer) buf) | |
2334 | (funcall (if noselect #'display-buffer #'switch-to-buffer) buf)) | |
2335 | (with-current-buffer buf | |
b5cd37ea CW |
2336 | (save-selected-window |
2337 | ;; We switch to the buffer's window in order to be able | |
2338 | ;; to modify the value of point | |
fab0d308 | 2339 | (select-window (get-buffer-window buf 0)) |
34a4faa0 JPW |
2340 | (or (eq major-mode 'ibuffer-mode) |
2341 | (ibuffer-mode)) | |
4ed1f829 | 2342 | (setq ibuffer-restore-window-config-on-quit other-window-p) |
b5cd37ea CW |
2343 | (when shrink |
2344 | (setq ibuffer-shrink-to-minimum-size shrink)) | |
2345 | (when qualifiers | |
2346 | (require 'ibuf-ext) | |
2347 | (setq ibuffer-filtering-qualifiers qualifiers)) | |
2348 | (when filter-groups | |
2349 | (require 'ibuf-ext) | |
cba63a2d | 2350 | (setq ibuffer-filter-groups filter-groups)) |
fd225d80 CW |
2351 | (when formats |
2352 | (set (make-local-variable 'ibuffer-formats) formats)) | |
b5cd37ea CW |
2353 | (ibuffer-update nil) |
2354 | ;; Skip the group name by default. | |
2355 | (ibuffer-forward-line 0 t) | |
25d2f683 CW |
2356 | (unwind-protect |
2357 | (progn | |
b5cd37ea | 2358 | (setq buffer-read-only nil) |
7ad5b902 | 2359 | (run-hooks 'ibuffer-hook)) |
b5cd37ea CW |
2360 | (setq buffer-read-only t)) |
2361 | (unless ibuffer-expert | |
2362 | (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help")))))) | |
25d2f683 | 2363 | |
b23af469 | 2364 | (put 'ibuffer-mode 'mode-class 'special) |
25d2f683 CW |
2365 | (defun ibuffer-mode () |
2366 | "A major mode for viewing a list of buffers. | |
972b8f82 | 2367 | In Ibuffer, you can conveniently perform many operations on the |
25d2f683 CW |
2368 | currently open buffers, in addition to filtering your view to a |
2369 | particular subset of them, and sorting by various criteria. | |
2370 | ||
2371 | Operations on marked buffers: | |
2372 | ||
2373 | '\\[ibuffer-do-save]' - Save the marked buffers | |
2374 | '\\[ibuffer-do-view]' - View the marked buffers in this frame. | |
2375 | '\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame. | |
2376 | '\\[ibuffer-do-revert]' - Revert the marked buffers. | |
2377 | '\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers. | |
2378 | '\\[ibuffer-do-delete]' - Kill the marked buffers. | |
2379 | '\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked | |
2380 | buffers. | |
2381 | '\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers. | |
2382 | '\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression. | |
2383 | '\\[ibuffer-do-print]' - Print the marked buffers. | |
2384 | '\\[ibuffer-do-occur]' - List lines in all marked buffers which match | |
2385 | a given regexp (like the function `occur'). | |
2386 | '\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked | |
2387 | buffers to a shell command. | |
2388 | '\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked | |
2389 | buffers with the output of a shell command. | |
2390 | '\\[ibuffer-do-shell-command-file]' - Run a shell command with the | |
2391 | buffer's file as an argument. | |
2392 | '\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This | |
2393 | is a very flexible command. For example, if you want to make all | |
2394 | of the marked buffers read only, try using (toggle-read-only 1) as | |
2395 | the input form. | |
2396 | '\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form | |
2397 | is evaluated. | |
2398 | '\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer, | |
2399 | but don't kill the associated buffer. | |
2400 | '\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion. | |
2401 | ||
2402 | Marking commands: | |
2403 | ||
2404 | '\\[ibuffer-mark-forward]' - Mark the buffer at point. | |
2405 | '\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark | |
2406 | all unmarked buffers. | |
2407 | '\\[ibuffer-unmark-forward]' - Unmark the buffer at point. | |
2408 | '\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the | |
2409 | previous line. | |
2410 | '\\[ibuffer-unmark-all]' - Unmark all marked buffers. | |
2411 | '\\[ibuffer-mark-by-mode]' - Mark buffers by major mode. | |
2412 | '\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers. | |
2413 | This means that the buffer is modified, and has an associated file. | |
2414 | '\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers, | |
2415 | regardless of whether or not they have an associated file. | |
2416 | '\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and | |
2417 | ends with '*'. | |
2418 | '\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have | |
2419 | an associated file, but that file doesn't currently exist. | |
2420 | '\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers. | |
2421 | '\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode. | |
2422 | '\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc. | |
2423 | '\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'. | |
2424 | '\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion. | |
2425 | '\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp. | |
2426 | '\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp. | |
2427 | '\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp. | |
2428 | ||
2429 | Filtering commands: | |
2430 | ||
2431 | '\\[ibuffer-filter-by-mode]' - Add a filter by major mode. | |
5bc06df9 | 2432 | '\\[ibuffer-filter-by-used-mode]' - Add a filter by major mode now in use. |
25d2f683 CW |
2433 | '\\[ibuffer-filter-by-name]' - Add a filter by buffer name. |
2434 | '\\[ibuffer-filter-by-content]' - Add a filter by buffer content. | |
2435 | '\\[ibuffer-filter-by-filename]' - Add a filter by filename. | |
2436 | '\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size. | |
2437 | '\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size. | |
2438 | '\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate. | |
2439 | '\\[ibuffer-save-filters]' - Save the current filters with a name. | |
2440 | '\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters. | |
2441 | '\\[ibuffer-add-saved-filters]' - Add saved filters to current filters. | |
2442 | '\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR. | |
2443 | '\\[ibuffer-pop-filter]' - Remove the top filter. | |
2444 | '\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter. | |
2445 | '\\[ibuffer-decompose-filter]' - Break down the topmost filter. | |
2446 | '\\[ibuffer-filter-disable]' - Remove all filtering currently in effect. | |
cba63a2d CW |
2447 | |
2448 | Filter group commands: | |
2449 | ||
2450 | '\\[ibuffer-filters-to-filter-group]' - Create filter group from filters. | |
2451 | '\\[ibuffer-pop-filter-group]' - Remove top filter group. | |
b098e753 CW |
2452 | '\\[ibuffer-forward-filter-group]' - Move to the next filter group. |
2453 | '\\[ibuffer-backward-filter-group]' - Move to the previous filter group. | |
2454 | '\\[ibuffer-clear-filter-groups]' - Remove all active filter groups. | |
2455 | '\\[ibuffer-save-filter-groups]' - Save the current groups with a name. | |
2456 | '\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups. | |
2457 | '\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups. | |
71296446 | 2458 | |
25d2f683 CW |
2459 | Sorting commands: |
2460 | ||
2461 | '\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes. | |
2462 | '\\[ibuffer-invert-sorting]' - Reverse the current sorting order. | |
2463 | '\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically. | |
d5794180 | 2464 | '\\[ibuffer-do-sort-by-filename/process]' - Sort the buffers by the file name. |
25d2f683 CW |
2465 | '\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time. |
2466 | '\\[ibuffer-do-sort-by-size]' - Sort the buffers by size. | |
2467 | '\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode. | |
2468 | ||
2469 | Other commands: | |
2470 | ||
4c38df30 JPW |
2471 | '\\[ibuffer-update]' - Regenerate the list of all buffers. |
2472 | Prefix arg means to toggle whether buffers that match | |
2473 | `ibuffer-maybe-show-predicates' should be displayed. | |
2474 | ||
25d2f683 CW |
2475 | '\\[ibuffer-switch-format]' - Change the current display format. |
2476 | '\\[forward-line]' - Move point to the next line. | |
2477 | '\\[previous-line]' - Move point to the previous line. | |
25d2f683 CW |
2478 | '\\[ibuffer-quit]' - Bury the Ibuffer buffer. |
2479 | '\\[describe-mode]' - This help. | |
2480 | '\\[ibuffer-diff-with-file]' - View the differences between this buffer | |
2481 | and its associated file. | |
2482 | '\\[ibuffer-visit-buffer]' - View the buffer on this line. | |
2483 | '\\[ibuffer-visit-buffer-other-window]' - As above, but in another window. | |
2484 | '\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select | |
2485 | the new window. | |
2486 | '\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line. | |
2487 | ||
cba63a2d | 2488 | ** Information on Filtering: |
25d2f683 CW |
2489 | |
2490 | You can filter your ibuffer view via different critera. Each Ibuffer | |
2491 | buffer has its own stack of active filters. For example, suppose you | |
2492 | are working on an Emacs Lisp project. You can create an Ibuffer | |
2493 | buffer displays buffers in just `emacs-lisp' modes via | |
2494 | '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there | |
2495 | is just one entry on the filtering stack. | |
2496 | ||
2497 | You can also combine filters. The various filtering commands push a | |
2498 | new filter onto the stack, and the filters combine to show just | |
2499 | buffers which satisfy ALL criteria on the stack. For example, suppose | |
2500 | you only want to see buffers in `emacs-lisp' mode, whose names begin | |
2501 | with \"gnus\". You can accomplish this via: | |
2502 | '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET | |
2503 | \\[ibuffer-filter-by-name] ^gnus RET'. | |
2504 | ||
2505 | Additionally, you can OR the top two filters together with | |
2506 | '\\[ibuffer-or-filters]'. To see all buffers in either | |
2507 | `emacs-lisp-mode' or `lisp-interaction-mode', type: | |
2508 | ||
2509 | '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filter-by-mode] lisp-interaction-mode RET \\[ibuffer-or-filters]'. | |
2510 | ||
2511 | Filters can also be saved and restored using mnemonic names: see the | |
2512 | functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'. | |
2513 | ||
2514 | To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and | |
2515 | to disable all filtering currently in effect, use | |
cba63a2d CW |
2516 | '\\[ibuffer-filter-disable]'. |
2517 | ||
2518 | ** Filter Groups: | |
2519 | ||
2520 | Once one has mastered filters, the next logical step up is \"filter | |
2521 | groups\". A filter group is basically a named group of buffers which | |
2522 | match a filter, which are displayed together in an Ibuffer buffer. To | |
2523 | create a filter group, simply use the regular functions to create a | |
2524 | filter, and then type '\\[ibuffer-filters-to-filter-group]'. | |
2525 | ||
2526 | A quick example will make things clearer. Suppose that one wants to | |
2527 | group all of one's Emacs Lisp buffers together. To do this, type | |
2528 | ||
2529 | '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filters-to-filter-group] RET emacs lisp buffers RET' | |
2530 | ||
2531 | You may, of course, name the group whatever you want; it doesn't have | |
2532 | to be \"emacs lisp buffers\". Filter groups may be composed of any | |
2533 | arbitrary combination of filters. | |
2534 | ||
2535 | Just like filters themselves, filter groups act as a stack. Buffers | |
2536 | will not be displayed multiple times if they would be included in | |
2537 | multiple filter groups; instead, the first filter group is used. The | |
2538 | filter groups are displayed in this order of precedence. | |
2539 | ||
2540 | You may rearrange filter groups by using the regular | |
2541 | '\\[ibuffer-kill-line]' and '\\[ibuffer-yank]' pair. Yanked groups | |
2542 | will be inserted before the group at point." | |
25d2f683 CW |
2543 | (kill-all-local-variables) |
2544 | (use-local-map ibuffer-mode-map) | |
2545 | (setq major-mode 'ibuffer-mode) | |
2546 | (setq mode-name "Ibuffer") | |
23eabff6 | 2547 | ;; Include state info next to the mode name. |
e47b4224 | 2548 | (set (make-local-variable 'mode-line-process) |
56618a0a SM |
2549 | '(" by " |
2550 | (ibuffer-sorting-mode (:eval (symbol-name ibuffer-sorting-mode)) | |
23eabff6 SM |
2551 | "view time") |
2552 | (ibuffer-sorting-reversep " [rev]") | |
2553 | (ibuffer-auto-mode " (Auto)") | |
2554 | ;; Only list the filters if they're not already in the header-line. | |
2555 | (header-line-format | |
2556 | "" | |
2557 | (:eval (if (functionp 'ibuffer-format-qualifier) | |
2558 | (mapconcat 'ibuffer-format-qualifier | |
2559 | ibuffer-filtering-qualifiers "")))))) | |
6d11a78b SM |
2560 | ;; `ibuffer-update' puts this on header-line-format when needed. |
2561 | (setq ibuffer-header-line-format | |
2562 | ;; Display the part that won't be in the mode-line. | |
2563 | (list* "" mode-name | |
2564 | (mapcar (lambda (elem) | |
2565 | (if (eq (car-safe elem) 'header-line-format) | |
2566 | (nth 2 elem) elem)) | |
2567 | mode-line-process))) | |
23eabff6 | 2568 | |
25d2f683 CW |
2569 | (setq buffer-read-only t) |
2570 | (buffer-disable-undo) | |
3eda3649 | 2571 | (setq truncate-lines ibuffer-truncate-lines) |
25d2f683 CW |
2572 | ;; This makes things less ugly for Emacs 21 users with a non-nil |
2573 | ;; `show-trailing-whitespace'. | |
2574 | (setq show-trailing-whitespace nil) | |
4ba16127 JPW |
2575 | ;; disable `show-paren-mode' buffer-locally |
2576 | (if (bound-and-true-p show-paren-mode) | |
2577 | (set (make-local-variable 'show-paren-mode) nil)) | |
25d2f683 CW |
2578 | (set (make-local-variable 'revert-buffer-function) |
2579 | #'ibuffer-update) | |
2580 | (set (make-local-variable 'ibuffer-sorting-mode) | |
2581 | ibuffer-default-sorting-mode) | |
2582 | (set (make-local-variable 'ibuffer-sorting-reversep) | |
2583 | ibuffer-default-sorting-reversep) | |
2584 | (set (make-local-variable 'ibuffer-shrink-to-minimum-size) | |
2585 | ibuffer-default-shrink-to-minimum-size) | |
957237cb JPW |
2586 | (set (make-local-variable 'ibuffer-display-maybe-show-predicates) |
2587 | ibuffer-default-display-maybe-show-predicates) | |
25d2f683 | 2588 | (set (make-local-variable 'ibuffer-filtering-qualifiers) nil) |
cba63a2d CW |
2589 | (set (make-local-variable 'ibuffer-filter-groups) nil) |
2590 | (set (make-local-variable 'ibuffer-filter-group-kill-ring) nil) | |
2591 | (set (make-local-variable 'ibuffer-hidden-filter-groups) nil) | |
25d2f683 CW |
2592 | (set (make-local-variable 'ibuffer-compiled-formats) nil) |
2593 | (set (make-local-variable 'ibuffer-cached-formats) nil) | |
2594 | (set (make-local-variable 'ibuffer-cached-eliding-string) nil) | |
2595 | (set (make-local-variable 'ibuffer-cached-elide-long-columns) nil) | |
2596 | (set (make-local-variable 'ibuffer-current-format) nil) | |
4ed1f829 | 2597 | (set (make-local-variable 'ibuffer-restore-window-config-on-quit) nil) |
25d2f683 | 2598 | (set (make-local-variable 'ibuffer-did-modification) nil) |
b5cd37ea CW |
2599 | (set (make-local-variable 'ibuffer-tmp-hide-regexps) nil) |
2600 | (set (make-local-variable 'ibuffer-tmp-show-regexps) nil) | |
25d2f683 CW |
2601 | (define-key ibuffer-mode-map [menu-bar edit] 'undefined) |
2602 | (define-key ibuffer-mode-map [menu-bar operate] (cons "Operate" ibuffer-mode-operate-map)) | |
2603 | (ibuffer-update-format) | |
2604 | (when ibuffer-default-directory | |
2605 | (setq default-directory ibuffer-default-directory)) | |
214fee7a | 2606 | (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) |
23eabff6 | 2607 | (run-mode-hooks 'ibuffer-mode-hook)) |
25d2f683 CW |
2608 | |
2609 | (provide 'ibuffer) | |
2610 | ||
4e4a724c JPW |
2611 | (run-hooks 'ibuffer-load-hook) |
2612 | ||
25d2f683 CW |
2613 | ;; Local Variables: |
2614 | ;; coding: iso-8859-1 | |
2615 | ;; End: | |
2616 | ||
23eabff6 | 2617 | ;; arch-tag: 72581688-0603-4954-b8cf-837c700f62e8 |
25d2f683 | 2618 | ;;; ibuffer.el ends here |