1 ;;; ibuffer.el --- operate on buffers like dired
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5 ;; Author: Colin Walters <walters@verbum.org>
6 ;; Maintainer: John Paul Wallington <jpw@gnu.org>
8 ;; Keywords: buffer, convenience
10 ;; This file is part of GNU Emacs.
12 ;; This program is free software; you can redistribute it and/or
13 ;; modify it under the terms of the GNU General Public License as
14 ;; published by the Free Software Foundation; either version 2, or (at
15 ;; your option) any later version.
17 ;; This program is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program ; see the file COPYING. If not, write to
24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; ibuffer.el is an advanced replacement for the `buffer-menu' which
30 ;; is normally distributed with Emacs. Its interface is intended to
31 ;; be analogous to that of Dired.
43 "An advanced replacement for `buffer-menu'.
45 Ibuffer allows you to operate on buffers in a manner much like Dired.
46 Operations include sorting, marking by regular expression, and
47 the ability to filter the displayed buffers by various criteria."
50 (defcustom ibuffer-formats
'((mark modified read-only
" " (name 18 18 :left
:elide
)
51 " " (size 9 -
1 :right
)
52 " " (mode 16 16 :right
:elide
) " " filename-and-process
)
53 (mark " " (name 16 -
1) " " filename
))
54 "A list of ways to display buffer lines.
56 With Ibuffer, you are not limited to displaying just certain
57 attributes of a buffer such as size, name, and mode in a particular
58 order. Through this variable, you can completely customize and
59 control the appearance of an Ibuffer buffer. See also
60 `define-ibuffer-column', which allows you to define your own columns
63 This variable has the form
64 ((COLUMN COLUMN ...) (COLUMN COLUMN ...) ...)
65 Each element in `ibuffer-formats' should be a list containing COLUMN
66 specifiers. A COLUMN can be any of the following:
68 SYMBOL - A symbol naming the column. Predefined columns are:
69 mark modified read-only name size mode process filename
70 When you define your own columns using `define-ibuffer-column', just
71 use their name like the predefined columns here. This entry can
72 also be a function of two arguments, which should return a string.
73 The first argument is the buffer object, and the second is the mark
76 \"STRING\" - A literal string to display.
78 (SYMBOL MIN-SIZE MAX-SIZE &optional ALIGN ELIDE) - SYMBOL is a
79 symbol naming the column, and MIN-SIZE and MAX-SIZE are integers (or
80 functions of no arguments returning an integer) which constrict the
81 size of a column. If MAX-SIZE is -1, there is no upper bound. The
82 default values are 0 and -1, respectively. If MIN-SIZE is negative,
83 use the end of the string. The optional element ALIGN describes the
84 alignment of the column; it can be :left, :center or :right. The
85 optional element ELIDE describes whether or not to elide the column
86 if it is too long; valid values are :elide and nil. The default is
89 Some example of valid entries in `ibuffer-formats', with
90 description (also, feel free to try them out, and experiment with your
94 This format just displays the current mark (if any) and the name of
95 the buffer, separated by a space.
96 (mark modified read-only \" \" (name 16 16 :left) \" \" (size 6 -1 :right))
97 This format displays the current mark (if any), its modification and
98 read-only status, as well as the name of the buffer and its size. In
99 this format, the name is restricted to 16 characters (longer names
100 will be truncated, and shorter names will be padded with spaces), and
101 the name is also aligned to the left. The size of the buffer will
102 be padded with spaces up to a minimum of six characters, but there is
103 no upper limit on its size. The size will also be aligned to the
106 Thus, if you wanted to use these two formats, add
108 (setq ibuffer-formats '((mark \" \" name)
109 (mark modified read-only
110 (name 16 16 :left) (size 6 -1 :right))))
112 to your ~/.emacs file.
114 Using \\[ibuffer-switch-format], you can rotate the display between
115 the specified formats in the list."
119 (defcustom ibuffer-always-compile-formats
(featurep 'bytecomp
)
120 "If non-nil, then use the byte-compiler to optimize `ibuffer-formats'.
121 This will increase the redisplay speed, at the cost of loading the
122 elisp byte-compiler."
126 (defcustom ibuffer-fontification-alist
127 `((10 buffer-read-only font-lock-constant-face
)
128 (15 (string-match "^*" (buffer-name)) font-lock-keyword-face
)
129 (20 (and (string-match "^ " (buffer-name))
130 (null buffer-file-name
))
132 (25 (memq major-mode ibuffer-help-buffer-modes
) font-lock-comment-face
)
133 (30 (eq major-mode
'dired-mode
) font-lock-function-name-face
))
134 "An alist describing how to fontify buffers.
135 Each element should be of the form (PRIORITY FORM FACE), where
136 PRIORITY is an integer, FORM is an arbitrary form to evaluate in the
137 buffer, and FACE is the face to use for fontification. If the FORM
138 evaluates to non-nil, then FACE will be put on the buffer name. The
139 element with the highest PRIORITY takes precedence.
141 If you change this variable, you must kill the Ibuffer buffer and
142 recreate it for the change to take effect."
144 (list (integer :tag
"Priority")
145 (sexp :tag
"Test Form")
149 (defcustom ibuffer-use-other-window nil
150 "If non-nil, display Ibuffer in another window by default."
154 (defcustom ibuffer-default-shrink-to-minimum-size nil
155 "If non-nil, minimize the size of the Ibuffer window by default."
158 (defvar ibuffer-shrink-to-minimum-size nil
)
160 (defcustom ibuffer-display-summary t
161 "If non-nil, summarize Ibuffer columns."
165 (defcustom ibuffer-truncate-lines t
166 "If non-nil, do not display continuation lines."
170 (defcustom ibuffer-case-fold-search case-fold-search
171 "If non-nil, ignore case when searching."
175 (defcustom ibuffer-default-sorting-mode
'recency
176 "The criteria by which to sort the buffers.
178 Note that this variable is local to each Ibuffer buffer. Thus, you
179 can have multiple Ibuffer buffers open, each with a different sorted
180 view of the buffers."
181 :type
'(choice (const :tag
"Last view time" :value recency
)
182 (const :tag
"Lexicographic" :value alphabetic
)
183 (const :tag
"Buffer size" :value size
)
184 (const :tag
"Major mode" :value major-mode
))
186 (defvar ibuffer-sorting-mode nil
)
188 (defcustom ibuffer-default-sorting-reversep nil
189 "If non-nil, reverse the default sorting order."
192 (defvar ibuffer-sorting-reversep nil
)
194 (defcustom ibuffer-elide-long-columns nil
195 "If non-nil, then elide column entries which exceed their max length.
196 This variable is deprecated; use the :elide argument of
197 `ibuffer-formats' to elide just certain columns."
201 (defcustom ibuffer-eliding-string
"..."
202 "The string to use for eliding long columns."
206 (defcustom ibuffer-maybe-show-predicates
`(,(lambda (buf)
207 (and (string-match "^ " (buffer-name buf
))
208 (null buffer-file-name
))))
209 "A list of predicates for buffers to display conditionally.
211 A predicate can be a regexp or a function.
212 If a regexp, then it will be matched against the buffer's name.
213 If a function, it will be called with the buffer as an argument, and
214 should return non-nil if this buffer should be shown.
216 Viewing of buffers hidden because of these predicates is enabled by
217 giving a non-nil prefix argument to `ibuffer-update'. Note that this
218 specialized filtering occurs before real filtering."
219 :type
'(repeat (choice regexp function
))
222 (defvar ibuffer-current-format nil
)
224 (defcustom ibuffer-movement-cycle t
225 "If non-nil, then forward and backwards movement commands cycle."
229 (defcustom ibuffer-modified-char ?
*
230 "The character to display for modified buffers."
234 (defcustom ibuffer-read-only-char ?%
235 "The character to display for read-only buffers."
239 (defcustom ibuffer-marked-char ?
>
240 "The character to display for marked buffers."
244 (defcustom ibuffer-deletion-char ?D
245 "The character to display for buffers marked for deletion."
249 (defcustom ibuffer-expert nil
250 "If non-nil, don't ask for confirmation of \"dangerous\" operations."
254 (defcustom ibuffer-view-ibuffer nil
255 "If non-nil, display the current Ibuffer buffer itself.
256 Note that this has a drawback - the data about the current Ibuffer
257 buffer will most likely be inaccurate. This includes modification
262 (defcustom ibuffer-always-show-last-buffer nil
263 "If non-nil, always display the previous buffer.
264 This variable takes precedence over filtering, and even
265 `ibuffer-never-show-predicates'."
266 :type
'(choice (const :tag
"Always" :value t
)
267 (const :tag
"Never" :value nil
)
268 (const :tag
"Always except minibuffer" :value
:nomini
))
271 (defcustom ibuffer-jump-offer-only-visible-buffers nil
272 "If non-nil, only offer buffers visible in the Ibuffer buffer
273 in completion lists of the `ibuffer-jump-to-buffer' command."
277 (defcustom ibuffer-use-header-line
(boundp 'header-line-format
)
278 "If non-nil, display a header line containing current filters."
282 (defcustom ibuffer-default-directory nil
283 "The default directory to use for a new Ibuffer buffer.
284 If nil, inherit the directory of the buffer in which `ibuffer' was
285 called. Otherwise, this variable should be a string naming a
286 directory, like `default-directory'."
287 :type
'(choice (const :tag
"Inherit" :value nil
)
291 (defcustom ibuffer-help-buffer-modes
292 '(help-mode apropos-mode Info-mode Info-edit-mode
)
293 "List of \"Help\" major modes."
294 :type
'(repeat function
)
297 (defcustom ibuffer-hook nil
298 "Hook run when `ibuffer' is called."
301 (defvaralias 'ibuffer-hooks
'ibuffer-hook
)
303 (defcustom ibuffer-mode-hook nil
304 "Hook run upon entry into `ibuffer-mode'."
307 (defvaralias 'ibuffer-mode-hooks
'ibuffer-mode-hook
)
309 (defcustom ibuffer-load-hook nil
310 "Hook run when Ibuffer is loaded."
314 (defcustom ibuffer-marked-face
'font-lock-warning-face
315 "Face used for displaying marked buffers."
319 (defcustom ibuffer-deletion-face
'font-lock-type-face
320 "Face used for displaying buffers marked for deletion."
324 (defcustom ibuffer-title-face
'font-lock-type-face
325 "Face used for the title string."
329 (defcustom ibuffer-filter-group-name-face
'bold
330 "Face used for displaying filtering group names."
334 (defcustom ibuffer-directory-abbrev-alist nil
335 "An alist of file name abbreviations like `directory-abbrev-alist'."
336 :type
'(repeat (cons :format
"%v"
343 (defvar ibuffer-mode-map nil
)
344 (defvar ibuffer-mode-operate-map nil
)
345 (defvar ibuffer-mode-groups-popup nil
)
346 (unless ibuffer-mode-map
347 (let ((map (make-sparse-keymap))
348 (operate-map (make-sparse-keymap "Operate"))
349 (groups-map (make-sparse-keymap "Filter Groups")))
350 (define-key map
(kbd "0") 'digit-argument
)
351 (define-key map
(kbd "1") 'digit-argument
)
352 (define-key map
(kbd "2") 'digit-argument
)
353 (define-key map
(kbd "3") 'digit-argument
)
354 (define-key map
(kbd "4") 'digit-argument
)
355 (define-key map
(kbd "5") 'digit-argument
)
356 (define-key map
(kbd "6") 'digit-argument
)
357 (define-key map
(kbd "7") 'digit-argument
)
358 (define-key map
(kbd "8") 'digit-argument
)
359 (define-key map
(kbd "9") 'digit-argument
)
361 (define-key map
(kbd "m") 'ibuffer-mark-forward
)
362 (define-key map
(kbd "t") 'ibuffer-toggle-marks
)
363 (define-key map
(kbd "u") 'ibuffer-unmark-forward
)
364 (define-key map
(kbd "=") 'ibuffer-diff-with-file
)
365 (define-key map
(kbd "j") 'ibuffer-jump-to-buffer
)
366 (define-key map
(kbd "M-g") 'ibuffer-jump-to-buffer
)
367 (define-key map
(kbd "DEL") 'ibuffer-unmark-backward
)
368 (define-key map
(kbd "M-DEL") 'ibuffer-unmark-all
)
369 (define-key map
(kbd "* *") 'ibuffer-unmark-all
)
370 (define-key map
(kbd "* M") 'ibuffer-mark-by-mode
)
371 (define-key map
(kbd "* m") 'ibuffer-mark-modified-buffers
)
372 (define-key map
(kbd "* u") 'ibuffer-mark-unsaved-buffers
)
373 (define-key map
(kbd "* s") 'ibuffer-mark-special-buffers
)
374 (define-key map
(kbd "* r") 'ibuffer-mark-read-only-buffers
)
375 (define-key map
(kbd "* /") 'ibuffer-mark-dired-buffers
)
376 (define-key map
(kbd "* e") 'ibuffer-mark-dissociated-buffers
)
377 (define-key map
(kbd "* h") 'ibuffer-mark-help-buffers
)
378 (define-key map
(kbd ".") 'ibuffer-mark-old-buffers
)
380 (define-key map
(kbd "d") 'ibuffer-mark-for-delete
)
381 (define-key map
(kbd "C-d") 'ibuffer-mark-for-delete-backwards
)
382 (define-key map
(kbd "k") 'ibuffer-mark-for-delete
)
383 (define-key map
(kbd "x") 'ibuffer-do-kill-on-deletion-marks
)
385 ;; immediate operations
386 (define-key map
(kbd "n") 'ibuffer-forward-line
)
387 (define-key map
(kbd "<down>") 'ibuffer-forward-line
)
388 (define-key map
(kbd "SPC") 'forward-line
)
389 (define-key map
(kbd "p") 'ibuffer-backward-line
)
390 (define-key map
(kbd "<up>") 'ibuffer-backward-line
)
391 (define-key map
(kbd "M-}") 'ibuffer-forward-next-marked
)
392 (define-key map
(kbd "M-{") 'ibuffer-backwards-next-marked
)
393 (define-key map
(kbd "l") 'ibuffer-redisplay
)
394 (define-key map
(kbd "g") 'ibuffer-update
)
395 (define-key map
"`" 'ibuffer-switch-format
)
396 (define-key map
"-" 'ibuffer-add-to-tmp-hide
)
397 (define-key map
"+" 'ibuffer-add-to-tmp-show
)
398 (define-key map
"b" 'ibuffer-bury-buffer
)
399 (define-key map
(kbd ",") 'ibuffer-toggle-sorting-mode
)
400 (define-key map
(kbd "s i") 'ibuffer-invert-sorting
)
401 (define-key map
(kbd "s a") 'ibuffer-do-sort-by-alphabetic
)
402 (define-key map
(kbd "s v") 'ibuffer-do-sort-by-recency
)
403 (define-key map
(kbd "s s") 'ibuffer-do-sort-by-size
)
404 (define-key map
(kbd "s m") 'ibuffer-do-sort-by-major-mode
)
406 (define-key map
(kbd "/ m") 'ibuffer-filter-by-mode
)
407 (define-key map
(kbd "/ M") 'ibuffer-filter-by-used-mode
)
408 (define-key map
(kbd "/ n") 'ibuffer-filter-by-name
)
409 (define-key map
(kbd "/ c") 'ibuffer-filter-by-content
)
410 (define-key map
(kbd "/ e") 'ibuffer-filter-by-predicate
)
411 (define-key map
(kbd "/ f") 'ibuffer-filter-by-filename
)
412 (define-key map
(kbd "/ >") 'ibuffer-filter-by-size-gt
)
413 (define-key map
(kbd "/ <") 'ibuffer-filter-by-size-lt
)
414 (define-key map
(kbd "/ r") 'ibuffer-switch-to-saved-filters
)
415 (define-key map
(kbd "/ a") 'ibuffer-add-saved-filters
)
416 (define-key map
(kbd "/ x") 'ibuffer-delete-saved-filters
)
417 (define-key map
(kbd "/ d") 'ibuffer-decompose-filter
)
418 (define-key map
(kbd "/ s") 'ibuffer-save-filters
)
419 (define-key map
(kbd "/ p") 'ibuffer-pop-filter
)
420 (define-key map
(kbd "/ !") 'ibuffer-negate-filter
)
421 (define-key map
(kbd "/ t") 'ibuffer-exchange-filters
)
422 (define-key map
(kbd "/ TAB") 'ibuffer-exchange-filters
)
423 (define-key map
(kbd "/ o") 'ibuffer-or-filter
)
424 (define-key map
(kbd "/ g") 'ibuffer-filters-to-filter-group
)
425 (define-key map
(kbd "/ P") 'ibuffer-pop-filter-group
)
426 (define-key map
(kbd "/ D") 'ibuffer-decompose-filter-group
)
427 (define-key map
(kbd "/ /") 'ibuffer-filter-disable
)
429 (define-key map
(kbd "M-n") 'ibuffer-forward-filter-group
)
430 (define-key map
(kbd "<right>") 'ibuffer-forward-filter-group
)
431 (define-key map
(kbd "M-p") 'ibuffer-backward-filter-group
)
432 (define-key map
(kbd "<left>") 'ibuffer-backward-filter-group
)
433 (define-key map
(kbd "M-j") 'ibuffer-jump-to-filter-group
)
434 (define-key map
(kbd "C-k") 'ibuffer-kill-line
)
435 (define-key map
(kbd "C-y") 'ibuffer-yank
)
436 (define-key map
(kbd "/ S") 'ibuffer-save-filter-groups
)
437 (define-key map
(kbd "/ R") 'ibuffer-switch-to-saved-filter-groups
)
438 (define-key map
(kbd "/ X") 'ibuffer-delete-saved-filter-groups
)
439 (define-key map
(kbd "/ \\") 'ibuffer-clear-filter-groups
)
441 (define-key map
(kbd "q") 'ibuffer-quit
)
442 (define-key map
(kbd "h") 'describe-mode
)
443 (define-key map
(kbd "?") 'describe-mode
)
445 (define-key map
(kbd "% n") 'ibuffer-mark-by-name-regexp
)
446 (define-key map
(kbd "% m") 'ibuffer-mark-by-mode-regexp
)
447 (define-key map
(kbd "% f") 'ibuffer-mark-by-file-name-regexp
)
449 (define-key map
(kbd "C-t") 'ibuffer-visit-tags-table
)
451 (define-key map
(kbd "|") 'ibuffer-do-shell-command-pipe
)
452 (define-key map
(kbd "!") 'ibuffer-do-shell-command-file
)
453 (define-key map
(kbd "~") 'ibuffer-do-toggle-modified
)
455 (define-key map
(kbd "A") 'ibuffer-do-view
)
456 (define-key map
(kbd "D") 'ibuffer-do-delete
)
457 (define-key map
(kbd "E") 'ibuffer-do-eval
)
458 (define-key map
(kbd "F") 'ibuffer-do-shell-command-file
)
459 (define-key map
(kbd "I") 'ibuffer-do-query-replace-regexp
)
460 (define-key map
(kbd "H") 'ibuffer-do-view-other-frame
)
461 (define-key map
(kbd "N") 'ibuffer-do-shell-command-pipe-replace
)
462 (define-key map
(kbd "M") 'ibuffer-do-toggle-modified
)
463 (define-key map
(kbd "O") 'ibuffer-do-occur
)
464 (define-key map
(kbd "P") 'ibuffer-do-print
)
465 (define-key map
(kbd "Q") 'ibuffer-do-query-replace
)
466 (define-key map
(kbd "R") 'ibuffer-do-rename-uniquely
)
467 (define-key map
(kbd "S") 'ibuffer-do-save
)
468 (define-key map
(kbd "T") 'ibuffer-do-toggle-read-only
)
469 (define-key map
(kbd "U") 'ibuffer-do-replace-regexp
)
470 (define-key map
(kbd "V") 'ibuffer-do-revert
)
471 (define-key map
(kbd "W") 'ibuffer-do-view-and-eval
)
472 (define-key map
(kbd "X") 'ibuffer-do-shell-command-pipe
)
474 (define-key map
(kbd "k") 'ibuffer-do-kill-lines
)
475 (define-key map
(kbd "w") 'ibuffer-copy-filename-as-kill
)
477 (define-key map
(kbd "RET") 'ibuffer-visit-buffer
)
478 (define-key map
(kbd "e") 'ibuffer-visit-buffer
)
479 (define-key map
(kbd "f") 'ibuffer-visit-buffer
)
480 (define-key map
(kbd "C-x C-f") 'ibuffer-find-file
)
481 (define-key map
(kbd "o") 'ibuffer-visit-buffer-other-window
)
482 (define-key map
(kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect
)
483 (define-key map
(kbd "M-o") 'ibuffer-visit-buffer-1-window
)
484 (define-key map
(kbd "v") 'ibuffer-do-view
)
485 (define-key map
(kbd "C-x v") 'ibuffer-do-view-horizontally
)
486 (define-key map
(kbd "C-c C-a") 'ibuffer-auto-mode
)
487 (define-key map
(kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window
)
488 (define-key map
(kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame
)
490 (define-key map
[menu-bar view
]
491 (cons "View" (make-sparse-keymap "View")))
493 (define-key-after map
[menu-bar view visit-buffer
]
494 '(menu-item "View this buffer" ibuffer-visit-buffer
))
495 (define-key-after map
[menu-bar view visit-buffer-other-window
]
496 '(menu-item "View (other window)" ibuffer-visit-buffer-other-window
))
497 (define-key-after map
[menu-bar view visit-buffer-other-frame
]
498 '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame
))
499 (define-key-after map
[menu-bar view ibuffer-update
]
500 '(menu-item "Update" ibuffer-update
501 :help
"Regenerate the list of buffers"))
502 (define-key-after map
[menu-bar view switch-format
]
503 '(menu-item "Switch display format" ibuffer-switch-format
504 :help
"Toggle between available values of `ibuffer-formats'"))
506 (define-key-after map
[menu-bar view dashes
]
509 (define-key-after map
[menu-bar view sort
]
510 (cons "Sort" (make-sparse-keymap "Sort")))
512 (define-key-after map
[menu-bar view sort do-sort-by-major-mode
]
513 '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode
))
514 (define-key-after map
[menu-bar view sort do-sort-by-size
]
515 '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size
))
516 (define-key-after map
[menu-bar view sort do-sort-by-alphabetic
]
517 '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic
518 :help
"Sort by the alphabetic order of buffer name"))
519 (define-key-after map
[menu-bar view sort do-sort-by-recency
]
520 '(menu-item "Sort by view time" ibuffer-do-sort-by-recency
521 :help
"Sort by the last time the buffer was displayed"))
522 (define-key-after map
[menu-bar view sort dashes
]
524 (define-key-after map
[menu-bar view sort invert-sorting
]
525 '(menu-item "Reverse sorting order" ibuffer-invert-sorting
))
526 (define-key-after map
[menu-bar view sort toggle-sorting-mode
]
527 '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode
528 :help
"Switch between the various sorting criteria"))
530 (define-key-after map
[menu-bar view filter
]
531 (cons "Filter" (make-sparse-keymap "Filter")))
533 (define-key-after map
[menu-bar view filter filter-disable
]
534 '(menu-item "Disable all filtering" ibuffer-filter-disable
535 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
536 (define-key-after map
[menu-bar view filter filter-by-mode
]
537 '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode
))
538 (define-key-after map
[menu-bar view filter filter-by-mode
]
539 '(menu-item "Add filter by major mode in use..." ibuffer-filter-by-used-mode
))
540 (define-key-after map
[menu-bar view filter filter-by-name
]
541 '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name
))
542 (define-key-after map
[menu-bar view filter filter-by-filename
]
543 '(menu-item "Add filter by filename..." ibuffer-filter-by-filename
))
544 (define-key-after map
[menu-bar view filter filter-by-size-lt
]
545 '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt
))
546 (define-key-after map
[menu-bar view filter filter-by-size-gt
]
547 '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt
))
548 (define-key-after map
[menu-bar view filter filter-by-content
]
549 '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content
))
550 (define-key-after map
[menu-bar view filter filter-by-predicate
]
551 '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate
))
552 (define-key-after map
[menu-bar view filter pop-filter
]
553 '(menu-item "Remove top filter" ibuffer-pop-filter
554 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
555 (define-key-after map
[menu-bar view filter or-filter
]
556 '(menu-item "OR top two filters" ibuffer-or-filter
557 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
558 (cdr ibuffer-filtering-qualifiers
))
559 :help
"Create a new filter which is the logical OR of the top two filters"))
560 (define-key-after map
[menu-bar view filter negate-filter
]
561 '(menu-item "Negate top filter" ibuffer-negate-filter
562 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
563 (define-key-after map
[menu-bar view filter decompose-filter
]
564 '(menu-item "Decompose top filter" ibuffer-decompose-filter
565 :enable
(and (featurep 'ibuf-ext
) (memq (car ibuffer-filtering-qualifiers
) '(or saved not
)))
566 :help
"Break down a complex filter like OR or NOT"))
567 (define-key-after map
[menu-bar view filter exchange-filters
]
568 '(menu-item "Swap top two filters" ibuffer-exchange-filters
569 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
570 (cdr ibuffer-filtering-qualifiers
))))
571 (define-key-after map
[menu-bar view filter save-filters
]
572 '(menu-item "Save current filters permanently..." ibuffer-save-filters
573 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
574 :help
"Use a mnemnonic name to store current filter stack"))
575 (define-key-after map
[menu-bar view filter switch-to-saved-filters
]
576 '(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters
577 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)
578 :help
"Replace current filters with a saved stack"))
579 (define-key-after map
[menu-bar view filter add-saved-filters
]
580 '(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters
581 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
582 :help
"Include already saved stack with current filters"))
583 (define-key-after map
[menu-bar view filter delete-saved-filters
]
584 '(menu-item "Delete permanently saved filters..."
585 ibuffer-delete-saved-filters
586 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)))
590 (define-key-after groups-map
[filters-to-filter-group
]
591 '(menu-item "Create filter group from current filters..."
592 ibuffer-filters-to-filter-group
593 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
594 (define-key-after groups-map
[forward-filter-group
]
595 '(menu-item "Move point to the next filter group"
596 ibuffer-forward-filter-group
))
597 (define-key-after groups-map
[backward-filter-group
]
598 '(menu-item "Move point to the previous filter group"
599 ibuffer-backward-filter-group
))
600 (define-key-after groups-map
[jump-to-filter-group
]
601 '(menu-item "Move point to a specific filter group..."
602 ibuffer-jump-to-filter-group
))
603 (define-key-after groups-map
[kill-filter-group
]
604 '(menu-item "Kill filter group named..."
605 ibuffer-kill-filter-group
606 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
607 (define-key-after groups-map
[yank-filter-group
]
608 '(menu-item "Yank last killed filter group before..."
609 ibuffer-yank-filter-group
610 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-group-kill-ring
)))
611 (define-key-after groups-map
[pop-filter-group
]
612 '(menu-item "Remove top filter group"
613 ibuffer-pop-filter-group
614 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
615 (define-key-after groups-map
[clear-filter-groups
]
616 '(menu-item "Remove all filter groups"
617 ibuffer-clear-filter-groups
618 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
619 (define-key-after groups-map
[pop-filter-group
]
620 '(menu-item "Decompose filter group..."
621 ibuffer-pop-filter-group
622 :help
"\"Unmake\" a filter group"
623 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
624 (define-key-after groups-map
[save-filter-groups
]
625 '(menu-item "Save current filter groups permanently..."
626 ibuffer-save-filter-groups
627 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)
628 :help
"Use a mnemnonic name to store current filter groups"))
629 (define-key-after groups-map
[switch-to-saved-filter-groups
]
630 '(menu-item "Restore permanently saved filters..."
631 ibuffer-switch-to-saved-filter-groups
632 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)
633 :help
"Replace current filters with a saved stack"))
634 (define-key-after groups-map
[delete-saved-filter-groups
]
635 '(menu-item "Delete permanently saved filter groups..."
636 ibuffer-delete-saved-filter-groups
637 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)))
638 (define-key-after groups-map
[set-filter-groups-by-mode
]
639 '(menu-item "Set current filter groups to filter by mode"
640 ibuffer-set-filter-groups-by-mode
))
642 (define-key-after map
[menu-bar view filter-groups
]
643 (cons "Filter Groups" groups-map
))
645 (define-key-after map
[menu-bar view dashes2
]
647 (define-key-after map
[menu-bar view diff-with-file
]
648 '(menu-item "Diff with file" ibuffer-diff-with-file
649 :help
"View the differences between this buffer and its file"))
650 (define-key-after map
[menu-bar view auto-mode
]
651 '(menu-item "Toggle Auto Mode" ibuffer-auto-mode
652 :help
"Attempt to automatically update the Ibuffer buffer"))
653 (define-key-after map
[menu-bar view customize
]
654 '(menu-item "Customize Ibuffer" ibuffer-customize
655 :help
"Use Custom to customize Ibuffer"))
657 (define-key-after map
[menu-bar mark
]
658 (cons "Mark" (make-sparse-keymap "Mark")))
660 (define-key-after map
[menu-bar mark toggle-marks
]
661 '(menu-item "Toggle marks" ibuffer-toggle-marks
662 :help
"Unmark marked buffers, and mark unmarked buffers"))
663 (define-key-after map
[menu-bar mark mark-forward
]
664 '(menu-item "Mark" ibuffer-mark-forward
665 :help
"Mark the buffer at point"))
666 (define-key-after map
[menu-bar mark unmark-forward
]
667 '(menu-item "Unmark" ibuffer-unmark-forward
668 :help
"Unmark the buffer at point"))
669 (define-key-after map
[menu-bar mark mark-by-mode
]
670 '(menu-item "Mark by mode..." ibuffer-mark-by-mode
671 :help
"Mark all buffers in a particular major mode"))
672 (define-key-after map
[menu-bar mark mark-modified-buffers
]
673 '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers
674 :help
"Mark all buffers which have been modified"))
675 (define-key-after map
[menu-bar mark mark-unsaved-buffers
]
676 '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers
677 :help
"Mark all buffers which have a file and are modified"))
678 (define-key-after map
[menu-bar mark mark-read-only-buffers
]
679 '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers
680 :help
"Mark all buffers which are read-only"))
681 (define-key-after map
[menu-bar mark mark-special-buffers
]
682 '(menu-item "Mark special buffers" ibuffer-mark-special-buffers
683 :help
"Mark all buffers whose name begins with a *"))
684 (define-key-after map
[menu-bar mark mark-dired-buffers
]
685 '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers
686 :help
"Mark buffers in dired-mode"))
687 (define-key-after map
[menu-bar mark mark-dissociated-buffers
]
688 '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers
689 :help
"Mark buffers with a non-existent associated file"))
690 (define-key-after map
[menu-bar mark mark-help-buffers
]
691 '(menu-item "Mark help buffers" ibuffer-mark-help-buffers
692 :help
"Mark buffers in help-mode"))
693 (define-key-after map
[menu-bar mark mark-old-buffers
]
694 '(menu-item "Mark old buffers" ibuffer-mark-old-buffers
695 :help
"Mark buffers which have not been viewed recently"))
696 (define-key-after map
[menu-bar mark unmark-all
]
697 '(menu-item "Unmark All" ibuffer-unmark-all
))
699 (define-key-after map
[menu-bar mark dashes
]
702 (define-key-after map
[menu-bar mark mark-by-name-regexp
]
703 '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
704 :help
"Mark buffers whose name matches a regexp"))
705 (define-key-after map
[menu-bar mark mark-by-mode-regexp
]
706 '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp
707 :help
"Mark buffers whose major mode name matches a regexp"))
708 (define-key-after map
[menu-bar mark mark-by-file-name-regexp
]
709 '(menu-item "Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp
710 :help
"Mark buffers whose file name matches a regexp"))
712 ;; Operate map is added later
714 (define-key-after operate-map
[do-view
]
715 '(menu-item "View" ibuffer-do-view
))
716 (define-key-after operate-map
[do-view-other-frame
]
717 '(menu-item "View (separate frame)" ibuffer-do-view-other-frame
))
718 (define-key-after operate-map
[do-save
]
719 '(menu-item "Save" ibuffer-do-save
))
720 (define-key-after operate-map
[do-replace-regexp
]
721 '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp
722 :help
"Replace text inside marked buffers"))
723 (define-key-after operate-map
[do-query-replace
]
724 '(menu-item "Query Replace..." ibuffer-do-query-replace
725 :help
"Replace text in marked buffers, asking each time"))
726 (define-key-after operate-map
[do-query-replace-regexp
]
727 '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp
728 :help
"Replace text in marked buffers by regexp, asking each time"))
729 (define-key-after operate-map
[do-print
]
730 '(menu-item "Print" ibuffer-do-print
))
731 (define-key-after operate-map
[do-toggle-modified
]
732 '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified
))
733 (define-key-after operate-map
[do-revert
]
734 '(menu-item "Revert" ibuffer-do-revert
735 :help
"Revert marked buffers to their associated file"))
736 (define-key-after operate-map
[do-rename-uniquely
]
737 '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely
738 :help
"Rename marked buffers to a new, unique name"))
739 (define-key-after operate-map
[do-delete
]
740 '(menu-item "Kill" ibuffer-do-delete
))
741 (define-key-after operate-map
[do-occur
]
742 '(menu-item "List lines matching..." ibuffer-do-occur
743 :help
"View all lines in marked buffers matching a regexp"))
744 (define-key-after operate-map
[do-shell-command-pipe
]
745 '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe
746 :help
"For each marked buffer, send its contents to a shell command"))
747 (define-key-after operate-map
[do-shell-command-pipe-replace
]
748 '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace
749 :help
"For each marked buffer, replace its contents with output of shell command"))
750 (define-key-after operate-map
[do-shell-command-file
]
751 '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file
752 :help
"For each marked buffer, run a shell command with its file as argument"))
753 (define-key-after operate-map
[do-eval
]
754 '(menu-item "Eval..." ibuffer-do-eval
755 :help
"Evaluate a Lisp form in each marked buffer"))
756 (define-key-after operate-map
[do-view-and-eval
]
757 '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval
758 :help
"Evaluate a Lisp form in each marked buffer while viewing it"))
760 (setq ibuffer-mode-map map
761 ibuffer-mode-operate-map operate-map
762 ibuffer-mode-groups-popup
(copy-keymap groups-map
))))
764 (define-key ibuffer-mode-groups-popup
[kill-filter-group
]
765 '(menu-item "Kill filter group"
767 :enable
(and (featurep 'ibuf-ext
)
768 ibuffer-filter-groups
)))
769 (define-key ibuffer-mode-groups-popup
[yank-filter-group
]
770 '(menu-item "Yank last killed filter group"
772 :enable
(and (featurep 'ibuf-ext
)
773 ibuffer-filter-group-kill-ring
)))
775 (defvar ibuffer-name-map
776 (let ((map (make-sparse-keymap)))
777 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
778 (define-key map
[(mouse-2)] 'ibuffer-mouse-visit-buffer
)
779 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
782 (defvar ibuffer-mode-name-map
783 (let ((map (make-sparse-keymap)))
784 (define-key map
[(mouse-2)] 'ibuffer-mouse-filter-by-mode
)
785 (define-key map
(kbd "RET") 'ibuffer-interactive-filter-by-mode
)
788 (defvar ibuffer-mode-filter-group-map
789 (let ((map (make-sparse-keymap)))
790 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
791 (define-key map
[(mouse-2)] 'ibuffer-mouse-toggle-filter-group
)
792 (define-key map
(kbd "RET") 'ibuffer-toggle-filter-group
)
793 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
796 (defvar ibuffer-restore-window-config-on-quit nil
797 "If non-nil, restore previous window configuration upon exiting `ibuffer'.")
799 (defvar ibuffer-prev-window-config nil
800 "Window configuration before starting Ibuffer.")
802 (defvar ibuffer-did-modification nil
)
804 (defvar ibuffer-sorting-functions-alist nil
805 "An alist of functions which describe how to sort buffers.
807 Note: You most likely do not want to modify this variable directly;
808 use `define-ibuffer-sorter' instead.
810 The alist elements are constructed like (NAME DESCRIPTION FUNCTION)
811 Where NAME is a symbol describing the sorting method, DESCRIPTION is a
812 short string which will be displayed in the minibuffer and menu, and
813 FUNCTION is a function of two arguments, which will be the buffers to
816 ;;; Utility functions
817 (defun ibuffer-columnize-and-insert-list (list &optional pad-width
)
818 "Insert LIST into the current buffer in as many columns as possible.
819 The maximum number of columns is determined by the current window
820 width and the longest string in LIST."
823 (let ((width (window-width))
824 (max (+ (apply #'max
(mapcar #'length list
))
826 (let ((columns (/ width max
)))
827 (when (zerop columns
)
830 (dotimes (i (1- columns
))
831 (insert (concat (car list
) (make-string (- max
(length (car list
)))
833 (setq list
(cdr list
)))
834 (when (not (null list
))
838 (defsubst ibuffer-current-mark
()
839 (cadr (get-text-property (line-beginning-position)
840 'ibuffer-properties
)))
842 (defun ibuffer-mouse-toggle-mark (event)
843 "Toggle the marked status of the buffer chosen with the mouse."
846 (let ((pt (save-excursion
847 (mouse-set-point event
)
849 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
850 (ibuffer-toggle-marks it
)
852 (let ((mark (ibuffer-current-mark)))
853 (setq buffer-read-only nil
)
854 (if (eq mark ibuffer-marked-char
)
855 (ibuffer-set-mark ?
)
856 (ibuffer-set-mark ibuffer-marked-char
)))))
857 (setq buffer-read-only t
)))
859 (defun ibuffer-find-file (file &optional wildcards
)
860 "Like `find-file', but default to the directory of the buffer at point."
862 (let ((default-directory (let ((buf (ibuffer-current-buffer)))
863 (if (buffer-live-p buf
)
864 (with-current-buffer buf
866 default-directory
))))
867 (list (read-file-name "Find file: " default-directory
)
868 current-prefix-arg
)))
869 (find-file file
(or wildcards
(interactive-p))))
871 (defun ibuffer-mouse-visit-buffer (event)
872 "Visit the buffer chosen with the mouse."
876 (mouse-set-point event
)
877 (ibuffer-current-buffer t
))))
879 (defun ibuffer-mouse-popup-menu (event)
880 "Display a menu of operations."
882 (let ((eventpt (posn-point (event-end event
)))
885 (if (get-text-property eventpt
'ibuffer-filter-group-name
)
888 (popup-menu ibuffer-mode-groups-popup
))
889 (let ((inhibit-read-only t
))
891 ;; hm. we could probably do this in a better fashion
892 (ibuffer-unmark-all ?
\r)
895 (ibuffer-set-mark ibuffer-marked-char
))
897 (popup-menu ibuffer-mode-operate-map
)))))
898 (setq buffer-read-only t
)
899 (if (= eventpt
(point))
900 (goto-char origpt
)))))
902 (defun ibuffer-skip-properties (props direction
)
903 (while (and (not (eobp))
905 (dolist (prop props hit
)
906 (when (get-text-property (point) prop
)
908 (forward-line direction
)
909 (beginning-of-line)))
911 (defun ibuffer-customize ()
912 "Begin customizing Ibuffer interactively."
914 (customize-group 'ibuffer
))
916 (defun ibuffer-backward-line (&optional arg skip-group-names
)
917 "Move backwards ARG lines, wrapping around the list if necessary."
919 (or arg
(setq arg
1))
923 (when (and ibuffer-movement-cycle
924 (or (get-text-property (point) 'ibuffer-title
)
925 (and skip-group-names
926 (get-text-property (point)
927 'ibuffer-filter-group-name
))))
928 (goto-char (point-max))
930 (ibuffer-skip-properties (append '(ibuffer-summary)
931 (when skip-group-names
932 '(ibuffer-filter-group-name)))
934 ;; Handle the special case of no buffers.
935 (when (get-text-property (point) 'ibuffer-title
)
940 (defun ibuffer-forward-line (&optional arg skip-group-names
)
941 "Move forward ARG lines, wrapping around the list if necessary."
943 (or arg
(setq arg
1))
945 (when (and ibuffer-movement-cycle
947 (get-text-property (point) 'ibuffer-summary
)))
948 (goto-char (point-min)))
949 (when (or (get-text-property (point) 'ibuffer-title
)
950 (and skip-group-names
951 (get-text-property (point) 'ibuffer-filter-group-name
)))
954 (ibuffer-skip-properties (append '(ibuffer-title)
955 (when skip-group-names
956 '(ibuffer-filter-group-name)))
959 (ibuffer-backward-line (- arg
))
962 (when (and ibuffer-movement-cycle
964 (get-text-property (point) 'ibuffer-summary
)))
965 (goto-char (point-min)))
967 (ibuffer-skip-properties (append '(ibuffer-title)
968 (when skip-group-names
969 '(ibuffer-filter-group-name)))
972 (defun ibuffer-visit-buffer (&optional single
)
973 "Visit the buffer on this line.
974 If optional argument SINGLE is non-nil, then also ensure there is only
977 (let ((buf (ibuffer-current-buffer t
)))
978 (bury-buffer (current-buffer))
979 (switch-to-buffer buf
)
981 (delete-other-windows))))
983 (defun ibuffer-visit-buffer-other-window (&optional noselect
)
984 "Visit the buffer on this line in another window."
986 (let ((buf (ibuffer-current-buffer t
)))
987 (bury-buffer (current-buffer))
989 (let ((curwin (selected-window)))
991 (select-window curwin
))
992 (switch-to-buffer-other-window buf
))))
994 (defun ibuffer-visit-buffer-other-window-noselect ()
995 "Visit the buffer on this line in another window, but don't select it."
997 (ibuffer-visit-buffer-other-window t
))
999 (defun ibuffer-visit-buffer-other-frame ()
1000 "Visit the buffer on this line in another frame."
1002 (let ((buf (ibuffer-current-buffer t
)))
1003 (bury-buffer (current-buffer))
1004 (switch-to-buffer-other-frame buf
)))
1006 (defun ibuffer-visit-buffer-1-window ()
1007 "Visit the buffer on this line, and delete other windows."
1009 (ibuffer-visit-buffer t
))
1011 (defun ibuffer-bury-buffer ()
1012 "Bury the buffer on this line."
1014 (let ((buf (ibuffer-current-buffer t
))
1015 (line (+ 1 (count-lines 1 (point)))))
1017 (ibuffer-update nil t
)
1020 (defun ibuffer-visit-tags-table ()
1021 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
1023 (let ((file (buffer-file-name (ibuffer-current-buffer t
))))
1025 (visit-tags-table file
)
1026 (error "Specified buffer has no file"))))
1028 (defun ibuffer-do-view (&optional other-frame
)
1029 "View marked buffers, or the buffer on the current line.
1030 If optional argument OTHER-FRAME is non-nil, then display each
1031 marked buffer in a new frame. Otherwise, display each buffer as
1032 a new window in the current frame, splitting vertically."
1034 (ibuffer-do-view-1 (if other-frame
'other-frame
'vertically
)))
1036 (defun ibuffer-do-view-horizontally (&optional other-frame
)
1037 "As `ibuffer-do-view', but split windows horizontally."
1039 (ibuffer-do-view-1 (if other-frame
'other-frame
'horizontally
)))
1041 (defun ibuffer-do-view-1 (type)
1042 (let ((marked-bufs (ibuffer-get-marked-buffers)))
1043 (when (null marked-bufs
)
1044 (setq marked-bufs
(list (ibuffer-current-buffer t
))))
1045 (unless (and (eq type
'other-frame
)
1046 (not ibuffer-expert
)
1047 (> (length marked-bufs
) 3)
1048 (not (y-or-n-p (format "Really create a new frame for %s buffers? "
1049 (length marked-bufs
)))))
1050 (set-buffer-modified-p nil
)
1051 (delete-other-windows)
1052 (switch-to-buffer (pop marked-bufs
))
1053 (let ((height (/ (1- (if (eq type
'horizontally
) (frame-width)
1055 (1+ (length marked-bufs
)))))
1056 (mapcar (if (eq type
'other-frame
)
1058 (let ((curframe (selected-frame)))
1059 (select-frame (make-frame))
1060 (switch-to-buffer buf
)
1061 (select-frame curframe
)))
1063 (split-window nil height
(eq type
'horizontally
))
1065 (switch-to-buffer buf
)))
1068 (defun ibuffer-do-view-other-frame ()
1069 "View each of the marked buffers in a separate frame."
1071 (ibuffer-do-view t
))
1073 (defsubst ibuffer-map-marked-lines
(func)
1074 (prog1 (ibuffer-map-on-mark ibuffer-marked-char func
)
1075 (ibuffer-redisplay t
)))
1077 (defun ibuffer-shrink-to-fit (&optional owin
)
1078 (fit-window-to-buffer nil
(when owin
(/ (frame-height)
1079 (length (window-list (selected-frame)))))))
1081 (defun ibuffer-confirm-operation-on (operation names
)
1082 "Display a buffer asking whether to perform OPERATION on NAMES."
1084 (if (= (length names
) 1)
1085 (y-or-n-p (format "Really %s buffer %s? " operation
(car names
)))
1086 (let ((buf (get-buffer-create "*Ibuffer confirmation*")))
1087 (with-current-buffer buf
1088 (setq buffer-read-only nil
)
1090 (ibuffer-columnize-and-insert-list names
)
1091 (goto-char (point-min))
1092 (setq buffer-read-only t
))
1093 (let ((lastwin (car (last (window-list nil
'nomini
)))))
1094 ;; Now attempt to display the buffer...
1095 (save-window-excursion
1096 (select-window lastwin
)
1097 ;; The window might be too small to split; in that case,
1098 ;; try a few times to increase its size before giving up.
1108 (if (or (> (incf attempts
) 4)
1109 (and (stringp (cadr err
))
1110 ;; This definitely falls in the
1111 ;; ghetto hack category...
1112 (not (string-match "too small" (cadr err
)))))
1113 (apply #'signal err
)
1114 (enlarge-window 3))))))
1115 (select-window (next-window))
1116 (switch-to-buffer buf
)
1119 (fit-window-to-buffer)
1120 (y-or-n-p (format "Really %s %d buffers? "
1121 operation
(length names
))))
1122 (kill-buffer buf
))))))))
1124 (defsubst ibuffer-map-lines-nomodify
(function)
1125 "As `ibuffer-map-lines', but don't set the modification flag."
1126 (ibuffer-map-lines function t
))
1128 (defun ibuffer-buffer-names-with-mark (mark)
1129 (let ((ibuffer-buffer-names-with-mark-result nil
))
1130 (ibuffer-map-lines-nomodify
1132 (when (char-equal mark mk
)
1133 (push (buffer-name buf
)
1134 ibuffer-buffer-names-with-mark-result
))))
1135 ibuffer-buffer-names-with-mark-result
))
1137 (defsubst ibuffer-marked-buffer-names
()
1138 (ibuffer-buffer-names-with-mark ibuffer-marked-char
))
1140 (defsubst ibuffer-deletion-marked-buffer-names
()
1141 (ibuffer-buffer-names-with-mark ibuffer-deletion-char
))
1143 (defun ibuffer-count-marked-lines (&optional all
)
1145 (ibuffer-map-lines-nomodify
1146 #'(lambda (buf mark
)
1147 (not (char-equal mark ?
))))
1148 (ibuffer-map-lines-nomodify
1149 #'(lambda (buf mark
)
1150 (char-equal mark ibuffer-marked-char
)))))
1152 (defsubst ibuffer-count-deletion-lines
()
1153 (ibuffer-map-lines-nomodify
1154 #'(lambda (buf mark
)
1155 (char-equal mark ibuffer-deletion-char
))))
1157 (defsubst ibuffer-map-deletion-lines
(func)
1158 (ibuffer-map-on-mark ibuffer-deletion-char func
))
1160 (define-ibuffer-op ibuffer-do-save
()
1161 "Save marked buffers as with `save-buffer'."
1165 (when (buffer-modified-p buf
)
1166 (if (not (with-current-buffer buf
1168 ;; handle the case where we're prompted
1170 (save-window-excursion
1171 (switch-to-buffer buf
)
1173 (with-current-buffer buf
1177 (define-ibuffer-op ibuffer-do-toggle-modified
()
1178 "Toggle modification flag of marked buffers."
1179 (:opstring
"(un)marked as modified"
1181 (set-buffer-modified-p (not (buffer-modified-p))))
1183 (define-ibuffer-op ibuffer-do-toggle-read-only
()
1184 "Toggle read only status in marked buffers."
1185 (:opstring
"toggled read only status in"
1189 (define-ibuffer-op ibuffer-do-delete
()
1190 "Kill marked buffers as with `kill-this-buffer'."
1192 :active-opstring
"kill"
1196 (if (kill-buffer buf
)
1200 (define-ibuffer-op ibuffer-do-kill-on-deletion-marks
()
1201 "Kill buffers marked for deletion as with `kill-this-buffer'."
1203 :active-opstring
"kill"
1208 (if (kill-buffer buf
)
1212 (defun ibuffer-unmark-all (mark)
1213 "Unmark all buffers with mark MARK."
1214 (interactive "cRemove marks (RET means all):")
1215 (if (= (ibuffer-count-marked-lines t
) 0)
1216 (message "No buffers marked; use 'm' to mark a buffer")
1218 ((char-equal mark ibuffer-marked-char
)
1219 (ibuffer-map-marked-lines
1220 #'(lambda (buf mark
)
1221 (ibuffer-set-mark-1 ?
)
1223 ((char-equal mark ibuffer-deletion-char
)
1224 (ibuffer-map-deletion-lines
1225 #'(lambda (buf mark
)
1226 (ibuffer-set-mark-1 ?
)
1230 #'(lambda (buf mark
)
1231 (when (not (char-equal mark ?
))
1232 (ibuffer-set-mark-1 ?
))
1234 (ibuffer-redisplay t
))
1236 (defun ibuffer-toggle-marks (&optional group
)
1237 "Toggle which buffers are marked.
1238 In other words, unmarked buffers become marked, and marked buffers
1240 If point is on a group name, then this function operates on that
1243 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1247 #'(lambda (buf mark
)
1248 (cond ((eq mark ibuffer-marked-char
)
1249 (ibuffer-set-mark-1 ?
)
1252 (ibuffer-set-mark-1 ibuffer-marked-char
)
1257 (message "%s buffers marked" count
))
1258 (ibuffer-redisplay t
))
1260 (defun ibuffer-mark-forward (arg)
1261 "Mark the buffer on this line, and move forward ARG lines.
1262 If point is on a group name, this function operates on that group."
1264 (ibuffer-mark-interactive arg ibuffer-marked-char
1))
1266 (defun ibuffer-unmark-forward (arg)
1267 "Unmark the buffer on this line, and move forward ARG lines.
1268 If point is on a group name, this function operates on that group."
1270 (ibuffer-mark-interactive arg ?
1))
1272 (defun ibuffer-unmark-backward (arg)
1273 "Unmark the buffer on this line, and move backward ARG lines.
1274 If point is on a group name, this function operates on that group."
1276 (ibuffer-mark-interactive arg ? -
1))
1278 (defun ibuffer-mark-interactive (arg mark movement
)
1279 (assert (eq major-mode
'ibuffer-mode
))
1280 (or arg
(setq arg
1))
1281 (ibuffer-forward-line 0)
1282 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1285 (ibuffer-mark-on-buffer #'identity mark it
))
1286 (ibuffer-forward-line 0 t
)
1287 (let ((inhibit-read-only t
))
1289 (ibuffer-set-mark mark
)
1290 (ibuffer-forward-line movement t
)
1291 (setq arg
(1- arg
))))))
1293 (defun ibuffer-set-mark (mark)
1294 (assert (eq major-mode
'ibuffer-mode
))
1295 (let ((inhibit-read-only t
))
1296 (ibuffer-set-mark-1 mark
)
1297 (setq ibuffer-did-modification t
)
1298 (ibuffer-redisplay-current)
1299 (beginning-of-line)))
1301 (defun ibuffer-set-mark-1 (mark)
1302 (let ((beg (line-beginning-position))
1303 (end (line-end-position)))
1304 (put-text-property beg end
'ibuffer-properties
1305 (list (ibuffer-current-buffer)
1308 (defun ibuffer-mark-for-delete (arg)
1309 "Mark the buffers on ARG lines forward for deletion.
1310 If point is on a group name, this function operates on that group."
1312 (ibuffer-mark-interactive arg ibuffer-deletion-char
1))
1314 (defun ibuffer-mark-for-delete-backwards (arg)
1315 "Mark the buffers on ARG lines backward for deletion.
1316 If point is on a group name, this function operates on that group."
1318 (ibuffer-mark-interactive arg ibuffer-deletion-char -
1))
1320 (defun ibuffer-current-buffer (&optional must-be-live
)
1321 (let ((buf (car (get-text-property (line-beginning-position)
1322 'ibuffer-properties
))))
1325 (unless (buffer-live-p buf
)
1326 (error (substitute-command-keys "Buffer %s has been killed; use `\\[ibuffer-update]' to update") buf
))
1327 (error "No buffer on this line")))
1330 (defun ibuffer-active-formats-name ()
1331 (if (boundp 'ibuffer-filter-format-alist
)
1333 (dolist (filter ibuffer-filtering-qualifiers ret
)
1334 (let ((val (assq (car filter
) ibuffer-filter-format-alist
)))
1336 (setq ret
(car filter
)))))
1342 (defun ibuffer-current-formats (uncompiledp)
1343 (let* ((name (ibuffer-active-formats-name)))
1344 (ibuffer-check-formats)
1345 (if (eq name
:ibuffer-formats
)
1348 ibuffer-compiled-formats
)
1351 ibuffer-filter-format-alist
1352 ibuffer-compiled-filter-formats
))))))
1354 (defun ibuffer-current-format (&optional uncompiledp
)
1355 (or ibuffer-current-format
1356 (setq ibuffer-current-format
0))
1357 (nth ibuffer-current-format
(ibuffer-current-formats uncompiledp
)))
1359 (defun ibuffer-expand-format-entry (form)
1360 (if (or (consp form
)
1362 (let ((sym (intern (concat "ibuffer-make-column-"
1363 (symbol-name (if (consp form
)
1366 (unless (or (fboundp sym
)
1367 (assq sym ibuffer-inline-columns
))
1368 (error "Unknown column %s in ibuffer-formats" form
))
1369 (let (min max align elide
)
1371 (setq min
(or (nth 1 form
) 0)
1372 max
(or (nth 2 form
) -
1)
1373 align
(or (nth 3 form
) :left
)
1374 elide
(or (nth 4 form
) nil
))
1379 (list sym min max align elide
)))
1382 (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p
)
1383 (let ((ellipsis (propertize ibuffer-eliding-string
'font-lock-face
'bold
)))
1384 (if (or elide ibuffer-elide-long-columns
)
1389 (length ibuffer-eliding-string
)))
1391 (substring ,strvar
0 (- strlen
,(length ellipsis
)))
1396 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p
)
1400 `(substring ,strvar
0 ,maxvar
)))
1402 (defun ibuffer-compile-make-format-form (strvar widthform alignment
)
1403 (let* ((left `(make-string tmp2 ?
))
1404 (right `(make-string (- tmp1 tmp2
) ?
)))
1406 (setq tmp1
,widthform
1409 (:right
`(concat ,left
,right
,strvar
))
1410 (:center
`(concat ,left
,strvar
,right
))
1411 (:left
`(concat ,strvar
,left
,right
))
1412 (t (error "Invalid alignment %s" alignment
))))))
1414 (defun ibuffer-compile-format (format)
1416 ;; We use these variables to keep track of which variables
1417 ;; inside the generated function we need to bind, since
1418 ;; binding variables in Emacs takes time.
1419 str-used tmp1-used tmp2-used global-strlen-used
)
1420 (dolist (form format
)
1422 ;; Generate a form based on a particular format entry, like
1423 ;; " ", mark, or (mode 16 16 :right).
1425 ;; It's a string; all we need to do is insert it.
1427 (let* ((form (ibuffer-expand-format-entry form
))
1431 (align (nth 3 form
))
1432 (elide (nth 4 form
)))
1433 (let* ((from-end-p (when (minusp min
)
1440 min-used max-used strlen-used
)
1441 (when (or (not (integerp min
)) (>= min
0))
1442 ;; This is a complex case; they want it limited to a
1445 (setq str-used t strlen-used t global-strlen-used t
1446 tmp1-used t tmp2-used t
)
1447 ;; Generate code to limit the string to a minimum size.
1448 (setq minform
`(progn
1450 ,(ibuffer-compile-make-format-form
1452 `(- ,(if (integerp min
)
1457 (when (or (not (integerp max
)) (> max
0))
1458 (setq str-used t max-used t
)
1459 ;; Generate code to limit the string to a maximum size.
1460 (setq maxform
`(progn
1462 ,(ibuffer-compile-make-substring-form
1468 (setq strlen
(length str
))
1470 ,(ibuffer-compile-make-eliding-form 'str
1473 ;; Now, put these forms together with the rest of the code.
1475 ;; Is this an "inline" column? This means we have
1476 ;; to get the code from the
1477 ;; `ibuffer-inline-columns' alist and insert it
1478 ;; into our generated code. Otherwise, we just
1479 ;; generate a call to the column function.
1480 (ibuffer-aif (assq sym ibuffer-inline-columns
)
1482 `(,sym buffer mark
)))
1483 ;; You're not expected to understand this. Hell, I
1484 ;; don't even understand it, and I wrote it five
1486 (insertgenfn (ibuffer-aif (get sym
'ibuffer-column-summarizer
)
1487 ;; I really, really wish Emacs Lisp had closures.
1491 (put ',sym
'ibuffer-column-summary
1492 (cons ret
(get ',sym
'ibuffer-column-summary
)))
1496 (mincompform `(< strlen
,(if (integerp min
)
1499 (maxcompform `(> strlen
,(if (integerp max
)
1502 (if (or min-used max-used
)
1503 ;; The complex case, where we have to limit the
1504 ;; form to a maximum or minimum size.
1506 (when (and min-used
(not (integerp min
)))
1507 (push `(min ,min
) letbindings
))
1508 (when (and max-used
(not (integerp max
)))
1509 (push `(max ,max
) letbindings
))
1511 (if (and min-used max-used
)
1523 `(setq str
,callform
)
1525 `(strlen (length str
))))
1528 (append outforms
(list (funcall insertgenfn
'str sym
)))))
1529 ;; The simple case; just insert the string.
1530 (push (funcall insertgenfn callform sym
) outforms
))
1531 ;; Finally, return a `let' form which binds the
1532 ;; variables in `letbindings', and contains all the
1533 ;; code in `outforms'.
1538 ;; We don't want to unconditionally load the byte-compiler.
1539 (funcall (if (or ibuffer-always-compile-formats
1540 (featurep 'bytecomp
))
1543 ;; Here, we actually create a lambda form which
1544 ;; inserts all the generated forms for each entry
1545 ;; in the format string.
1546 (nconc (list 'lambda
'(buffer mark
))
1547 `((let ,(append (when str-used
1549 (when global-strlen-used
1555 ,@(nreverse result
))))))))
1557 (defvar ibuffer-compiled-formats nil
)
1558 (defvar ibuffer-cached-formats nil
)
1559 (defvar ibuffer-cached-eliding-string nil
)
1560 (defvar ibuffer-cached-elide-long-columns
0)
1562 (defun ibuffer-recompile-formats ()
1563 "Recompile `ibuffer-formats'."
1565 (setq ibuffer-compiled-formats
1566 (mapcar #'ibuffer-compile-format ibuffer-formats
))
1567 (when (boundp 'ibuffer-filter-format-alist
)
1568 (setq ibuffer-compiled-filter-formats
1569 (mapcar #'(lambda (entry)
1571 (mapcar #'(lambda (formats)
1572 (mapcar #'ibuffer-compile-format formats
))
1574 ibuffer-filter-format-alist
))))
1576 (defun ibuffer-clear-summary-columns (format)
1577 (dolist (form format
)
1578 (ibuffer-awhen (and (consp form
)
1579 (get (car form
) 'ibuffer-column-summarizer
))
1580 (put (car form
) 'ibuffer-column-summary nil
))))
1582 (defun ibuffer-check-formats ()
1583 (when (null ibuffer-formats
)
1584 (error "No formats!"))
1585 (let ((ext-loaded (featurep 'ibuf-ext
)))
1586 (when (or (null ibuffer-compiled-formats
)
1587 (null ibuffer-cached-formats
)
1588 (not (eq ibuffer-cached-formats ibuffer-formats
))
1589 (null ibuffer-cached-eliding-string
)
1590 (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string
))
1591 (eql 0 ibuffer-cached-elide-long-columns
)
1592 (not (eql ibuffer-cached-elide-long-columns
1593 ibuffer-elide-long-columns
))
1595 (not (eq ibuffer-cached-filter-formats
1596 ibuffer-filter-format-alist
))
1597 (and ibuffer-filter-format-alist
1598 (null ibuffer-compiled-filter-formats
))))
1599 (message "Formats have changed, recompiling...")
1600 (ibuffer-recompile-formats)
1601 (setq ibuffer-cached-formats ibuffer-formats
1602 ibuffer-cached-eliding-string ibuffer-eliding-string
1603 ibuffer-cached-elide-long-columns ibuffer-elide-long-columns
)
1605 (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist
))
1606 (message "Formats have changed, recompiling...done"))))
1608 (defvar ibuffer-inline-columns nil
)
1610 (define-ibuffer-column mark
(:name
" " :inline t
)
1613 (define-ibuffer-column read-only
(:name
"R" :inline t
)
1614 (if buffer-read-only
1615 (string ibuffer-read-only-char
)
1618 (define-ibuffer-column modified
(:name
"M" :inline t
)
1619 (if (buffer-modified-p)
1620 (string ibuffer-modified-char
)
1623 (define-ibuffer-column name
1626 ('mouse-face
'highlight
'keymap ibuffer-name-map
1627 'ibuffer-name-column t
1628 'help-echo
'(if tooltip-mode
1629 "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"
1630 "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate"))
1633 (let ((bufs (length strings
)))
1634 (cond ((zerop bufs
) "No buffers")
1635 ((= 1 bufs
) "1 buffer")
1636 (t (format "%s buffers" bufs
))))))
1637 (propertize (buffer-name) 'font-lock-face
(ibuffer-buffer-name-face buffer mark
)))
1639 (define-ibuffer-column size
1642 (lambda (column-strings)
1644 (dolist (string column-strings
)
1647 (+ (float (string-to-int string
))
1649 (format "%.0f" total
))))
1650 (format "%s" (buffer-size)))
1652 (define-ibuffer-column mode
(:inline t
1654 ('mouse-face
'highlight
1655 'keymap ibuffer-mode-name-map
1656 'help-echo
"mouse-2: filter by this mode"))
1657 (format "%s" mode-name
))
1659 (define-ibuffer-column process
1662 (let ((total (length (delete "" strings
))))
1663 (cond ((zerop total
) "No processes")
1664 ((= 1 total
) "1 process")
1665 (t (format "%d processes" total
))))))
1666 (ibuffer-aif (get-buffer-process buffer
)
1667 (format "(%s %s)" it
(process-status it
))
1670 (define-ibuffer-column filename
1673 (let ((total (length (delete "" strings
))))
1674 (cond ((zerop total
) "No files")
1675 ((= 1 total
) "1 file")
1676 (t (format "%d files" total
))))))
1677 (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist
))
1678 (abbreviate-file-name
1679 (or buffer-file-name
1680 (and (boundp 'dired-directory
)
1684 (define-ibuffer-column filename-and-process
1685 (:name
"Filename/Process"
1688 (setq strings
(delete "" strings
))
1691 (dolist (string strings
)
1692 (if (string-match "\\(\?:\\`(\[\[:ascii:\]\]\+)\\)" string
)
1693 (progn (setq procs
(1+ procs
))
1694 (if (< (match-end 0) (length string
))
1695 (setq files
(1+ files
))))
1696 (setq files
(1+ files
))))
1697 (concat (cond ((zerop files
) "No files")
1698 ((= 1 files
) "1 file")
1699 (t (format "%d files" files
)))
1701 (cond ((zerop procs
) "no processes")
1702 ((= 1 procs
) "1 process")
1703 (t (format "%d processes" procs
)))))))
1704 (let ((proc (get-buffer-process buffer
))
1705 (filename (ibuffer-make-column-filename buffer mark
)))
1707 (concat (propertize (format "(%s %s)" proc
(process-status proc
))
1708 'font-lock-face
'italic
)
1709 (if (> (length filename
) 0)
1710 (format " %s" filename
)
1714 (defun ibuffer-format-column (str width alignment
)
1715 (let ((left (make-string (/ width
2) ?
))
1716 (right (make-string (- width
(/ width
2)) ?
)))
1718 (:right
(concat left right str
))
1719 (:center
(concat left str right
))
1720 (t (concat str left right
)))))
1722 (defun ibuffer-buffer-name-face (buf mark
)
1723 (cond ((char-equal mark ibuffer-marked-char
)
1724 ibuffer-marked-face
)
1725 ((char-equal mark ibuffer-deletion-char
)
1726 ibuffer-deletion-face
)
1730 (dolist (e ibuffer-fontification-alist result
)
1731 (when (and (> (car e
) level
)
1732 (with-current-buffer buf
1735 result
(nth 2 e
))))))))
1737 (defun ibuffer-insert-buffer-line (buffer mark format
)
1738 "Insert a line describing BUFFER and MARK using FORMAT."
1739 (assert (eq major-mode
'ibuffer-mode
))
1740 (let ((beg (point)))
1741 (funcall format buffer mark
)
1742 (put-text-property beg
(point) 'ibuffer-properties
(list buffer mark
)))
1745 ;; This function knows a bit too much of the internals. It would be
1746 ;; nice if it was all abstracted away.
1747 (defun ibuffer-redisplay-current ()
1748 (assert (eq major-mode
'ibuffer-mode
))
1752 (let ((curformat (mapcar #'ibuffer-expand-format-entry
1753 (ibuffer-current-format t
))))
1754 (ibuffer-clear-summary-columns curformat
)
1755 (let ((buf (ibuffer-current-buffer)))
1757 (let ((mark (ibuffer-current-mark)))
1759 (delete-region (point) (1+ (line-end-position)))
1760 (ibuffer-insert-buffer-line
1762 (ibuffer-current-format)))
1763 (when ibuffer-shrink-to-minimum-size
1764 (ibuffer-shrink-to-fit)))))))
1766 (defun ibuffer-map-on-mark (mark func
)
1769 (if (char-equal mark mk
)
1770 (funcall func buf mark
)
1773 (defun ibuffer-map-lines (function &optional nomodify group
)
1774 "Call FUNCTION for each buffer.
1775 Don't set the ibuffer modification flag iff NOMODIFY is non-nil.
1777 If optional argument GROUP is non-nil, then only call FUNCTION on
1778 buffers in filtering group GROUP.
1780 FUNCTION is called with two arguments:
1781 the buffer object itself and the current mark symbol."
1782 (assert (eq major-mode
'ibuffer-mode
))
1783 (ibuffer-forward-line 0)
1784 (let* ((orig-target-line (1+ (count-lines (save-excursion
1785 (goto-char (point-min))
1786 (ibuffer-forward-line 0)
1789 (target-line-offset orig-target-line
)
1790 (ibuffer-map-lines-total 0)
1791 (ibuffer-map-lines-count 0))
1794 (setq buffer-read-only nil
)
1795 (goto-char (point-min))
1796 (ibuffer-forward-line 0 t
)
1797 (while (and (not (eobp))
1798 (not (get-text-property (point) 'ibuffer-summary
))
1800 (ibuffer-forward-line 0 t
)
1802 (not (get-text-property (point) 'ibuffer-summary
)))))
1804 (if (buffer-live-p (ibuffer-current-buffer))
1805 (when (or (null group
)
1806 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group
)
1810 (ibuffer-current-buffer)
1811 (ibuffer-current-mark))))
1812 ;; Kill the line if the buffer is dead
1814 ;; A given mapping function should return:
1815 ;; `nil' if it chose not to affect the buffer
1816 ;; `kill' means the remove line from the buffer list
1818 (incf ibuffer-map-lines-total
)
1819 (cond ((null result
)
1822 (delete-region (line-beginning-position)
1823 (1+ (line-end-position)))
1824 (incf ibuffer-map-lines-count
)
1825 (when (< ibuffer-map-lines-total
1827 (decf target-line-offset
)))
1829 (incf ibuffer-map-lines-count
)
1830 (forward-line 1)))))
1831 ibuffer-map-lines-count
)
1833 (setq buffer-read-only t
)
1835 (set-buffer-modified-p nil
))
1836 (goto-char (point-min))
1837 (ibuffer-forward-line 0)
1838 (ibuffer-forward-line (1- target-line-offset
))))))
1840 (defun ibuffer-get-marked-buffers ()
1841 "Return a list of buffer objects currently marked."
1843 (mapcar #'(lambda (e)
1844 (when (eq (cdr e
) ibuffer-marked-char
)
1846 (ibuffer-current-state-list))))
1848 (defun ibuffer-current-state-list (&optional pos
)
1849 "Return a list like (BUF . MARK) of all buffers in an ibuffer.
1850 If POS is non-nil, return a list like (BUF MARK POINT), where POINT is
1851 the value of point at the beginning of the line for that buffer."
1852 (let ((ibuffer-current-state-list-tmp '()))
1853 ;; ah, if only we had closures. I bet this will mysteriously
1854 ;; break later. Don't blame me.
1856 (ibuffer-map-lines-nomodify
1857 #'(lambda (buf mark
)
1858 (when (buffer-live-p buf
)
1859 (push (list buf mark
(point)) ibuffer-current-state-list-tmp
))))
1860 (ibuffer-map-lines-nomodify
1861 #'(lambda (buf mark
)
1862 (when (buffer-live-p buf
)
1863 (push (cons buf mark
) ibuffer-current-state-list-tmp
)))))
1864 (nreverse ibuffer-current-state-list-tmp
)))
1866 (defun ibuffer-current-buffers-with-marks (curbufs)
1867 "Return a list like (BUF . MARK) of all open buffers."
1868 (let ((bufs (ibuffer-current-state-list)))
1869 (mapcar #'(lambda (buf) (let ((e (assq buf bufs
)))
1875 (defun ibuffer-buf-matches-predicates (buf predicates
)
1877 (name (buffer-name buf
)))
1878 (dolist (pred predicates
)
1879 (when (if (stringp pred
)
1880 (string-match pred name
)
1885 (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all
)
1886 (let ((ext-loaded (featurep 'ibuf-ext
)))
1889 ;; element should be like (BUFFER . MARK)
1891 (let* ((buf (car e
)))
1893 ;; This takes precedence over anything else
1894 (or (and ibuffer-always-show-last-buffer
1896 (funcall (if ext-loaded
1897 #'ibuffer-ext-visible-p
1898 #'ibuffer-visible-p
)
1899 buf all ibuffer-buf
))
1903 (defun ibuffer-visible-p (buf all
&optional ibuffer-buf
)
1906 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates
)))
1907 (or ibuffer-view-ibuffer
1909 (not (eq ibuffer-buf buf
))))))
1911 ;; This function is a special case; it's not defined by
1912 ;; `ibuffer-define-sorter'.
1913 (defun ibuffer-do-sort-by-recency ()
1914 "Sort the buffers by last view time."
1916 (setq ibuffer-sorting-mode
'recency
)
1917 (ibuffer-redisplay t
))
1919 (defun ibuffer-update-format ()
1920 (when (null ibuffer-current-format
)
1921 (setq ibuffer-current-format
0))
1922 (when (null ibuffer-formats
)
1923 (error "Ibuffer error: no formats!")))
1925 (defun ibuffer-switch-format ()
1926 "Switch the current display format."
1928 (assert (eq major-mode
'ibuffer-mode
))
1929 (unless (consp ibuffer-formats
)
1930 (error "Ibuffer error: No formats!"))
1931 (setq ibuffer-current-format
1932 (if (>= ibuffer-current-format
(1- (length (ibuffer-current-formats nil
))))
1934 (1+ ibuffer-current-format
)))
1935 (ibuffer-update-format)
1936 (ibuffer-redisplay t
))
1938 (defun ibuffer-update-title-and-summary (format)
1939 (assert (eq major-mode
'ibuffer-mode
))
1940 ;; Don't do funky font-lock stuff here
1941 (let ((after-change-functions nil
))
1942 (if (get-text-property (point-min) 'ibuffer-title
)
1943 (delete-region (point-min)
1944 (next-single-property-change
1945 (point-min) 'ibuffer-title
)))
1946 (goto-char (point-min))
1947 (add-text-properties
1950 (let ((opos (point)))
1951 ;; Insert the title names.
1952 (dolist (element format
)
1954 (if (stringp element
)
1956 (let ((sym (car element
))
1957 (min (cadr element
))
1958 ;; (max (caddr element))
1959 (align (cadddr element
)))
1960 ;; Ignore a negative min when we're inserting the title
1963 (let* ((name (or (get sym
'ibuffer-column-name
)
1964 (error "Unknown column %s in ibuffer-formats" sym
)))
1965 (len (length name
)))
1967 (ibuffer-format-column name
1971 (add-text-properties opos
(point) `(ibuffer-title-header t
))
1973 ;; Add the underlines
1974 (let ((str (save-excursion
1977 (buffer-substring (point) (line-end-position)))))
1978 (apply #'insert
(mapcar
1980 (if (not (or (char-equal c ?
)
1981 (char-equal c ?
\n)))
1987 `(ibuffer-title t font-lock-face
,ibuffer-title-face
))
1988 ;; Now, insert the summary columns.
1989 (goto-char (point-max))
1990 (if (get-text-property (1- (point-max)) 'ibuffer-summary
)
1991 (delete-region (previous-single-property-change
1992 (point-max) 'ibuffer-summary
)
1994 (if ibuffer-display-summary
1995 (add-text-properties
1999 (dolist (element format
)
2001 (if (stringp element
)
2002 (make-string (length element
) ?
)
2003 (let ((sym (car element
)))
2004 (let ((min (cadr element
))
2005 ;; (max (caddr element))
2006 (align (cadddr element
)))
2007 ;; Ignore a negative min when we're inserting the title
2010 (let* ((summary (if (get sym
'ibuffer-column-summarizer
)
2011 (funcall (get sym
'ibuffer-column-summarizer
)
2012 (get sym
'ibuffer-column-summary
))
2013 (make-string (length (get sym
'ibuffer-column-name
))
2015 (len (length summary
)))
2017 (ibuffer-format-column summary
2022 `(ibuffer-summary t
)))))
2024 (defun ibuffer-update-mode-name ()
2025 (setq mode-name
(format "Ibuffer by %s" (if ibuffer-sorting-mode
2026 ibuffer-sorting-mode
2028 (when ibuffer-sorting-reversep
2029 (setq mode-name
(concat mode-name
" [rev]")))
2030 (when (and (featurep 'ibuf-ext
)
2032 (setq mode-name
(concat mode-name
" (Auto)")))
2034 (when (featurep 'ibuf-ext
)
2035 (dolist (qualifier ibuffer-filtering-qualifiers
)
2037 (concat result
(ibuffer-format-qualifier qualifier
))))
2038 (if ibuffer-use-header-line
2039 (setq header-line-format
2040 (when ibuffer-filtering-qualifiers
2041 (replace-regexp-in-string "%" "%%"
2042 (concat mode-name result
))))
2044 (setq mode-name
(concat mode-name result
))
2045 (when (boundp 'header-line-format
)
2046 (setq header-line-format nil
)))))))
2048 (defun ibuffer-redisplay (&optional silent
)
2049 "Redisplay the current list of buffers.
2050 This does not show new buffers; use `ibuffer-update' for that.
2052 If optional arg SILENT is non-nil, do not display progress messages."
2054 (ibuffer-forward-line 0)
2056 (message "Redisplaying current buffer list..."))
2057 (let ((blist (ibuffer-current-state-list)))
2059 (if (and (featurep 'ibuf-ext
)
2060 (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups
))
2061 (message "No buffers! (note: filtering in effect)")
2062 (error "No buffers!")))
2063 (ibuffer-redisplay-engine blist t
)
2064 (ibuffer-update-mode-name)
2066 (message "Redisplaying current buffer list...done"))
2067 (ibuffer-forward-line 0)))
2069 (defun ibuffer-update (arg &optional silent
)
2070 "Regenerate the list of all buffers.
2071 Display buffers whose name matches one of `ibuffer-maybe-show-predicates'
2072 iff arg ARG is non-nil.
2074 If optional arg SILENT is non-nil, do not display progress messages."
2076 (ibuffer-forward-line 0)
2077 (let* ((bufs (buffer-list))
2078 (blist (ibuffer-filter-buffers
2082 (eq ibuffer-always-show-last-buffer
2084 (minibufferp (cadr bufs
)))
2087 (ibuffer-current-buffers-with-marks bufs
)
2090 (if (and (featurep 'ibuf-ext
)
2091 ibuffer-filtering-qualifiers
)
2092 (message "No buffers! (note: filtering in effect)")
2093 (error "No buffers!")))
2095 (message "Updating buffer list..."))
2096 (ibuffer-redisplay-engine blist arg
)
2097 (ibuffer-update-mode-name)
2099 (message "Updating buffer list...done")))
2100 (if (eq ibuffer-shrink-to-minimum-size
'onewindow
)
2101 (ibuffer-shrink-to-fit t
)
2102 (when ibuffer-shrink-to-minimum-size
2103 (ibuffer-shrink-to-fit)))
2104 (ibuffer-forward-line 0))
2106 (defun ibuffer-sort-bufferlist (bmarklist)
2107 (let* ((sortdat (assq ibuffer-sorting-mode
2108 ibuffer-sorting-functions-alist
))
2109 (func (caddr sortdat
)))
2111 ;; actually sort the buffers
2112 (if (and sortdat func
)
2113 (sort bmarklist func
)
2115 ;; perhaps reverse the sorted buffer list
2116 (if ibuffer-sorting-reversep
2120 (defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist
)
2121 (add-text-properties
2124 (insert "[ " display-name
" ]")
2126 `(ibuffer-filter-group-name
2128 font-lock-face
,ibuffer-filter-group-name-face
2129 keymap
,ibuffer-mode-filter-group-map
2130 mouse-face highlight
2131 help-echo
,(let ((echo '(if tooltip-mode
2132 "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group"
2133 "mouse-1: toggle marks mouse-2: hide/show")))
2134 (if (> (length filter-string
) 0)
2135 `(concat ,filter-string
2136 (if tooltip-mode
"\n" " ")
2144 (dolist (entry bmarklist
)
2145 (ibuffer-insert-buffer-line (car entry
) (cdr entry
) format
))
2147 'ibuffer-filter-group
2150 (defun ibuffer-redisplay-engine (bmarklist &optional all
)
2151 (assert (eq major-mode
'ibuffer-mode
))
2152 (let* ((--ibuffer-insert-buffers-and-marks-format
2153 (ibuffer-current-format))
2154 (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry
2155 (ibuffer-current-format t
)))
2156 (orig (count-lines (point-min) (point)))
2157 ;; Inhibit font-lock caching tricks, since we're modifying the
2158 ;; entire buffer at once
2159 (after-change-functions nil
)
2160 (ext-loaded (featurep 'ibuf-ext
))
2161 (bgroups (if ext-loaded
2162 (ibuffer-generate-filter-groups bmarklist
)
2163 (list (cons "Default" bmarklist
)))))
2164 (ibuffer-clear-summary-columns --ibuffer-expanded-format
)
2167 (setq buffer-read-only nil
)
2169 (ibuffer-update-format)
2170 (dolist (group (nreverse bgroups
))
2171 (let* ((name (car group
))
2172 (disabled (and ext-loaded
2173 (member name ibuffer-hidden-filter-groups
)))
2174 (bmarklist (cdr group
)))
2175 (unless (and (null bmarklist
)
2178 (null ibuffer-show-empty-filter-groups
))
2179 (ibuffer-insert-filter-group
2181 (if disabled
(concat name
" ...") name
)
2183 (ibuffer-format-filter-group-data name
)
2185 --ibuffer-insert-buffers-and-marks-format
2188 (ibuffer-sort-bufferlist bmarklist
))))))
2189 (ibuffer-update-title-and-summary --ibuffer-expanded-format
))
2190 (setq buffer-read-only t
)
2191 (set-buffer-modified-p ibuffer-did-modification
)
2192 (setq ibuffer-did-modification nil
)
2193 (goto-line (1+ orig
)))))
2195 (defun ibuffer-quit ()
2196 "Quit this `ibuffer' session.
2197 Try to restore the previous window configuration iff
2198 `ibuffer-restore-window-config-on-quit' is non-nil."
2200 (if ibuffer-restore-window-config-on-quit
2203 (unless (= (count-windows) 1)
2204 (set-window-configuration ibuffer-prev-window-config
)))
2208 (defun ibuffer-list-buffers (&optional files-only
)
2209 "Display a list of buffers, in another window.
2210 If optional argument FILES-ONLY is non-nil, then add a filter for
2211 buffers which are visiting a file."
2213 (ibuffer t nil
(when files-only
2214 '((filename .
".*"))) t
))
2217 (defun ibuffer-other-window (&optional files-only
)
2218 "Like `ibuffer', but displayed in another window by default.
2219 If optional argument FILES-ONLY is non-nil, then add a filter for
2220 buffers which are visiting a file."
2222 (ibuffer t nil
(when files-only
2223 '((filename .
".*")))))
2226 (defun ibuffer (&optional other-window-p name qualifiers noselect
2227 shrink filter-groups formats
)
2228 "Begin using `ibuffer' to edit a list of buffers.
2229 Type 'h' after entering ibuffer for more information.
2231 Optional argument OTHER-WINDOW-P says to use another window.
2232 Optional argument NAME specifies the name of the buffer; it defaults
2234 Optional argument QUALIFIERS is an initial set of filtering qualifiers
2235 to use; see `ibuffer-filtering-qualifiers'.
2236 Optional argument NOSELECT means don't select the Ibuffer buffer.
2237 Optional argument SHRINK means shrink the buffer to minimal size. The
2238 special value `onewindow' means always use another window.
2239 Optional argument FILTER-GROUPS is an initial set of filtering
2240 groups to use; see `ibuffer-filter-groups'.
2241 Optional argument FORMATS is the value to use for `ibuffer-formats'.
2242 If specified, then the variable `ibuffer-formats' will have that value
2243 locally in this buffer."
2245 (when ibuffer-use-other-window
2246 (setq other-window-p t
))
2247 (setq ibuffer-prev-window-config
(current-window-configuration))
2248 (let ((buf (get-buffer-create (or name
"*Ibuffer*"))))
2250 (funcall (if noselect
#'(lambda (buf) (display-buffer buf t
)) #'pop-to-buffer
) buf
)
2251 (funcall (if noselect
#'display-buffer
#'switch-to-buffer
) buf
))
2252 (with-current-buffer buf
2253 (save-selected-window
2254 ;; We switch to the buffer's window in order to be able
2255 ;; to modify the value of point
2256 (select-window (get-buffer-window buf
))
2257 (or (eq major-mode
'ibuffer-mode
)
2259 (setq ibuffer-restore-window-config-on-quit other-window-p
)
2261 (setq ibuffer-shrink-to-minimum-size shrink
))
2264 (setq ibuffer-filtering-qualifiers qualifiers
))
2267 (setq ibuffer-filter-groups filter-groups
))
2269 (set (make-local-variable 'ibuffer-formats
) formats
))
2270 (ibuffer-update nil
)
2271 ;; Skip the group name by default.
2272 (ibuffer-forward-line 0 t
)
2275 (setq buffer-read-only nil
)
2276 (run-hooks 'ibuffer-hook
))
2277 (setq buffer-read-only t
))
2278 (unless ibuffer-expert
2279 (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))))))
2281 (put 'ibuffer-mode
'mode-class
'special
)
2282 (defun ibuffer-mode ()
2283 "A major mode for viewing a list of buffers.
2284 In ibuffer, you can conveniently perform many operations on the
2285 currently open buffers, in addition to filtering your view to a
2286 particular subset of them, and sorting by various criteria.
2288 Operations on marked buffers:
2290 '\\[ibuffer-do-save]' - Save the marked buffers
2291 '\\[ibuffer-do-view]' - View the marked buffers in this frame.
2292 '\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame.
2293 '\\[ibuffer-do-revert]' - Revert the marked buffers.
2294 '\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers.
2295 '\\[ibuffer-do-delete]' - Kill the marked buffers.
2296 '\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked
2298 '\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers.
2299 '\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression.
2300 '\\[ibuffer-do-print]' - Print the marked buffers.
2301 '\\[ibuffer-do-occur]' - List lines in all marked buffers which match
2302 a given regexp (like the function `occur').
2303 '\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked
2304 buffers to a shell command.
2305 '\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked
2306 buffers with the output of a shell command.
2307 '\\[ibuffer-do-shell-command-file]' - Run a shell command with the
2308 buffer's file as an argument.
2309 '\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This
2310 is a very flexible command. For example, if you want to make all
2311 of the marked buffers read only, try using (toggle-read-only 1) as
2313 '\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form
2315 '\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer,
2316 but don't kill the associated buffer.
2317 '\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion.
2321 '\\[ibuffer-mark-forward]' - Mark the buffer at point.
2322 '\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark
2323 all unmarked buffers.
2324 '\\[ibuffer-unmark-forward]' - Unmark the buffer at point.
2325 '\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the
2327 '\\[ibuffer-unmark-all]' - Unmark all marked buffers.
2328 '\\[ibuffer-mark-by-mode]' - Mark buffers by major mode.
2329 '\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers.
2330 This means that the buffer is modified, and has an associated file.
2331 '\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers,
2332 regardless of whether or not they have an associated file.
2333 '\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and
2335 '\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have
2336 an associated file, but that file doesn't currently exist.
2337 '\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers.
2338 '\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode.
2339 '\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc.
2340 '\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'.
2341 '\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion.
2342 '\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp.
2343 '\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp.
2344 '\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp.
2348 '\\[ibuffer-filter-by-mode]' - Add a filter by major mode.
2349 '\\[ibuffer-filter-by-used-mode]' - Add a filter by major mode now in use.
2350 '\\[ibuffer-filter-by-name]' - Add a filter by buffer name.
2351 '\\[ibuffer-filter-by-content]' - Add a filter by buffer content.
2352 '\\[ibuffer-filter-by-filename]' - Add a filter by filename.
2353 '\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size.
2354 '\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size.
2355 '\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate.
2356 '\\[ibuffer-save-filters]' - Save the current filters with a name.
2357 '\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters.
2358 '\\[ibuffer-add-saved-filters]' - Add saved filters to current filters.
2359 '\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR.
2360 '\\[ibuffer-pop-filter]' - Remove the top filter.
2361 '\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter.
2362 '\\[ibuffer-decompose-filter]' - Break down the topmost filter.
2363 '\\[ibuffer-filter-disable]' - Remove all filtering currently in effect.
2365 Filter group commands:
2367 '\\[ibuffer-filters-to-filter-group]' - Create filter group from filters.
2368 '\\[ibuffer-pop-filter-group]' - Remove top filter group.
2369 '\\[ibuffer-forward-filter-group]' - Move to the next filter group.
2370 '\\[ibuffer-backward-filter-group]' - Move to the previous filter group.
2371 '\\[ibuffer-clear-filter-groups]' - Remove all active filter groups.
2372 '\\[ibuffer-save-filter-groups]' - Save the current groups with a name.
2373 '\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups.
2374 '\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups.
2378 '\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes.
2379 '\\[ibuffer-invert-sorting]' - Reverse the current sorting order.
2380 '\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically.
2381 '\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time.
2382 '\\[ibuffer-do-sort-by-size]' - Sort the buffers by size.
2383 '\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode.
2387 '\\[ibuffer-switch-format]' - Change the current display format.
2388 '\\[forward-line]' - Move point to the next line.
2389 '\\[previous-line]' - Move point to the previous line.
2390 '\\[ibuffer-update]' - As above, but add new buffers to the list.
2391 '\\[ibuffer-quit]' - Bury the Ibuffer buffer.
2392 '\\[describe-mode]' - This help.
2393 '\\[ibuffer-diff-with-file]' - View the differences between this buffer
2394 and its associated file.
2395 '\\[ibuffer-visit-buffer]' - View the buffer on this line.
2396 '\\[ibuffer-visit-buffer-other-window]' - As above, but in another window.
2397 '\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select
2399 '\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line.
2401 ** Information on Filtering:
2403 You can filter your ibuffer view via different critera. Each Ibuffer
2404 buffer has its own stack of active filters. For example, suppose you
2405 are working on an Emacs Lisp project. You can create an Ibuffer
2406 buffer displays buffers in just `emacs-lisp' modes via
2407 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there
2408 is just one entry on the filtering stack.
2410 You can also combine filters. The various filtering commands push a
2411 new filter onto the stack, and the filters combine to show just
2412 buffers which satisfy ALL criteria on the stack. For example, suppose
2413 you only want to see buffers in `emacs-lisp' mode, whose names begin
2414 with \"gnus\". You can accomplish this via:
2415 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2416 \\[ibuffer-filter-by-name] ^gnus RET'.
2418 Additionally, you can OR the top two filters together with
2419 '\\[ibuffer-or-filters]'. To see all buffers in either
2420 `emacs-lisp-mode' or `lisp-interaction-mode', type:
2422 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filter-by-mode] lisp-interaction-mode RET \\[ibuffer-or-filters]'.
2424 Filters can also be saved and restored using mnemonic names: see the
2425 functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'.
2427 To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and
2428 to disable all filtering currently in effect, use
2429 '\\[ibuffer-filter-disable]'.
2433 Once one has mastered filters, the next logical step up is \"filter
2434 groups\". A filter group is basically a named group of buffers which
2435 match a filter, which are displayed together in an Ibuffer buffer. To
2436 create a filter group, simply use the regular functions to create a
2437 filter, and then type '\\[ibuffer-filters-to-filter-group]'.
2439 A quick example will make things clearer. Suppose that one wants to
2440 group all of one's Emacs Lisp buffers together. To do this, type
2442 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filters-to-filter-group] RET emacs lisp buffers RET'
2444 You may, of course, name the group whatever you want; it doesn't have
2445 to be \"emacs lisp buffers\". Filter groups may be composed of any
2446 arbitrary combination of filters.
2448 Just like filters themselves, filter groups act as a stack. Buffers
2449 will not be displayed multiple times if they would be included in
2450 multiple filter groups; instead, the first filter group is used. The
2451 filter groups are displayed in this order of precedence.
2453 You may rearrange filter groups by using the regular
2454 '\\[ibuffer-kill-line]' and '\\[ibuffer-yank]' pair. Yanked groups
2455 will be inserted before the group at point."
2456 (kill-all-local-variables)
2457 (use-local-map ibuffer-mode-map
)
2458 (setq major-mode
'ibuffer-mode
)
2459 (setq mode-name
"Ibuffer")
2460 (setq buffer-read-only t
)
2461 (buffer-disable-undo)
2462 (setq truncate-lines ibuffer-truncate-lines
)
2463 ;; This makes things less ugly for Emacs 21 users with a non-nil
2464 ;; `show-trailing-whitespace'.
2465 (setq show-trailing-whitespace nil
)
2466 ;; disable `show-paren-mode' buffer-locally
2467 (if (bound-and-true-p show-paren-mode
)
2468 (set (make-local-variable 'show-paren-mode
) nil
))
2469 (set (make-local-variable 'revert-buffer-function
)
2471 (set (make-local-variable 'ibuffer-sorting-mode
)
2472 ibuffer-default-sorting-mode
)
2473 (set (make-local-variable 'ibuffer-sorting-reversep
)
2474 ibuffer-default-sorting-reversep
)
2475 (set (make-local-variable 'ibuffer-shrink-to-minimum-size
)
2476 ibuffer-default-shrink-to-minimum-size
)
2477 (set (make-local-variable 'ibuffer-filtering-qualifiers
) nil
)
2478 (set (make-local-variable 'ibuffer-filter-groups
) nil
)
2479 (set (make-local-variable 'ibuffer-filter-group-kill-ring
) nil
)
2480 (set (make-local-variable 'ibuffer-hidden-filter-groups
) nil
)
2481 (set (make-local-variable 'ibuffer-compiled-formats
) nil
)
2482 (set (make-local-variable 'ibuffer-cached-formats
) nil
)
2483 (set (make-local-variable 'ibuffer-cached-eliding-string
) nil
)
2484 (set (make-local-variable 'ibuffer-cached-elide-long-columns
) nil
)
2485 (set (make-local-variable 'ibuffer-current-format
) nil
)
2486 (set (make-local-variable 'ibuffer-restore-window-config-on-quit
) nil
)
2487 (set (make-local-variable 'ibuffer-did-modification
) nil
)
2488 (set (make-local-variable 'ibuffer-tmp-hide-regexps
) nil
)
2489 (set (make-local-variable 'ibuffer-tmp-show-regexps
) nil
)
2490 (define-key ibuffer-mode-map
[menu-bar edit
] 'undefined
)
2491 (define-key ibuffer-mode-map
[menu-bar operate
] (cons "Operate" ibuffer-mode-operate-map
))
2492 (ibuffer-update-format)
2493 (when ibuffer-default-directory
2494 (setq default-directory ibuffer-default-directory
))
2495 (add-hook 'change-major-mode-hook
'font-lock-defontify nil t
)
2496 (run-hooks 'ibuffer-mode-hook
)
2497 ;; called after mode hooks to allow the user to add filters
2498 (ibuffer-update-mode-name))
2502 (run-hooks 'ibuffer-load-hook
)
2505 ;; coding: iso-8859-1
2508 ;;; arch-tag: 72581688-0603-4954-b8cf-837c700f62e8
2509 ;;; ibuffer.el ends here