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