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