1 ;;; ibuffer.el --- operate on buffers like dired
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005 Free Software Foundation, Inc.
6 ;; Author: Colin Walters <walters@verbum.org>
7 ;; Maintainer: John Paul Wallington <jpw@gnu.org>
9 ;; Keywords: buffer, convenience
11 ;; This file is part of GNU Emacs.
13 ;; This program is free software; you can redistribute it and/or
14 ;; modify it under the terms of the GNU General Public License as
15 ;; published by the Free Software Foundation; either version 2, or (at
16 ;; your option) any later version.
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.
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
25 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
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.
43 ;; These come from ibuf-ext.el, which can not be require'd at compile time
44 ;; because it has a recursive dependency on ibuffer.el
45 (defvar ibuffer-auto-mode
)
46 (defvar ibuffer-cached-filter-formats
)
47 (defvar ibuffer-compiled-filter-formats
)
48 (defvar ibuffer-filter-format-alist
)
49 (defvar ibuffer-filter-group-kill-ring
)
50 (defvar ibuffer-filter-groups
)
51 (defvar ibuffer-filtering-qualifiers
)
52 (defvar ibuffer-hidden-filter-groups
)
53 (defvar ibuffer-inline-columns
)
54 (defvar ibuffer-show-empty-filter-groups
)
55 (defvar ibuffer-tmp-hide-regexps
)
56 (defvar ibuffer-tmp-show-regexps
)
59 "An advanced replacement for `buffer-menu'.
61 Ibuffer allows you to operate on buffers in a manner much like Dired.
62 Operations include sorting, marking by regular expression, and
63 the ability to filter the displayed buffers by various criteria."
67 (defcustom ibuffer-formats
'((mark modified read-only
" " (name 18 18 :left
:elide
)
68 " " (size 9 -
1 :right
)
69 " " (mode 16 16 :right
:elide
) " " filename-and-process
)
70 (mark " " (name 16 -
1) " " filename
))
71 "A list of ways to display buffer lines.
73 With Ibuffer, you are not limited to displaying just certain
74 attributes of a buffer such as size, name, and mode in a particular
75 order. Through this variable, you can completely customize and
76 control the appearance of an Ibuffer buffer. See also
77 `define-ibuffer-column', which allows you to define your own columns
80 This variable has the form
81 ((COLUMN COLUMN ...) (COLUMN COLUMN ...) ...)
82 Each element in `ibuffer-formats' should be a list containing COLUMN
83 specifiers. A COLUMN can be any of the following:
85 SYMBOL - A symbol naming the column. Predefined columns are:
86 mark modified read-only name size mode process filename
87 When you define your own columns using `define-ibuffer-column', just
88 use their name like the predefined columns here. This entry can
89 also be a function of two arguments, which should return a string.
90 The first argument is the buffer object, and the second is the mark
93 \"STRING\" - A literal string to display.
95 (SYMBOL MIN-SIZE MAX-SIZE &optional ALIGN ELIDE) - SYMBOL is a
96 symbol naming the column, and MIN-SIZE and MAX-SIZE are integers (or
97 functions of no arguments returning an integer) which constrict the
98 size of a column. If MAX-SIZE is -1, there is no upper bound. The
99 default values are 0 and -1, respectively. If MIN-SIZE is negative,
100 use the end of the string. The optional element ALIGN describes the
101 alignment of the column; it can be :left, :center or :right. The
102 optional element ELIDE describes whether or not to elide the column
103 if it is too long; valid values are :elide and nil. The default is
106 Some example of valid entries in `ibuffer-formats', with
107 description (also, feel free to try them out, and experiment with your
111 This format just displays the current mark (if any) and the name of
112 the buffer, separated by a space.
113 (mark modified read-only \" \" (name 16 16 :left) \" \" (size 6 -1 :right))
114 This format displays the current mark (if any), its modification and
115 read-only status, as well as the name of the buffer and its size. In
116 this format, the name is restricted to 16 characters (longer names
117 will be truncated, and shorter names will be padded with spaces), and
118 the name is also aligned to the left. The size of the buffer will
119 be padded with spaces up to a minimum of six characters, but there is
120 no upper limit on its size. The size will also be aligned to the
123 Thus, if you wanted to use these two formats, add
125 (setq ibuffer-formats '((mark \" \" name)
126 (mark modified read-only
127 (name 16 16 :left) (size 6 -1 :right))))
129 to your ~/.emacs file.
131 Using \\[ibuffer-switch-format], you can rotate the display between
132 the specified formats in the list."
136 (defcustom ibuffer-always-compile-formats
(featurep 'bytecomp
)
137 "If non-nil, then use the byte-compiler to optimize `ibuffer-formats'.
138 This will increase the redisplay speed, at the cost of loading the
139 elisp byte-compiler."
143 (defcustom ibuffer-fontification-alist
144 `((10 buffer-read-only font-lock-constant-face
)
145 (15 (string-match "^*" (buffer-name)) font-lock-keyword-face
)
146 (20 (and (string-match "^ " (buffer-name))
147 (null buffer-file-name
))
149 (25 (memq major-mode ibuffer-help-buffer-modes
) font-lock-comment-face
)
150 (30 (eq major-mode
'dired-mode
) font-lock-function-name-face
))
151 "An alist describing how to fontify buffers.
152 Each element should be of the form (PRIORITY FORM FACE), where
153 PRIORITY is an integer, FORM is an arbitrary form to evaluate in the
154 buffer, and FACE is the face to use for fontification. If the FORM
155 evaluates to non-nil, then FACE will be put on the buffer name. The
156 element with the highest PRIORITY takes precedence.
158 If you change this variable, you must kill the Ibuffer buffer and
159 recreate it for the change to take effect."
161 (list (integer :tag
"Priority")
162 (sexp :tag
"Test Form")
166 (defcustom ibuffer-use-other-window nil
167 "If non-nil, display Ibuffer in another window by default."
171 (defcustom ibuffer-default-shrink-to-minimum-size nil
172 "If non-nil, minimize the size of the Ibuffer window by default."
175 (defvar ibuffer-shrink-to-minimum-size nil
)
177 (defcustom ibuffer-display-summary t
178 "If non-nil, summarize Ibuffer columns."
182 (defcustom ibuffer-truncate-lines t
183 "If non-nil, do not display continuation lines."
187 (defcustom ibuffer-case-fold-search case-fold-search
188 "If non-nil, ignore case when searching."
192 (defcustom ibuffer-default-sorting-mode
'recency
193 "The criteria by which to sort the buffers.
195 Note that this variable is local to each Ibuffer buffer. Thus, you
196 can have multiple Ibuffer buffers open, each with a different sorted
197 view of the buffers."
198 :type
'(choice (const :tag
"Last view time" :value recency
)
199 (const :tag
"Lexicographic" :value alphabetic
)
200 (const :tag
"Buffer size" :value size
)
201 (const :tag
"Major mode" :value major-mode
))
203 (defvar ibuffer-sorting-mode nil
)
205 (defcustom ibuffer-default-sorting-reversep nil
206 "If non-nil, reverse the default sorting order."
209 (defvar ibuffer-sorting-reversep nil
)
211 (defcustom ibuffer-elide-long-columns nil
212 "If non-nil, then elide column entries which exceed their max length."
215 (make-obsolete-variable 'ibuffer-elide-long-columns
216 "use the :elide argument of `ibuffer-formats'."
219 (defcustom ibuffer-eliding-string
"..."
220 "The string to use for eliding long columns."
224 (defcustom ibuffer-maybe-show-predicates
`(,(lambda (buf)
225 (and (string-match "^ " (buffer-name buf
))
226 (null buffer-file-name
))))
227 "A list of predicates for buffers to display conditionally.
229 A predicate can be a regexp or a function.
230 If a regexp, then it will be matched against the buffer's name.
231 If a function, it will be called with the buffer as an argument, and
232 should return non-nil if this buffer should be shown.
234 Viewing of buffers hidden because of these predicates may be customized
235 via `ibuffer-default-display-maybe-show-predicates' and is toggled by
236 giving a non-nil prefix argument to `ibuffer-update'.
237 Note that this specialized filtering occurs before real filtering."
238 :type
'(repeat (choice regexp function
))
241 (defcustom ibuffer-default-display-maybe-show-predicates nil
242 "Non-nil means show buffers that match `ibuffer-maybe-show-predicates'."
246 (defvar ibuffer-display-maybe-show-predicates nil
)
248 (defvar ibuffer-current-format nil
)
250 (defcustom ibuffer-movement-cycle t
251 "If non-nil, then forward and backwards movement commands cycle."
255 (defcustom ibuffer-modified-char ?
*
256 "The character to display for modified buffers."
260 (defcustom ibuffer-read-only-char ?%
261 "The character to display for read-only buffers."
265 (defcustom ibuffer-marked-char ?
>
266 "The character to display for marked buffers."
270 (defcustom ibuffer-deletion-char ?D
271 "The character to display for buffers marked for deletion."
275 (defcustom ibuffer-expert nil
276 "If non-nil, don't ask for confirmation of \"dangerous\" operations."
280 (defcustom ibuffer-view-ibuffer nil
281 "If non-nil, display the current Ibuffer buffer itself.
282 Note that this has a drawback - the data about the current Ibuffer
283 buffer will most likely be inaccurate. This includes modification
288 (defcustom ibuffer-always-show-last-buffer nil
289 "If non-nil, always display the previous buffer.
290 This variable takes precedence over filtering, and even
291 `ibuffer-never-show-predicates'."
292 :type
'(choice (const :tag
"Always" :value t
)
293 (const :tag
"Never" :value nil
)
294 (const :tag
"Always except minibuffer" :value
:nomini
))
297 (defcustom ibuffer-jump-offer-only-visible-buffers nil
298 "If non-nil, only offer buffers visible in the Ibuffer buffer
299 in completion lists of the `ibuffer-jump-to-buffer' command."
303 (defcustom ibuffer-use-header-line
(boundp 'header-line-format
)
304 "If non-nil, display a header line containing current filters."
308 (defcustom ibuffer-default-directory nil
309 "The default directory to use for a new Ibuffer buffer.
310 If nil, inherit the directory of the buffer in which `ibuffer' was
311 called. Otherwise, this variable should be a string naming a
312 directory, like `default-directory'."
313 :type
'(choice (const :tag
"Inherit" :value nil
)
317 (defcustom ibuffer-help-buffer-modes
318 '(help-mode apropos-mode Info-mode Info-edit-mode
)
319 "List of \"Help\" major modes."
320 :type
'(repeat function
)
323 (defcustom ibuffer-hook nil
324 "Hook run when `ibuffer' is called."
327 (define-obsolete-variable-alias 'ibuffer-hooks
328 'ibuffer-hook
"22.1")
330 (defcustom ibuffer-mode-hook nil
331 "Hook run upon entry into `ibuffer-mode'."
334 (define-obsolete-variable-alias 'ibuffer-mode-hooks
335 'ibuffer-mode-hook
"22.1")
337 (defcustom ibuffer-load-hook nil
338 "Hook run when Ibuffer is loaded."
342 (defcustom ibuffer-marked-face
'font-lock-warning-face
343 "Face used for displaying marked buffers."
347 (defcustom ibuffer-deletion-face
'font-lock-type-face
348 "Face used for displaying buffers marked for deletion."
352 (defcustom ibuffer-title-face
'font-lock-type-face
353 "Face used for the title string."
357 (defcustom ibuffer-filter-group-name-face
'bold
358 "Face used for displaying filtering group names."
362 (defcustom ibuffer-directory-abbrev-alist nil
363 "An alist of file name abbreviations like `directory-abbrev-alist'."
364 :type
'(repeat (cons :format
"%v"
371 (defvar ibuffer-mode-map nil
)
372 (defvar ibuffer-mode-operate-map nil
)
373 (defvar ibuffer-mode-groups-popup nil
)
374 (unless ibuffer-mode-map
375 (let ((map (make-sparse-keymap))
376 (operate-map (make-sparse-keymap "Operate"))
377 (groups-map (make-sparse-keymap "Filter Groups")))
378 (define-key map
(kbd "0") 'digit-argument
)
379 (define-key map
(kbd "1") 'digit-argument
)
380 (define-key map
(kbd "2") 'digit-argument
)
381 (define-key map
(kbd "3") 'digit-argument
)
382 (define-key map
(kbd "4") 'digit-argument
)
383 (define-key map
(kbd "5") 'digit-argument
)
384 (define-key map
(kbd "6") 'digit-argument
)
385 (define-key map
(kbd "7") 'digit-argument
)
386 (define-key map
(kbd "8") 'digit-argument
)
387 (define-key map
(kbd "9") 'digit-argument
)
389 (define-key map
(kbd "m") 'ibuffer-mark-forward
)
390 (define-key map
(kbd "t") 'ibuffer-toggle-marks
)
391 (define-key map
(kbd "u") 'ibuffer-unmark-forward
)
392 (define-key map
(kbd "=") 'ibuffer-diff-with-file
)
393 (define-key map
(kbd "j") 'ibuffer-jump-to-buffer
)
394 (define-key map
(kbd "M-g") 'ibuffer-jump-to-buffer
)
395 (define-key map
(kbd "DEL") 'ibuffer-unmark-backward
)
396 (define-key map
(kbd "M-DEL") 'ibuffer-unmark-all
)
397 (define-key map
(kbd "* *") 'ibuffer-unmark-all
)
398 (define-key map
(kbd "* M") 'ibuffer-mark-by-mode
)
399 (define-key map
(kbd "* m") 'ibuffer-mark-modified-buffers
)
400 (define-key map
(kbd "* u") 'ibuffer-mark-unsaved-buffers
)
401 (define-key map
(kbd "* s") 'ibuffer-mark-special-buffers
)
402 (define-key map
(kbd "* r") 'ibuffer-mark-read-only-buffers
)
403 (define-key map
(kbd "* /") 'ibuffer-mark-dired-buffers
)
404 (define-key map
(kbd "* e") 'ibuffer-mark-dissociated-buffers
)
405 (define-key map
(kbd "* h") 'ibuffer-mark-help-buffers
)
406 (define-key map
(kbd ".") 'ibuffer-mark-old-buffers
)
408 (define-key map
(kbd "d") 'ibuffer-mark-for-delete
)
409 (define-key map
(kbd "C-d") 'ibuffer-mark-for-delete-backwards
)
410 (define-key map
(kbd "k") 'ibuffer-mark-for-delete
)
411 (define-key map
(kbd "x") 'ibuffer-do-kill-on-deletion-marks
)
413 ;; immediate operations
414 (define-key map
(kbd "n") 'ibuffer-forward-line
)
415 (define-key map
(kbd "<down>") 'ibuffer-forward-line
)
416 (define-key map
(kbd "SPC") 'forward-line
)
417 (define-key map
(kbd "p") 'ibuffer-backward-line
)
418 (define-key map
(kbd "<up>") 'ibuffer-backward-line
)
419 (define-key map
(kbd "M-}") 'ibuffer-forward-next-marked
)
420 (define-key map
(kbd "M-{") 'ibuffer-backwards-next-marked
)
421 (define-key map
(kbd "l") 'ibuffer-redisplay
)
422 (define-key map
(kbd "g") 'ibuffer-update
)
423 (define-key map
"`" 'ibuffer-switch-format
)
424 (define-key map
"-" 'ibuffer-add-to-tmp-hide
)
425 (define-key map
"+" 'ibuffer-add-to-tmp-show
)
426 (define-key map
"b" 'ibuffer-bury-buffer
)
427 (define-key map
(kbd ",") 'ibuffer-toggle-sorting-mode
)
428 (define-key map
(kbd "s i") 'ibuffer-invert-sorting
)
429 (define-key map
(kbd "s a") 'ibuffer-do-sort-by-alphabetic
)
430 (define-key map
(kbd "s v") 'ibuffer-do-sort-by-recency
)
431 (define-key map
(kbd "s s") 'ibuffer-do-sort-by-size
)
432 (define-key map
(kbd "s m") 'ibuffer-do-sort-by-major-mode
)
434 (define-key map
(kbd "/ m") 'ibuffer-filter-by-mode
)
435 (define-key map
(kbd "/ M") 'ibuffer-filter-by-used-mode
)
436 (define-key map
(kbd "/ n") 'ibuffer-filter-by-name
)
437 (define-key map
(kbd "/ c") 'ibuffer-filter-by-content
)
438 (define-key map
(kbd "/ e") 'ibuffer-filter-by-predicate
)
439 (define-key map
(kbd "/ f") 'ibuffer-filter-by-filename
)
440 (define-key map
(kbd "/ >") 'ibuffer-filter-by-size-gt
)
441 (define-key map
(kbd "/ <") 'ibuffer-filter-by-size-lt
)
442 (define-key map
(kbd "/ r") 'ibuffer-switch-to-saved-filters
)
443 (define-key map
(kbd "/ a") 'ibuffer-add-saved-filters
)
444 (define-key map
(kbd "/ x") 'ibuffer-delete-saved-filters
)
445 (define-key map
(kbd "/ d") 'ibuffer-decompose-filter
)
446 (define-key map
(kbd "/ s") 'ibuffer-save-filters
)
447 (define-key map
(kbd "/ p") 'ibuffer-pop-filter
)
448 (define-key map
(kbd "/ !") 'ibuffer-negate-filter
)
449 (define-key map
(kbd "/ t") 'ibuffer-exchange-filters
)
450 (define-key map
(kbd "/ TAB") 'ibuffer-exchange-filters
)
451 (define-key map
(kbd "/ o") 'ibuffer-or-filter
)
452 (define-key map
(kbd "/ g") 'ibuffer-filters-to-filter-group
)
453 (define-key map
(kbd "/ P") 'ibuffer-pop-filter-group
)
454 (define-key map
(kbd "/ D") 'ibuffer-decompose-filter-group
)
455 (define-key map
(kbd "/ /") 'ibuffer-filter-disable
)
457 (define-key map
(kbd "M-n") 'ibuffer-forward-filter-group
)
458 (define-key map
(kbd "<right>") 'ibuffer-forward-filter-group
)
459 (define-key map
(kbd "M-p") 'ibuffer-backward-filter-group
)
460 (define-key map
(kbd "<left>") 'ibuffer-backward-filter-group
)
461 (define-key map
(kbd "M-j") 'ibuffer-jump-to-filter-group
)
462 (define-key map
(kbd "C-k") 'ibuffer-kill-line
)
463 (define-key map
(kbd "C-y") 'ibuffer-yank
)
464 (define-key map
(kbd "/ S") 'ibuffer-save-filter-groups
)
465 (define-key map
(kbd "/ R") 'ibuffer-switch-to-saved-filter-groups
)
466 (define-key map
(kbd "/ X") 'ibuffer-delete-saved-filter-groups
)
467 (define-key map
(kbd "/ \\") 'ibuffer-clear-filter-groups
)
469 (define-key map
(kbd "q") 'ibuffer-quit
)
470 (define-key map
(kbd "h") 'describe-mode
)
471 (define-key map
(kbd "?") 'describe-mode
)
473 (define-key map
(kbd "% n") 'ibuffer-mark-by-name-regexp
)
474 (define-key map
(kbd "% m") 'ibuffer-mark-by-mode-regexp
)
475 (define-key map
(kbd "% f") 'ibuffer-mark-by-file-name-regexp
)
477 (define-key map
(kbd "C-t") 'ibuffer-visit-tags-table
)
479 (define-key map
(kbd "|") 'ibuffer-do-shell-command-pipe
)
480 (define-key map
(kbd "!") 'ibuffer-do-shell-command-file
)
481 (define-key map
(kbd "~") 'ibuffer-do-toggle-modified
)
483 (define-key map
(kbd "A") 'ibuffer-do-view
)
484 (define-key map
(kbd "D") 'ibuffer-do-delete
)
485 (define-key map
(kbd "E") 'ibuffer-do-eval
)
486 (define-key map
(kbd "F") 'ibuffer-do-shell-command-file
)
487 (define-key map
(kbd "I") 'ibuffer-do-query-replace-regexp
)
488 (define-key map
(kbd "H") 'ibuffer-do-view-other-frame
)
489 (define-key map
(kbd "N") 'ibuffer-do-shell-command-pipe-replace
)
490 (define-key map
(kbd "M") 'ibuffer-do-toggle-modified
)
491 (define-key map
(kbd "O") 'ibuffer-do-occur
)
492 (define-key map
(kbd "P") 'ibuffer-do-print
)
493 (define-key map
(kbd "Q") 'ibuffer-do-query-replace
)
494 (define-key map
(kbd "R") 'ibuffer-do-rename-uniquely
)
495 (define-key map
(kbd "S") 'ibuffer-do-save
)
496 (define-key map
(kbd "T") 'ibuffer-do-toggle-read-only
)
497 (define-key map
(kbd "U") 'ibuffer-do-replace-regexp
)
498 (define-key map
(kbd "V") 'ibuffer-do-revert
)
499 (define-key map
(kbd "W") 'ibuffer-do-view-and-eval
)
500 (define-key map
(kbd "X") 'ibuffer-do-shell-command-pipe
)
502 (define-key map
(kbd "k") 'ibuffer-do-kill-lines
)
503 (define-key map
(kbd "w") 'ibuffer-copy-filename-as-kill
)
505 (define-key map
(kbd "RET") 'ibuffer-visit-buffer
)
506 (define-key map
(kbd "e") 'ibuffer-visit-buffer
)
507 (define-key map
(kbd "f") 'ibuffer-visit-buffer
)
508 (define-key map
(kbd "C-x C-f") 'ibuffer-find-file
)
509 (define-key map
(kbd "o") 'ibuffer-visit-buffer-other-window
)
510 (define-key map
(kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect
)
511 (define-key map
(kbd "M-o") 'ibuffer-visit-buffer-1-window
)
512 (define-key map
(kbd "v") 'ibuffer-do-view
)
513 (define-key map
(kbd "C-x v") 'ibuffer-do-view-horizontally
)
514 (define-key map
(kbd "C-c C-a") 'ibuffer-auto-mode
)
515 (define-key map
(kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window
)
516 (define-key map
(kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame
)
518 (define-key map
[menu-bar view
]
519 (cons "View" (make-sparse-keymap "View")))
521 (define-key-after map
[menu-bar view visit-buffer
]
522 '(menu-item "View this buffer" ibuffer-visit-buffer
))
523 (define-key-after map
[menu-bar view visit-buffer-other-window
]
524 '(menu-item "View (other window)" ibuffer-visit-buffer-other-window
))
525 (define-key-after map
[menu-bar view visit-buffer-other-frame
]
526 '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame
))
527 (define-key-after map
[menu-bar view ibuffer-update
]
528 '(menu-item "Update" ibuffer-update
529 :help
"Regenerate the list of buffers"))
530 (define-key-after map
[menu-bar view switch-format
]
531 '(menu-item "Switch display format" ibuffer-switch-format
532 :help
"Toggle between available values of `ibuffer-formats'"))
534 (define-key-after map
[menu-bar view dashes
]
537 (define-key-after map
[menu-bar view sort
]
538 (cons "Sort" (make-sparse-keymap "Sort")))
540 (define-key-after map
[menu-bar view sort do-sort-by-major-mode
]
541 '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode
))
542 (define-key-after map
[menu-bar view sort do-sort-by-size
]
543 '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size
))
544 (define-key-after map
[menu-bar view sort do-sort-by-alphabetic
]
545 '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic
546 :help
"Sort by the alphabetic order of buffer name"))
547 (define-key-after map
[menu-bar view sort do-sort-by-recency
]
548 '(menu-item "Sort by view time" ibuffer-do-sort-by-recency
549 :help
"Sort by the last time the buffer was displayed"))
550 (define-key-after map
[menu-bar view sort dashes
]
552 (define-key-after map
[menu-bar view sort invert-sorting
]
553 '(menu-item "Reverse sorting order" ibuffer-invert-sorting
))
554 (define-key-after map
[menu-bar view sort toggle-sorting-mode
]
555 '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode
556 :help
"Switch between the various sorting criteria"))
558 (define-key-after map
[menu-bar view filter
]
559 (cons "Filter" (make-sparse-keymap "Filter")))
561 (define-key-after map
[menu-bar view filter filter-disable
]
562 '(menu-item "Disable all filtering" ibuffer-filter-disable
563 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
564 (define-key-after map
[menu-bar view filter filter-by-mode
]
565 '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode
))
566 (define-key-after map
[menu-bar view filter filter-by-mode
]
567 '(menu-item "Add filter by major mode in use..." ibuffer-filter-by-used-mode
))
568 (define-key-after map
[menu-bar view filter filter-by-name
]
569 '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name
))
570 (define-key-after map
[menu-bar view filter filter-by-filename
]
571 '(menu-item "Add filter by filename..." ibuffer-filter-by-filename
))
572 (define-key-after map
[menu-bar view filter filter-by-size-lt
]
573 '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt
))
574 (define-key-after map
[menu-bar view filter filter-by-size-gt
]
575 '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt
))
576 (define-key-after map
[menu-bar view filter filter-by-content
]
577 '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content
))
578 (define-key-after map
[menu-bar view filter filter-by-predicate
]
579 '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate
))
580 (define-key-after map
[menu-bar view filter pop-filter
]
581 '(menu-item "Remove top filter" ibuffer-pop-filter
582 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
583 (define-key-after map
[menu-bar view filter or-filter
]
584 '(menu-item "OR top two filters" ibuffer-or-filter
585 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
586 (cdr ibuffer-filtering-qualifiers
))
587 :help
"Create a new filter which is the logical OR of the top two filters"))
588 (define-key-after map
[menu-bar view filter negate-filter
]
589 '(menu-item "Negate top filter" ibuffer-negate-filter
590 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
591 (define-key-after map
[menu-bar view filter decompose-filter
]
592 '(menu-item "Decompose top filter" ibuffer-decompose-filter
593 :enable
(and (featurep 'ibuf-ext
) (memq (car ibuffer-filtering-qualifiers
) '(or saved not
)))
594 :help
"Break down a complex filter like OR or NOT"))
595 (define-key-after map
[menu-bar view filter exchange-filters
]
596 '(menu-item "Swap top two filters" ibuffer-exchange-filters
597 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
598 (cdr ibuffer-filtering-qualifiers
))))
599 (define-key-after map
[menu-bar view filter save-filters
]
600 '(menu-item "Save current filters permanently..." ibuffer-save-filters
601 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
602 :help
"Use a mnemnonic name to store current filter stack"))
603 (define-key-after map
[menu-bar view filter switch-to-saved-filters
]
604 '(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters
605 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)
606 :help
"Replace current filters with a saved stack"))
607 (define-key-after map
[menu-bar view filter add-saved-filters
]
608 '(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters
609 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
610 :help
"Include already saved stack with current filters"))
611 (define-key-after map
[menu-bar view filter delete-saved-filters
]
612 '(menu-item "Delete permanently saved filters..."
613 ibuffer-delete-saved-filters
614 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)))
618 (define-key-after groups-map
[filters-to-filter-group
]
619 '(menu-item "Create filter group from current filters..."
620 ibuffer-filters-to-filter-group
621 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
622 (define-key-after groups-map
[forward-filter-group
]
623 '(menu-item "Move point to the next filter group"
624 ibuffer-forward-filter-group
))
625 (define-key-after groups-map
[backward-filter-group
]
626 '(menu-item "Move point to the previous filter group"
627 ibuffer-backward-filter-group
))
628 (define-key-after groups-map
[jump-to-filter-group
]
629 '(menu-item "Move point to a specific filter group..."
630 ibuffer-jump-to-filter-group
))
631 (define-key-after groups-map
[kill-filter-group
]
632 '(menu-item "Kill filter group named..."
633 ibuffer-kill-filter-group
634 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
635 (define-key-after groups-map
[yank-filter-group
]
636 '(menu-item "Yank last killed filter group before..."
637 ibuffer-yank-filter-group
638 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-group-kill-ring
)))
639 (define-key-after groups-map
[pop-filter-group
]
640 '(menu-item "Remove top filter group"
641 ibuffer-pop-filter-group
642 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
643 (define-key-after groups-map
[clear-filter-groups
]
644 '(menu-item "Remove all filter groups"
645 ibuffer-clear-filter-groups
646 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
647 (define-key-after groups-map
[pop-filter-group
]
648 '(menu-item "Decompose filter group..."
649 ibuffer-pop-filter-group
650 :help
"\"Unmake\" a filter group"
651 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
652 (define-key-after groups-map
[save-filter-groups
]
653 '(menu-item "Save current filter groups permanently..."
654 ibuffer-save-filter-groups
655 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)
656 :help
"Use a mnemnonic name to store current filter groups"))
657 (define-key-after groups-map
[switch-to-saved-filter-groups
]
658 '(menu-item "Restore permanently saved filters..."
659 ibuffer-switch-to-saved-filter-groups
660 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)
661 :help
"Replace current filters with a saved stack"))
662 (define-key-after groups-map
[delete-saved-filter-groups
]
663 '(menu-item "Delete permanently saved filter groups..."
664 ibuffer-delete-saved-filter-groups
665 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)))
666 (define-key-after groups-map
[set-filter-groups-by-mode
]
667 '(menu-item "Set current filter groups to filter by mode"
668 ibuffer-set-filter-groups-by-mode
))
670 (define-key-after map
[menu-bar view filter-groups
]
671 (cons "Filter Groups" groups-map
))
673 (define-key-after map
[menu-bar view dashes2
]
675 (define-key-after map
[menu-bar view diff-with-file
]
676 '(menu-item "Diff with file" ibuffer-diff-with-file
677 :help
"View the differences between this buffer and its file"))
678 (define-key-after map
[menu-bar view auto-mode
]
679 '(menu-item "Toggle Auto Mode" ibuffer-auto-mode
680 :help
"Attempt to automatically update the Ibuffer buffer"))
681 (define-key-after map
[menu-bar view customize
]
682 '(menu-item "Customize Ibuffer" ibuffer-customize
683 :help
"Use Custom to customize Ibuffer"))
685 (define-key-after map
[menu-bar mark
]
686 (cons "Mark" (make-sparse-keymap "Mark")))
688 (define-key-after map
[menu-bar mark toggle-marks
]
689 '(menu-item "Toggle marks" ibuffer-toggle-marks
690 :help
"Unmark marked buffers, and mark unmarked buffers"))
691 (define-key-after map
[menu-bar mark mark-forward
]
692 '(menu-item "Mark" ibuffer-mark-forward
693 :help
"Mark the buffer at point"))
694 (define-key-after map
[menu-bar mark unmark-forward
]
695 '(menu-item "Unmark" ibuffer-unmark-forward
696 :help
"Unmark the buffer at point"))
697 (define-key-after map
[menu-bar mark mark-by-mode
]
698 '(menu-item "Mark by mode..." ibuffer-mark-by-mode
699 :help
"Mark all buffers in a particular major mode"))
700 (define-key-after map
[menu-bar mark mark-modified-buffers
]
701 '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers
702 :help
"Mark all buffers which have been modified"))
703 (define-key-after map
[menu-bar mark mark-unsaved-buffers
]
704 '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers
705 :help
"Mark all buffers which have a file and are modified"))
706 (define-key-after map
[menu-bar mark mark-read-only-buffers
]
707 '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers
708 :help
"Mark all buffers which are read-only"))
709 (define-key-after map
[menu-bar mark mark-special-buffers
]
710 '(menu-item "Mark special buffers" ibuffer-mark-special-buffers
711 :help
"Mark all buffers whose name begins with a *"))
712 (define-key-after map
[menu-bar mark mark-dired-buffers
]
713 '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers
714 :help
"Mark buffers in dired-mode"))
715 (define-key-after map
[menu-bar mark mark-dissociated-buffers
]
716 '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers
717 :help
"Mark buffers with a non-existent associated file"))
718 (define-key-after map
[menu-bar mark mark-help-buffers
]
719 '(menu-item "Mark help buffers" ibuffer-mark-help-buffers
720 :help
"Mark buffers in help-mode"))
721 (define-key-after map
[menu-bar mark mark-old-buffers
]
722 '(menu-item "Mark old buffers" ibuffer-mark-old-buffers
723 :help
"Mark buffers which have not been viewed recently"))
724 (define-key-after map
[menu-bar mark unmark-all
]
725 '(menu-item "Unmark All" ibuffer-unmark-all
))
727 (define-key-after map
[menu-bar mark dashes
]
730 (define-key-after map
[menu-bar mark mark-by-name-regexp
]
731 '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
732 :help
"Mark buffers whose name matches a regexp"))
733 (define-key-after map
[menu-bar mark mark-by-mode-regexp
]
734 '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp
735 :help
"Mark buffers whose major mode name matches a regexp"))
736 (define-key-after map
[menu-bar mark mark-by-file-name-regexp
]
737 '(menu-item "Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp
738 :help
"Mark buffers whose file name matches a regexp"))
740 ;; Operate map is added later
742 (define-key-after operate-map
[do-view
]
743 '(menu-item "View" ibuffer-do-view
))
744 (define-key-after operate-map
[do-view-other-frame
]
745 '(menu-item "View (separate frame)" ibuffer-do-view-other-frame
))
746 (define-key-after operate-map
[do-save
]
747 '(menu-item "Save" ibuffer-do-save
))
748 (define-key-after operate-map
[do-replace-regexp
]
749 '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp
750 :help
"Replace text inside marked buffers"))
751 (define-key-after operate-map
[do-query-replace
]
752 '(menu-item "Query Replace..." ibuffer-do-query-replace
753 :help
"Replace text in marked buffers, asking each time"))
754 (define-key-after operate-map
[do-query-replace-regexp
]
755 '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp
756 :help
"Replace text in marked buffers by regexp, asking each time"))
757 (define-key-after operate-map
[do-print
]
758 '(menu-item "Print" ibuffer-do-print
))
759 (define-key-after operate-map
[do-toggle-modified
]
760 '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified
))
761 (define-key-after operate-map
[do-revert
]
762 '(menu-item "Revert" ibuffer-do-revert
763 :help
"Revert marked buffers to their associated file"))
764 (define-key-after operate-map
[do-rename-uniquely
]
765 '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely
766 :help
"Rename marked buffers to a new, unique name"))
767 (define-key-after operate-map
[do-delete
]
768 '(menu-item "Kill" ibuffer-do-delete
))
769 (define-key-after operate-map
[do-occur
]
770 '(menu-item "List lines matching..." ibuffer-do-occur
771 :help
"View all lines in marked buffers matching a regexp"))
772 (define-key-after operate-map
[do-shell-command-pipe
]
773 '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe
774 :help
"For each marked buffer, send its contents to a shell command"))
775 (define-key-after operate-map
[do-shell-command-pipe-replace
]
776 '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace
777 :help
"For each marked buffer, replace its contents with output of shell command"))
778 (define-key-after operate-map
[do-shell-command-file
]
779 '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file
780 :help
"For each marked buffer, run a shell command with its file as argument"))
781 (define-key-after operate-map
[do-eval
]
782 '(menu-item "Eval..." ibuffer-do-eval
783 :help
"Evaluate a Lisp form in each marked buffer"))
784 (define-key-after operate-map
[do-view-and-eval
]
785 '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval
786 :help
"Evaluate a Lisp form in each marked buffer while viewing it"))
788 (setq ibuffer-mode-map map
789 ibuffer-mode-operate-map operate-map
790 ibuffer-mode-groups-popup
(copy-keymap groups-map
))))
792 (define-key ibuffer-mode-groups-popup
[kill-filter-group
]
793 '(menu-item "Kill filter group"
795 :enable
(and (featurep 'ibuf-ext
)
796 ibuffer-filter-groups
)))
797 (define-key ibuffer-mode-groups-popup
[yank-filter-group
]
798 '(menu-item "Yank last killed filter group"
800 :enable
(and (featurep 'ibuf-ext
)
801 ibuffer-filter-group-kill-ring
)))
803 (defvar ibuffer-name-map
804 (let ((map (make-sparse-keymap)))
805 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
806 (define-key map
[(mouse-2)] 'ibuffer-mouse-visit-buffer
)
807 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
810 (defvar ibuffer-mode-name-map
811 (let ((map (make-sparse-keymap)))
812 (define-key map
[(mouse-2)] 'ibuffer-mouse-filter-by-mode
)
813 (define-key map
(kbd "RET") 'ibuffer-interactive-filter-by-mode
)
816 (defvar ibuffer-mode-filter-group-map
817 (let ((map (make-sparse-keymap)))
818 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
819 (define-key map
[(mouse-2)] 'ibuffer-mouse-toggle-filter-group
)
820 (define-key map
(kbd "RET") 'ibuffer-toggle-filter-group
)
821 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
824 (defvar ibuffer-restore-window-config-on-quit nil
825 "If non-nil, restore previous window configuration upon exiting `ibuffer'.")
827 (defvar ibuffer-prev-window-config nil
828 "Window configuration before starting Ibuffer.")
830 (defvar ibuffer-did-modification nil
)
832 (defvar ibuffer-compiled-formats nil
)
833 (defvar ibuffer-cached-formats nil
)
834 (defvar ibuffer-cached-eliding-string nil
)
835 (defvar ibuffer-cached-elide-long-columns
0)
837 (defvar ibuffer-sorting-functions-alist nil
838 "An alist of functions which describe how to sort buffers.
840 Note: You most likely do not want to modify this variable directly;
841 use `define-ibuffer-sorter' instead.
843 The alist elements are constructed like (NAME DESCRIPTION FUNCTION)
844 Where NAME is a symbol describing the sorting method, DESCRIPTION is a
845 short string which will be displayed in the minibuffer and menu, and
846 FUNCTION is a function of two arguments, which will be the buffers to
849 ;;; Utility functions
850 (defun ibuffer-columnize-and-insert-list (list &optional pad-width
)
851 "Insert LIST into the current buffer in as many columns as possible.
852 The maximum number of columns is determined by the current window
853 width and the longest string in LIST."
856 (let ((width (window-width))
857 (max (+ (apply #'max
(mapcar #'length list
))
859 (let ((columns (/ width max
)))
860 (when (zerop columns
)
863 (dotimes (i (1- columns
))
864 (insert (concat (car list
) (make-string (- max
(length (car list
)))
866 (setq list
(cdr list
)))
867 (when (not (null list
))
871 (defsubst ibuffer-current-mark
()
872 (cadr (get-text-property (line-beginning-position)
873 'ibuffer-properties
)))
875 (defun ibuffer-mouse-toggle-mark (event)
876 "Toggle the marked status of the buffer chosen with the mouse."
879 (let ((pt (save-excursion
880 (mouse-set-point event
)
882 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
883 (ibuffer-toggle-marks it
)
885 (let ((mark (ibuffer-current-mark)))
886 (setq buffer-read-only nil
)
887 (if (eq mark ibuffer-marked-char
)
888 (ibuffer-set-mark ?\s
)
889 (ibuffer-set-mark ibuffer-marked-char
)))))
890 (setq buffer-read-only t
)))
892 (defun ibuffer-find-file (file &optional wildcards
)
893 "Like `find-file', but default to the directory of the buffer at point."
895 (let ((default-directory (let ((buf (ibuffer-current-buffer)))
896 (if (buffer-live-p buf
)
897 (with-current-buffer buf
899 default-directory
))))
900 (list (read-file-name "Find file: " default-directory
)
902 (find-file file wildcards
))
904 (defun ibuffer-mouse-visit-buffer (event)
905 "Visit the buffer chosen with the mouse."
909 (mouse-set-point event
)
910 (ibuffer-current-buffer t
))))
912 (defun ibuffer-mouse-popup-menu (event)
913 "Display a menu of operations."
915 (let ((eventpt (posn-point (event-end event
)))
918 (if (get-text-property eventpt
'ibuffer-filter-group-name
)
921 (popup-menu ibuffer-mode-groups-popup
))
922 (let ((inhibit-read-only t
))
924 ;; hm. we could probably do this in a better fashion
925 (ibuffer-unmark-all ?
\r)
928 (ibuffer-set-mark ibuffer-marked-char
))
930 (popup-menu ibuffer-mode-operate-map
)))))
931 (setq buffer-read-only t
)
932 (if (= eventpt
(point))
933 (goto-char origpt
)))))
935 (defun ibuffer-skip-properties (props direction
)
936 (while (and (not (eobp))
938 (dolist (prop props hit
)
939 (when (get-text-property (point) prop
)
941 (forward-line direction
)
942 (beginning-of-line)))
944 (defun ibuffer-customize ()
945 "Begin customizing Ibuffer interactively."
947 (customize-group 'ibuffer
))
949 (defun ibuffer-backward-line (&optional arg skip-group-names
)
950 "Move backwards ARG lines, wrapping around the list if necessary."
952 (or arg
(setq arg
1))
956 (when (and ibuffer-movement-cycle
957 (or (get-text-property (point) 'ibuffer-title
)
958 (and skip-group-names
959 (get-text-property (point)
960 'ibuffer-filter-group-name
))))
961 (goto-char (point-max))
963 (ibuffer-skip-properties (append '(ibuffer-summary)
964 (when skip-group-names
965 '(ibuffer-filter-group-name)))
967 ;; Handle the special case of no buffers.
968 (when (get-text-property (point) 'ibuffer-title
)
973 (defun ibuffer-forward-line (&optional arg skip-group-names
)
974 "Move forward ARG lines, wrapping around the list if necessary."
976 (or arg
(setq arg
1))
978 (when (and ibuffer-movement-cycle
980 (get-text-property (point) 'ibuffer-summary
)))
981 (goto-char (point-min)))
982 (when (or (get-text-property (point) 'ibuffer-title
)
983 (and skip-group-names
984 (get-text-property (point) 'ibuffer-filter-group-name
)))
987 (ibuffer-skip-properties (append '(ibuffer-title)
988 (when skip-group-names
989 '(ibuffer-filter-group-name)))
992 (ibuffer-backward-line (- arg
))
995 (when (and ibuffer-movement-cycle
997 (get-text-property (point) 'ibuffer-summary
)))
998 (goto-char (point-min)))
1000 (ibuffer-skip-properties (append '(ibuffer-title)
1001 (when skip-group-names
1002 '(ibuffer-filter-group-name)))
1005 (defun ibuffer-visit-buffer (&optional single
)
1006 "Visit the buffer on this line.
1007 If optional argument SINGLE is non-nil, then also ensure there is only
1010 (let ((buf (ibuffer-current-buffer t
)))
1011 (bury-buffer (current-buffer))
1012 (switch-to-buffer buf
)
1014 (delete-other-windows))))
1016 (defun ibuffer-visit-buffer-other-window (&optional noselect
)
1017 "Visit the buffer on this line in another window."
1019 (let ((buf (ibuffer-current-buffer t
)))
1020 (bury-buffer (current-buffer))
1022 (let ((curwin (selected-window)))
1024 (select-window curwin
))
1025 (switch-to-buffer-other-window buf
))))
1027 (defun ibuffer-visit-buffer-other-window-noselect ()
1028 "Visit the buffer on this line in another window, but don't select it."
1030 (ibuffer-visit-buffer-other-window t
))
1032 (defun ibuffer-visit-buffer-other-frame ()
1033 "Visit the buffer on this line in another frame."
1035 (let ((buf (ibuffer-current-buffer t
)))
1036 (bury-buffer (current-buffer))
1037 (switch-to-buffer-other-frame buf
)))
1039 (defun ibuffer-visit-buffer-1-window ()
1040 "Visit the buffer on this line, and delete other windows."
1042 (ibuffer-visit-buffer t
))
1044 (defun ibuffer-bury-buffer ()
1045 "Bury the buffer on this line."
1047 (let ((buf (ibuffer-current-buffer t
))
1048 (line (+ 1 (count-lines 1 (point)))))
1050 (ibuffer-update nil t
)
1053 (defun ibuffer-visit-tags-table ()
1054 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
1056 (let ((file (buffer-file-name (ibuffer-current-buffer t
))))
1058 (visit-tags-table file
)
1059 (error "Specified buffer has no file"))))
1061 (defun ibuffer-do-view (&optional other-frame
)
1062 "View marked buffers, or the buffer on the current line.
1063 If optional argument OTHER-FRAME is non-nil, then display each
1064 marked buffer in a new frame. Otherwise, display each buffer as
1065 a new window in the current frame, splitting vertically."
1067 (ibuffer-do-view-1 (if other-frame
'other-frame
'vertically
)))
1069 (defun ibuffer-do-view-horizontally (&optional other-frame
)
1070 "As `ibuffer-do-view', but split windows horizontally."
1072 (ibuffer-do-view-1 (if other-frame
'other-frame
'horizontally
)))
1074 (defun ibuffer-do-view-1 (type)
1075 (let ((marked-bufs (ibuffer-get-marked-buffers)))
1076 (when (null marked-bufs
)
1077 (setq marked-bufs
(list (ibuffer-current-buffer t
))))
1078 (unless (and (eq type
'other-frame
)
1079 (not ibuffer-expert
)
1080 (> (length marked-bufs
) 3)
1081 (not (y-or-n-p (format "Really create a new frame for %s buffers? "
1082 (length marked-bufs
)))))
1083 (set-buffer-modified-p nil
)
1084 (delete-other-windows)
1085 (switch-to-buffer (pop marked-bufs
))
1086 (let ((height (/ (1- (if (eq type
'horizontally
) (frame-width)
1088 (1+ (length marked-bufs
)))))
1089 (mapcar (if (eq type
'other-frame
)
1091 (let ((curframe (selected-frame)))
1092 (select-frame (make-frame))
1093 (switch-to-buffer buf
)
1094 (select-frame curframe
)))
1096 (split-window nil height
(eq type
'horizontally
))
1098 (switch-to-buffer buf
)))
1101 (defun ibuffer-do-view-other-frame ()
1102 "View each of the marked buffers in a separate frame."
1104 (ibuffer-do-view t
))
1106 (defsubst ibuffer-map-marked-lines
(func)
1107 (prog1 (ibuffer-map-on-mark ibuffer-marked-char func
)
1108 (ibuffer-redisplay t
)))
1110 (defun ibuffer-shrink-to-fit (&optional owin
)
1111 (fit-window-to-buffer nil
(when owin
(/ (frame-height)
1112 (length (window-list (selected-frame)))))))
1114 (defun ibuffer-confirm-operation-on (operation names
)
1115 "Display a buffer asking whether to perform OPERATION on NAMES."
1117 (if (= (length names
) 1)
1118 (y-or-n-p (format "Really %s buffer %s? " operation
(car names
)))
1119 (let ((buf (get-buffer-create "*Ibuffer confirmation*")))
1120 (with-current-buffer buf
1121 (setq buffer-read-only nil
)
1123 (ibuffer-columnize-and-insert-list names
)
1124 (goto-char (point-min))
1125 (setq buffer-read-only t
))
1126 (let ((lastwin (car (last (window-list nil
'nomini
)))))
1127 ;; Now attempt to display the buffer...
1128 (save-window-excursion
1129 (select-window lastwin
)
1130 ;; The window might be too small to split; in that case,
1131 ;; try a few times to increase its size before giving up.
1141 (if (or (> (incf attempts
) 4)
1142 (and (stringp (cadr err
))
1143 ;; This definitely falls in the
1144 ;; ghetto hack category...
1145 (not (string-match "too small" (cadr err
)))))
1146 (apply #'signal err
)
1147 (enlarge-window 3))))))
1148 (select-window (next-window))
1149 (switch-to-buffer buf
)
1152 (fit-window-to-buffer)
1153 (y-or-n-p (format "Really %s %d buffers? "
1154 operation
(length names
))))
1155 (kill-buffer buf
))))))))
1157 (defsubst ibuffer-map-lines-nomodify
(function)
1158 "As `ibuffer-map-lines', but don't set the modification flag."
1159 (ibuffer-map-lines function t
))
1161 (defun ibuffer-buffer-names-with-mark (mark)
1162 (let ((ibuffer-buffer-names-with-mark-result nil
))
1163 (ibuffer-map-lines-nomodify
1165 (when (char-equal mark mk
)
1166 (push (buffer-name buf
)
1167 ibuffer-buffer-names-with-mark-result
))))
1168 ibuffer-buffer-names-with-mark-result
))
1170 (defsubst ibuffer-marked-buffer-names
()
1171 (ibuffer-buffer-names-with-mark ibuffer-marked-char
))
1173 (defsubst ibuffer-deletion-marked-buffer-names
()
1174 (ibuffer-buffer-names-with-mark ibuffer-deletion-char
))
1176 (defun ibuffer-count-marked-lines (&optional all
)
1178 (ibuffer-map-lines-nomodify
1179 #'(lambda (buf mark
)
1180 (not (char-equal mark ?\s
))))
1181 (ibuffer-map-lines-nomodify
1182 #'(lambda (buf mark
)
1183 (char-equal mark ibuffer-marked-char
)))))
1185 (defsubst ibuffer-count-deletion-lines
()
1186 (ibuffer-map-lines-nomodify
1187 #'(lambda (buf mark
)
1188 (char-equal mark ibuffer-deletion-char
))))
1190 (defsubst ibuffer-map-deletion-lines
(func)
1191 (ibuffer-map-on-mark ibuffer-deletion-char func
))
1193 (define-ibuffer-op ibuffer-do-save
()
1194 "Save marked buffers as with `save-buffer'."
1198 (when (buffer-modified-p buf
)
1199 (if (not (with-current-buffer buf
1201 ;; handle the case where we're prompted
1203 (save-window-excursion
1204 (switch-to-buffer buf
)
1206 (with-current-buffer buf
1210 (define-ibuffer-op ibuffer-do-toggle-modified
()
1211 "Toggle modification flag of marked buffers."
1212 (:opstring
"(un)marked as modified"
1214 (set-buffer-modified-p (not (buffer-modified-p))))
1216 (define-ibuffer-op ibuffer-do-toggle-read-only
()
1217 "Toggle read only status in marked buffers."
1218 (:opstring
"toggled read only status in"
1222 (define-ibuffer-op ibuffer-do-delete
()
1223 "Kill marked buffers as with `kill-this-buffer'."
1225 :active-opstring
"kill"
1229 (if (kill-buffer buf
)
1233 (define-ibuffer-op ibuffer-do-kill-on-deletion-marks
()
1234 "Kill buffers marked for deletion as with `kill-this-buffer'."
1236 :active-opstring
"kill"
1241 (if (kill-buffer buf
)
1245 (defun ibuffer-unmark-all (mark)
1246 "Unmark all buffers with mark MARK."
1247 (interactive "cRemove marks (RET means all):")
1248 (if (= (ibuffer-count-marked-lines t
) 0)
1249 (message "No buffers marked; use 'm' to mark a buffer")
1251 ((char-equal mark ibuffer-marked-char
)
1252 (ibuffer-map-marked-lines
1253 #'(lambda (buf mark
)
1254 (ibuffer-set-mark-1 ?\s
)
1256 ((char-equal mark ibuffer-deletion-char
)
1257 (ibuffer-map-deletion-lines
1258 #'(lambda (buf mark
)
1259 (ibuffer-set-mark-1 ?\s
)
1263 #'(lambda (buf mark
)
1264 (when (not (char-equal mark ?\s
))
1265 (ibuffer-set-mark-1 ?\s
))
1267 (ibuffer-redisplay t
))
1269 (defun ibuffer-toggle-marks (&optional group
)
1270 "Toggle which buffers are marked.
1271 In other words, unmarked buffers become marked, and marked buffers
1273 If point is on a group name, then this function operates on that
1276 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1280 #'(lambda (buf mark
)
1281 (cond ((eq mark ibuffer-marked-char
)
1282 (ibuffer-set-mark-1 ?\s
)
1285 (ibuffer-set-mark-1 ibuffer-marked-char
)
1290 (message "%s buffers marked" count
))
1291 (ibuffer-redisplay t
))
1293 (defun ibuffer-mark-forward (arg)
1294 "Mark the buffer on this line, and move forward ARG lines.
1295 If point is on a group name, this function operates on that group."
1297 (ibuffer-mark-interactive arg ibuffer-marked-char
1))
1299 (defun ibuffer-unmark-forward (arg)
1300 "Unmark the buffer on this line, and move forward ARG lines.
1301 If point is on a group name, this function operates on that group."
1303 (ibuffer-mark-interactive arg ?\s
1))
1305 (defun ibuffer-unmark-backward (arg)
1306 "Unmark the buffer on this line, and move backward ARG lines.
1307 If point is on a group name, this function operates on that group."
1309 (ibuffer-mark-interactive arg ?\s -
1))
1311 (defun ibuffer-mark-interactive (arg mark movement
)
1312 (assert (eq major-mode
'ibuffer-mode
))
1313 (or arg
(setq arg
1))
1314 (ibuffer-forward-line 0)
1315 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1318 (ibuffer-mark-on-buffer #'identity mark it
))
1319 (ibuffer-forward-line 0 t
)
1320 (let ((inhibit-read-only t
))
1322 (ibuffer-set-mark mark
)
1323 (ibuffer-forward-line movement t
)
1324 (setq arg
(1- arg
))))))
1326 (defun ibuffer-set-mark (mark)
1327 (assert (eq major-mode
'ibuffer-mode
))
1328 (let ((inhibit-read-only t
))
1329 (ibuffer-set-mark-1 mark
)
1330 (setq ibuffer-did-modification t
)
1331 (ibuffer-redisplay-current)
1332 (beginning-of-line)))
1334 (defun ibuffer-set-mark-1 (mark)
1335 (let ((beg (line-beginning-position))
1336 (end (line-end-position)))
1337 (put-text-property beg end
'ibuffer-properties
1338 (list (ibuffer-current-buffer)
1341 (defun ibuffer-mark-for-delete (arg)
1342 "Mark the buffers on ARG lines forward for deletion.
1343 If point is on a group name, this function operates on that group."
1345 (ibuffer-mark-interactive arg ibuffer-deletion-char
1))
1347 (defun ibuffer-mark-for-delete-backwards (arg)
1348 "Mark the buffers on ARG lines backward for deletion.
1349 If point is on a group name, this function operates on that group."
1351 (ibuffer-mark-interactive arg ibuffer-deletion-char -
1))
1353 (defun ibuffer-current-buffer (&optional must-be-live
)
1354 (let ((buf (car (get-text-property (line-beginning-position)
1355 'ibuffer-properties
))))
1358 (unless (buffer-live-p buf
)
1359 (error (substitute-command-keys "Buffer %s has been killed; use `\\[ibuffer-update]' to update") buf
))
1360 (error "No buffer on this line")))
1363 (defun ibuffer-active-formats-name ()
1364 (if (boundp 'ibuffer-filter-format-alist
)
1366 (dolist (filter ibuffer-filtering-qualifiers ret
)
1367 (let ((val (assq (car filter
) ibuffer-filter-format-alist
)))
1369 (setq ret
(car filter
)))))
1375 (defun ibuffer-current-formats (uncompiledp)
1376 (let* ((name (ibuffer-active-formats-name)))
1377 (ibuffer-check-formats)
1378 (if (eq name
:ibuffer-formats
)
1381 ibuffer-compiled-formats
)
1384 ibuffer-filter-format-alist
1385 ibuffer-compiled-filter-formats
))))))
1387 (defun ibuffer-current-format (&optional uncompiledp
)
1388 (or ibuffer-current-format
1389 (setq ibuffer-current-format
0))
1390 (nth ibuffer-current-format
(ibuffer-current-formats uncompiledp
)))
1392 (defun ibuffer-expand-format-entry (form)
1393 (if (or (consp form
)
1395 (let ((sym (intern (concat "ibuffer-make-column-"
1396 (symbol-name (if (consp form
)
1399 (unless (or (fboundp sym
)
1400 (assq sym ibuffer-inline-columns
))
1401 (error "Unknown column %s in ibuffer-formats" form
))
1402 (let (min max align elide
)
1404 (setq min
(or (nth 1 form
) 0)
1405 max
(or (nth 2 form
) -
1)
1406 align
(or (nth 3 form
) :left
)
1407 elide
(or (nth 4 form
) nil
))
1412 (list sym min max align elide
)))
1415 (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p
)
1416 (let ((ellipsis (propertize ibuffer-eliding-string
'font-lock-face
'bold
)))
1417 (if (or elide
(with-no-warnings ibuffer-elide-long-columns
))
1422 (length ibuffer-eliding-string
)))
1424 (substring ,strvar
0 (- strlen
,(length ellipsis
)))
1429 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p
)
1433 `(substring ,strvar
0 ,maxvar
)))
1435 (defun ibuffer-compile-make-format-form (strvar widthform alignment
)
1436 (let* ((left `(make-string tmp2 ?\s
))
1437 (right `(make-string (- tmp1 tmp2
) ?\s
)))
1439 (setq tmp1
,widthform
1442 (:right
`(concat ,left
,right
,strvar
))
1443 (:center
`(concat ,left
,strvar
,right
))
1444 (:left
`(concat ,strvar
,left
,right
))
1445 (t (error "Invalid alignment %s" alignment
))))))
1447 (defun ibuffer-compile-format (format)
1449 ;; We use these variables to keep track of which variables
1450 ;; inside the generated function we need to bind, since
1451 ;; binding variables in Emacs takes time.
1452 str-used tmp1-used tmp2-used global-strlen-used
)
1453 (dolist (form format
)
1455 ;; Generate a form based on a particular format entry, like
1456 ;; " ", mark, or (mode 16 16 :right).
1458 ;; It's a string; all we need to do is insert it.
1460 (let* ((form (ibuffer-expand-format-entry form
))
1464 (align (nth 3 form
))
1465 (elide (nth 4 form
)))
1466 (let* ((from-end-p (when (minusp min
)
1473 min-used max-used strlen-used
)
1474 (when (or (not (integerp min
)) (>= min
0))
1475 ;; This is a complex case; they want it limited to a
1478 (setq str-used t strlen-used t global-strlen-used t
1479 tmp1-used t tmp2-used t
)
1480 ;; Generate code to limit the string to a minimum size.
1481 (setq minform
`(progn
1483 ,(ibuffer-compile-make-format-form
1485 `(- ,(if (integerp min
)
1490 (when (or (not (integerp max
)) (> max
0))
1491 (setq str-used t max-used t
)
1492 ;; Generate code to limit the string to a maximum size.
1493 (setq maxform
`(progn
1495 ,(ibuffer-compile-make-substring-form
1501 (setq strlen
(length str
))
1503 ,(ibuffer-compile-make-eliding-form 'str
1506 ;; Now, put these forms together with the rest of the code.
1508 ;; Is this an "inline" column? This means we have
1509 ;; to get the code from the
1510 ;; `ibuffer-inline-columns' alist and insert it
1511 ;; into our generated code. Otherwise, we just
1512 ;; generate a call to the column function.
1513 (ibuffer-aif (assq sym ibuffer-inline-columns
)
1515 `(,sym buffer mark
)))
1516 ;; You're not expected to understand this. Hell, I
1517 ;; don't even understand it, and I wrote it five
1519 (insertgenfn (ibuffer-aif (get sym
'ibuffer-column-summarizer
)
1520 ;; I really, really wish Emacs Lisp had closures.
1524 (put ',sym
'ibuffer-column-summary
1525 (cons ret
(get ',sym
'ibuffer-column-summary
)))
1529 (mincompform `(< strlen
,(if (integerp min
)
1532 (maxcompform `(> strlen
,(if (integerp max
)
1535 (if (or min-used max-used
)
1536 ;; The complex case, where we have to limit the
1537 ;; form to a maximum or minimum size.
1539 (when (and min-used
(not (integerp min
)))
1540 (push `(min ,min
) letbindings
))
1541 (when (and max-used
(not (integerp max
)))
1542 (push `(max ,max
) letbindings
))
1544 (if (and min-used max-used
)
1556 `(setq str
,callform
)
1558 `(strlen (length str
))))
1561 (append outforms
(list (funcall insertgenfn
'str sym
)))))
1562 ;; The simple case; just insert the string.
1563 (push (funcall insertgenfn callform sym
) outforms
))
1564 ;; Finally, return a `let' form which binds the
1565 ;; variables in `letbindings', and contains all the
1566 ;; code in `outforms'.
1571 ;; We don't want to unconditionally load the byte-compiler.
1572 (funcall (if (or ibuffer-always-compile-formats
1573 (featurep 'bytecomp
))
1576 ;; Here, we actually create a lambda form which
1577 ;; inserts all the generated forms for each entry
1578 ;; in the format string.
1579 (nconc (list 'lambda
'(buffer mark
))
1580 `((let ,(append (when str-used
1582 (when global-strlen-used
1588 ,@(nreverse result
))))))))
1590 (defun ibuffer-recompile-formats ()
1591 "Recompile `ibuffer-formats'."
1593 (setq ibuffer-compiled-formats
1594 (mapcar #'ibuffer-compile-format ibuffer-formats
))
1595 (when (boundp 'ibuffer-filter-format-alist
)
1596 (setq ibuffer-compiled-filter-formats
1597 (mapcar #'(lambda (entry)
1599 (mapcar #'(lambda (formats)
1600 (mapcar #'ibuffer-compile-format formats
))
1602 ibuffer-filter-format-alist
))))
1604 (defun ibuffer-clear-summary-columns (format)
1605 (dolist (form format
)
1606 (ibuffer-awhen (and (consp form
)
1607 (get (car form
) 'ibuffer-column-summarizer
))
1608 (put (car form
) 'ibuffer-column-summary nil
))))
1610 (defun ibuffer-check-formats ()
1611 (when (null ibuffer-formats
)
1612 (error "No formats!"))
1613 (let ((ext-loaded (featurep 'ibuf-ext
)))
1614 (when (or (null ibuffer-compiled-formats
)
1615 (null ibuffer-cached-formats
)
1616 (not (eq ibuffer-cached-formats ibuffer-formats
))
1617 (null ibuffer-cached-eliding-string
)
1618 (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string
))
1619 (eql 0 ibuffer-cached-elide-long-columns
)
1620 (not (eql ibuffer-cached-elide-long-columns
1621 (with-no-warnings ibuffer-elide-long-columns
)))
1623 (not (eq ibuffer-cached-filter-formats
1624 ibuffer-filter-format-alist
))
1625 (and ibuffer-filter-format-alist
1626 (null ibuffer-compiled-filter-formats
))))
1627 (message "Formats have changed, recompiling...")
1628 (ibuffer-recompile-formats)
1629 (setq ibuffer-cached-formats ibuffer-formats
1630 ibuffer-cached-eliding-string ibuffer-eliding-string
1631 ibuffer-cached-elide-long-columns
(with-no-warnings ibuffer-elide-long-columns
))
1633 (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist
))
1634 (message "Formats have changed, recompiling...done"))))
1636 (defvar ibuffer-inline-columns nil
)
1638 (define-ibuffer-column mark
(:name
" " :inline t
)
1641 (define-ibuffer-column read-only
(:name
"R" :inline t
)
1642 (if buffer-read-only
1643 (string ibuffer-read-only-char
)
1646 (define-ibuffer-column modified
(:name
"M" :inline t
)
1647 (if (buffer-modified-p)
1648 (string ibuffer-modified-char
)
1651 (define-ibuffer-column name
1654 ('mouse-face
'highlight
'keymap ibuffer-name-map
1655 'ibuffer-name-column t
1656 'help-echo
'(if tooltip-mode
1657 "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"
1658 "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate"))
1661 (let ((bufs (length strings
)))
1662 (cond ((zerop bufs
) "No buffers")
1663 ((= 1 bufs
) "1 buffer")
1664 (t (format "%s buffers" bufs
))))))
1665 (propertize (buffer-name) 'font-lock-face
(ibuffer-buffer-name-face buffer mark
)))
1667 (define-ibuffer-column size
1670 (lambda (column-strings)
1672 (dolist (string column-strings
)
1675 (+ (float (string-to-number string
))
1677 (format "%.0f" total
))))
1678 (format "%s" (buffer-size)))
1680 (define-ibuffer-column mode
1683 ('mouse-face
'highlight
1684 'keymap ibuffer-mode-name-map
1685 'help-echo
"mouse-2: filter by this mode"))
1686 (format "%s" mode-name
))
1688 (define-ibuffer-column process
1691 (let ((total (length (delete "" strings
))))
1692 (cond ((zerop total
) "No processes")
1693 ((= 1 total
) "1 process")
1694 (t (format "%d processes" total
))))))
1695 (ibuffer-aif (get-buffer-process buffer
)
1696 (format "(%s %s)" it
(process-status it
))
1699 (define-ibuffer-column filename
1702 (let ((total (length (delete "" strings
))))
1703 (cond ((zerop total
) "No files")
1704 ((= 1 total
) "1 file")
1705 (t (format "%d files" total
))))))
1706 (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist
))
1707 (abbreviate-file-name
1708 (or buffer-file-name
1709 (and (boundp 'dired-directory
)
1710 (if (stringp dired-directory
)
1712 (car dired-directory
)))
1715 (define-ibuffer-column filename-and-process
1716 (:name
"Filename/Process"
1719 (setq strings
(delete "" strings
))
1722 (dolist (string strings
)
1723 (if (string-match "\\(\?:\\`(\[\[:ascii:\]\]\+)\\)" string
)
1724 (progn (setq procs
(1+ procs
))
1725 (if (< (match-end 0) (length string
))
1726 (setq files
(1+ files
))))
1727 (setq files
(1+ files
))))
1728 (concat (cond ((zerop files
) "No files")
1729 ((= 1 files
) "1 file")
1730 (t (format "%d files" files
)))
1732 (cond ((zerop procs
) "no processes")
1733 ((= 1 procs
) "1 process")
1734 (t (format "%d processes" procs
)))))))
1735 (let ((proc (get-buffer-process buffer
))
1736 (filename (ibuffer-make-column-filename buffer mark
)))
1738 (concat (propertize (format "(%s %s)" proc
(process-status proc
))
1739 'font-lock-face
'italic
)
1740 (if (> (length filename
) 0)
1741 (format " %s" filename
)
1745 (defun ibuffer-format-column (str width alignment
)
1746 (let ((left (make-string (/ width
2) ?\s
))
1747 (right (make-string (- width
(/ width
2)) ?\s
)))
1749 (:right
(concat left right str
))
1750 (:center
(concat left str right
))
1751 (t (concat str left right
)))))
1753 (defun ibuffer-buffer-name-face (buf mark
)
1754 (cond ((char-equal mark ibuffer-marked-char
)
1755 ibuffer-marked-face
)
1756 ((char-equal mark ibuffer-deletion-char
)
1757 ibuffer-deletion-face
)
1761 (dolist (e ibuffer-fontification-alist result
)
1762 (when (and (> (car e
) level
)
1763 (with-current-buffer buf
1766 result
(nth 2 e
))))))))
1768 (defun ibuffer-insert-buffer-line (buffer mark format
)
1769 "Insert a line describing BUFFER and MARK using FORMAT."
1770 (assert (eq major-mode
'ibuffer-mode
))
1771 (let ((beg (point)))
1772 (funcall format buffer mark
)
1773 (put-text-property beg
(point) 'ibuffer-properties
(list buffer mark
)))
1776 ;; This function knows a bit too much of the internals. It would be
1777 ;; nice if it was all abstracted away.
1778 (defun ibuffer-redisplay-current ()
1779 (assert (eq major-mode
'ibuffer-mode
))
1783 (let ((curformat (mapcar #'ibuffer-expand-format-entry
1784 (ibuffer-current-format t
))))
1785 (ibuffer-clear-summary-columns curformat
)
1786 (let ((buf (ibuffer-current-buffer)))
1788 (let ((mark (ibuffer-current-mark)))
1790 (delete-region (point) (1+ (line-end-position)))
1791 (ibuffer-insert-buffer-line
1793 (ibuffer-current-format)))
1794 (when ibuffer-shrink-to-minimum-size
1795 (ibuffer-shrink-to-fit)))))))
1797 (defun ibuffer-map-on-mark (mark func
)
1800 (if (char-equal mark mk
)
1801 (funcall func buf mark
)
1804 (defun ibuffer-map-lines (function &optional nomodify group
)
1805 "Call FUNCTION for each buffer.
1806 Don't set the ibuffer modification flag iff NOMODIFY is non-nil.
1808 If optional argument GROUP is non-nil, then only call FUNCTION on
1809 buffers in filtering group GROUP.
1811 FUNCTION is called with two arguments:
1812 the buffer object itself and the current mark symbol."
1813 (assert (eq major-mode
'ibuffer-mode
))
1814 (ibuffer-forward-line 0)
1815 (let* ((orig-target-line (1+ (count-lines (save-excursion
1816 (goto-char (point-min))
1817 (ibuffer-forward-line 0)
1820 (target-line-offset orig-target-line
)
1821 (ibuffer-map-lines-total 0)
1822 (ibuffer-map-lines-count 0))
1825 (setq buffer-read-only nil
)
1826 (goto-char (point-min))
1827 (ibuffer-forward-line 0 t
)
1828 (while (and (not (eobp))
1829 (not (get-text-property (point) 'ibuffer-summary
))
1831 (ibuffer-forward-line 0 t
)
1833 (not (get-text-property (point) 'ibuffer-summary
)))))
1835 (if (buffer-live-p (ibuffer-current-buffer))
1836 (when (or (null group
)
1837 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group
)
1841 (ibuffer-current-buffer)
1842 (ibuffer-current-mark))))
1843 ;; Kill the line if the buffer is dead
1845 ;; A given mapping function should return:
1846 ;; `nil' if it chose not to affect the buffer
1847 ;; `kill' means the remove line from the buffer list
1849 (incf ibuffer-map-lines-total
)
1850 (cond ((null result
)
1853 (delete-region (line-beginning-position)
1854 (1+ (line-end-position)))
1855 (incf ibuffer-map-lines-count
)
1856 (when (< ibuffer-map-lines-total
1858 (decf target-line-offset
)))
1860 (incf ibuffer-map-lines-count
)
1861 (forward-line 1)))))
1862 ibuffer-map-lines-count
)
1864 (setq buffer-read-only t
)
1866 (set-buffer-modified-p nil
))
1867 (goto-char (point-min))
1868 (ibuffer-forward-line 0)
1869 (ibuffer-forward-line (1- target-line-offset
))))))
1871 (defun ibuffer-get-marked-buffers ()
1872 "Return a list of buffer objects currently marked."
1874 (mapcar #'(lambda (e)
1875 (when (eq (cdr e
) ibuffer-marked-char
)
1877 (ibuffer-current-state-list))))
1879 (defun ibuffer-current-state-list (&optional pos
)
1880 "Return a list like (BUF . MARK) of all buffers in an ibuffer.
1881 If POS is non-nil, return a list like (BUF MARK POINT), where POINT is
1882 the value of point at the beginning of the line for that buffer."
1883 (let ((ibuffer-current-state-list-tmp '()))
1884 ;; ah, if only we had closures. I bet this will mysteriously
1885 ;; break later. Don't blame me.
1887 (ibuffer-map-lines-nomodify
1888 #'(lambda (buf mark
)
1889 (when (buffer-live-p buf
)
1890 (push (list buf mark
(point)) ibuffer-current-state-list-tmp
))))
1891 (ibuffer-map-lines-nomodify
1892 #'(lambda (buf mark
)
1893 (when (buffer-live-p buf
)
1894 (push (cons buf mark
) ibuffer-current-state-list-tmp
)))))
1895 (nreverse ibuffer-current-state-list-tmp
)))
1897 (defun ibuffer-current-buffers-with-marks (curbufs)
1898 "Return a list like (BUF . MARK) of all open buffers."
1899 (let ((bufs (ibuffer-current-state-list)))
1900 (mapcar #'(lambda (buf) (let ((e (assq buf bufs
)))
1906 (defun ibuffer-buf-matches-predicates (buf predicates
)
1908 (name (buffer-name buf
)))
1909 (dolist (pred predicates
)
1910 (when (if (stringp pred
)
1911 (string-match pred name
)
1916 (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all
)
1917 (let ((ext-loaded (featurep 'ibuf-ext
)))
1920 ;; element should be like (BUFFER . MARK)
1922 (let* ((buf (car e
)))
1924 ;; This takes precedence over anything else
1925 (or (and ibuffer-always-show-last-buffer
1927 (funcall (if ext-loaded
1928 #'ibuffer-ext-visible-p
1929 #'ibuffer-visible-p
)
1930 buf all ibuffer-buf
))
1934 (defun ibuffer-visible-p (buf all
&optional ibuffer-buf
)
1937 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates
)))
1938 (or ibuffer-view-ibuffer
1940 (not (eq ibuffer-buf buf
))))))
1942 ;; This function is a special case; it's not defined by
1943 ;; `ibuffer-define-sorter'.
1944 (defun ibuffer-do-sort-by-recency ()
1945 "Sort the buffers by last view time."
1947 (setq ibuffer-sorting-mode
'recency
)
1948 (ibuffer-redisplay t
))
1950 (defun ibuffer-update-format ()
1951 (when (null ibuffer-current-format
)
1952 (setq ibuffer-current-format
0))
1953 (when (null ibuffer-formats
)
1954 (error "Ibuffer error: no formats!")))
1956 (defun ibuffer-switch-format ()
1957 "Switch the current display format."
1959 (assert (eq major-mode
'ibuffer-mode
))
1960 (unless (consp ibuffer-formats
)
1961 (error "Ibuffer error: No formats!"))
1962 (setq ibuffer-current-format
1963 (if (>= ibuffer-current-format
(1- (length (ibuffer-current-formats nil
))))
1965 (1+ ibuffer-current-format
)))
1966 (ibuffer-update-format)
1967 (ibuffer-redisplay t
))
1969 (defun ibuffer-update-title-and-summary (format)
1970 (assert (eq major-mode
'ibuffer-mode
))
1971 ;; Don't do funky font-lock stuff here
1972 (let ((after-change-functions nil
))
1973 (if (get-text-property (point-min) 'ibuffer-title
)
1974 (delete-region (point-min)
1975 (next-single-property-change
1976 (point-min) 'ibuffer-title
)))
1977 (goto-char (point-min))
1978 (add-text-properties
1981 (let ((opos (point)))
1982 ;; Insert the title names.
1983 (dolist (element format
)
1985 (if (stringp element
)
1987 (let ((sym (car element
))
1988 (min (cadr element
))
1989 ;; (max (caddr element))
1990 (align (cadddr element
)))
1991 ;; Ignore a negative min when we're inserting the title
1994 (let* ((name (or (get sym
'ibuffer-column-name
)
1995 (error "Unknown column %s in ibuffer-formats" sym
)))
1996 (len (length name
)))
1998 (ibuffer-format-column name
2002 (add-text-properties opos
(point) `(ibuffer-title-header t
))
2004 ;; Add the underlines
2005 (let ((str (save-excursion
2008 (buffer-substring (point) (line-end-position)))))
2009 (apply #'insert
(mapcar
2011 (if (not (or (char-equal c ?\s
)
2012 (char-equal c ?
\n)))
2018 `(ibuffer-title t font-lock-face
,ibuffer-title-face
))
2019 ;; Now, insert the summary columns.
2020 (goto-char (point-max))
2021 (if (get-text-property (1- (point-max)) 'ibuffer-summary
)
2022 (delete-region (previous-single-property-change
2023 (point-max) 'ibuffer-summary
)
2025 (if ibuffer-display-summary
2026 (add-text-properties
2030 (dolist (element format
)
2032 (if (stringp element
)
2033 (make-string (length element
) ?\s
)
2034 (let ((sym (car element
)))
2035 (let ((min (cadr element
))
2036 ;; (max (caddr element))
2037 (align (cadddr element
)))
2038 ;; Ignore a negative min when we're inserting the title
2041 (let* ((summary (if (get sym
'ibuffer-column-summarizer
)
2042 (funcall (get sym
'ibuffer-column-summarizer
)
2043 (get sym
'ibuffer-column-summary
))
2044 (make-string (length (get sym
'ibuffer-column-name
))
2046 (len (length summary
)))
2048 (ibuffer-format-column summary
2053 `(ibuffer-summary t
)))))
2055 (defun ibuffer-update-mode-name ()
2056 (setq mode-name
(format "Ibuffer by %s" (if ibuffer-sorting-mode
2057 ibuffer-sorting-mode
2059 (when ibuffer-sorting-reversep
2060 (setq mode-name
(concat mode-name
" [rev]")))
2061 (when (and (featurep 'ibuf-ext
)
2063 (setq mode-name
(concat mode-name
" (Auto)")))
2065 (when (featurep 'ibuf-ext
)
2066 (dolist (qualifier ibuffer-filtering-qualifiers
)
2068 (concat result
(ibuffer-format-qualifier qualifier
))))
2069 (if ibuffer-use-header-line
2070 (setq header-line-format
2071 (when ibuffer-filtering-qualifiers
2072 (replace-regexp-in-string "%" "%%"
2073 (concat mode-name result
))))
2075 (setq mode-name
(concat mode-name result
))
2076 (when (boundp 'header-line-format
)
2077 (setq header-line-format nil
)))))))
2079 (defun ibuffer-redisplay (&optional silent
)
2080 "Redisplay the current list of buffers.
2081 This does not show new buffers; use `ibuffer-update' for that.
2083 If optional arg SILENT is non-nil, do not display progress messages."
2085 (ibuffer-forward-line 0)
2087 (message "Redisplaying current buffer list..."))
2088 (let ((blist (ibuffer-current-state-list)))
2090 (if (and (featurep 'ibuf-ext
)
2091 (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups
))
2092 (message "No buffers! (note: filtering in effect)")
2093 (error "No buffers!")))
2094 (ibuffer-redisplay-engine blist t
)
2095 (ibuffer-update-mode-name)
2097 (message "Redisplaying current buffer list...done"))
2098 (ibuffer-forward-line 0)))
2100 (defun ibuffer-update (arg &optional silent
)
2101 "Regenerate the list of all buffers.
2103 Prefix arg non-nil means to toggle whether buffers that match
2104 `ibuffer-maybe-show-predicates' should be displayed.
2106 If optional arg SILENT is non-nil, do not display progress messages."
2109 (setq ibuffer-display-maybe-show-predicates
2110 (not ibuffer-display-maybe-show-predicates
)))
2111 (ibuffer-forward-line 0)
2112 (let* ((bufs (buffer-list))
2113 (blist (ibuffer-filter-buffers
2117 (eq ibuffer-always-show-last-buffer
2119 (minibufferp (cadr bufs
)))
2122 (ibuffer-current-buffers-with-marks bufs
)
2123 ibuffer-display-maybe-show-predicates
)))
2125 (if (and (featurep 'ibuf-ext
)
2126 ibuffer-filtering-qualifiers
)
2127 (message "No buffers! (note: filtering in effect)")
2128 (error "No buffers!")))
2130 (message "Updating buffer list..."))
2131 (ibuffer-redisplay-engine blist arg
)
2132 (ibuffer-update-mode-name)
2134 (message "Updating buffer list...done")))
2135 (if (eq ibuffer-shrink-to-minimum-size
'onewindow
)
2136 (ibuffer-shrink-to-fit t
)
2137 (when ibuffer-shrink-to-minimum-size
2138 (ibuffer-shrink-to-fit)))
2139 (ibuffer-forward-line 0))
2141 (defun ibuffer-sort-bufferlist (bmarklist)
2142 (let* ((sortdat (assq ibuffer-sorting-mode
2143 ibuffer-sorting-functions-alist
))
2144 (func (caddr sortdat
)))
2146 ;; actually sort the buffers
2147 (if (and sortdat func
)
2148 (sort bmarklist func
)
2150 ;; perhaps reverse the sorted buffer list
2151 (if ibuffer-sorting-reversep
2155 (defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist
)
2156 (add-text-properties
2159 (insert "[ " display-name
" ]")
2161 `(ibuffer-filter-group-name
2163 font-lock-face
,ibuffer-filter-group-name-face
2164 keymap
,ibuffer-mode-filter-group-map
2165 mouse-face highlight
2166 help-echo
,(let ((echo '(if tooltip-mode
2167 "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group"
2168 "mouse-1: toggle marks mouse-2: hide/show")))
2169 (if (> (length filter-string
) 0)
2170 `(concat ,filter-string
2171 (if tooltip-mode
"\n" " ")
2179 (dolist (entry bmarklist
)
2180 (ibuffer-insert-buffer-line (car entry
) (cdr entry
) format
))
2182 'ibuffer-filter-group
2185 (defun ibuffer-redisplay-engine (bmarklist &optional ignore
)
2186 (assert (eq major-mode
'ibuffer-mode
))
2187 (let* ((--ibuffer-insert-buffers-and-marks-format
2188 (ibuffer-current-format))
2189 (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry
2190 (ibuffer-current-format t
)))
2191 (orig (count-lines (point-min) (point)))
2192 ;; Inhibit font-lock caching tricks, since we're modifying the
2193 ;; entire buffer at once
2194 (after-change-functions nil
)
2195 (ext-loaded (featurep 'ibuf-ext
))
2196 (bgroups (if ext-loaded
2197 (ibuffer-generate-filter-groups bmarklist
)
2198 (list (cons "Default" bmarklist
)))))
2199 (ibuffer-clear-summary-columns --ibuffer-expanded-format
)
2202 (setq buffer-read-only nil
)
2204 (ibuffer-update-format)
2205 (dolist (group (nreverse bgroups
))
2206 (let* ((name (car group
))
2207 (disabled (and ext-loaded
2208 (member name ibuffer-hidden-filter-groups
)))
2209 (bmarklist (cdr group
)))
2210 (unless (and (null bmarklist
)
2213 (null ibuffer-show-empty-filter-groups
))
2214 (ibuffer-insert-filter-group
2216 (if disabled
(concat name
" ...") name
)
2218 (ibuffer-format-filter-group-data name
)
2220 --ibuffer-insert-buffers-and-marks-format
2223 (ibuffer-sort-bufferlist bmarklist
))))))
2224 (ibuffer-update-title-and-summary --ibuffer-expanded-format
))
2225 (setq buffer-read-only t
)
2226 (set-buffer-modified-p ibuffer-did-modification
)
2227 (setq ibuffer-did-modification nil
)
2228 (goto-line (1+ orig
)))))
2230 (defun ibuffer-quit ()
2231 "Quit this `ibuffer' session.
2232 Try to restore the previous window configuration iff
2233 `ibuffer-restore-window-config-on-quit' is non-nil."
2235 (if ibuffer-restore-window-config-on-quit
2238 (unless (= (count-windows) 1)
2239 (set-window-configuration ibuffer-prev-window-config
)))
2243 (defun ibuffer-list-buffers (&optional files-only
)
2244 "Display a list of buffers, in another window.
2245 If optional argument FILES-ONLY is non-nil, then add a filter for
2246 buffers which are visiting a file."
2248 (ibuffer t nil
(when files-only
2249 '((filename .
".*"))) t
))
2252 (defun ibuffer-other-window (&optional files-only
)
2253 "Like `ibuffer', but displayed in another window by default.
2254 If optional argument FILES-ONLY is non-nil, then add a filter for
2255 buffers which are visiting a file."
2257 (ibuffer t nil
(when files-only
2258 '((filename .
".*")))))
2261 (defun ibuffer (&optional other-window-p name qualifiers noselect
2262 shrink filter-groups formats
)
2263 "Begin using Ibuffer to edit a list of buffers.
2264 Type 'h' after entering ibuffer for more information.
2266 All arguments are optional.
2267 OTHER-WINDOW-P says to use another window.
2268 NAME specifies the name of the buffer (defaults to \"*Ibuffer*\").
2269 QUALIFIERS is an initial set of filtering qualifiers to use;
2270 see `ibuffer-filtering-qualifiers'.
2271 NOSELECT means don't select the Ibuffer buffer.
2272 SHRINK means shrink the buffer to minimal size. The special
2273 value `onewindow' means always use another window.
2274 FILTER-GROUPS is an initial set of filtering groups to use;
2275 see `ibuffer-filter-groups'.
2276 FORMATS is the value to use for `ibuffer-formats'.
2277 If specified, then the variable `ibuffer-formats' will have
2278 that value locally in this buffer."
2280 (when ibuffer-use-other-window
2281 (setq other-window-p t
))
2282 (setq ibuffer-prev-window-config
(current-window-configuration))
2283 (let ((buf (get-buffer-create (or name
"*Ibuffer*"))))
2285 (funcall (if noselect
#'(lambda (buf) (display-buffer buf t
)) #'pop-to-buffer
) buf
)
2286 (funcall (if noselect
#'display-buffer
#'switch-to-buffer
) buf
))
2287 (with-current-buffer buf
2288 (save-selected-window
2289 ;; We switch to the buffer's window in order to be able
2290 ;; to modify the value of point
2291 (select-window (get-buffer-window buf
0))
2292 (or (eq major-mode
'ibuffer-mode
)
2294 (setq ibuffer-restore-window-config-on-quit other-window-p
)
2296 (setq ibuffer-shrink-to-minimum-size shrink
))
2299 (setq ibuffer-filtering-qualifiers qualifiers
))
2302 (setq ibuffer-filter-groups filter-groups
))
2304 (set (make-local-variable 'ibuffer-formats
) formats
))
2305 (ibuffer-update nil
)
2306 ;; Skip the group name by default.
2307 (ibuffer-forward-line 0 t
)
2310 (setq buffer-read-only nil
)
2311 (run-hooks 'ibuffer-hook
))
2312 (setq buffer-read-only t
))
2313 (unless ibuffer-expert
2314 (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))))))
2316 (put 'ibuffer-mode
'mode-class
'special
)
2317 (defun ibuffer-mode ()
2318 "A major mode for viewing a list of buffers.
2319 In Ibuffer, you can conveniently perform many operations on the
2320 currently open buffers, in addition to filtering your view to a
2321 particular subset of them, and sorting by various criteria.
2323 Operations on marked buffers:
2325 '\\[ibuffer-do-save]' - Save the marked buffers
2326 '\\[ibuffer-do-view]' - View the marked buffers in this frame.
2327 '\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame.
2328 '\\[ibuffer-do-revert]' - Revert the marked buffers.
2329 '\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers.
2330 '\\[ibuffer-do-delete]' - Kill the marked buffers.
2331 '\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked
2333 '\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers.
2334 '\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression.
2335 '\\[ibuffer-do-print]' - Print the marked buffers.
2336 '\\[ibuffer-do-occur]' - List lines in all marked buffers which match
2337 a given regexp (like the function `occur').
2338 '\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked
2339 buffers to a shell command.
2340 '\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked
2341 buffers with the output of a shell command.
2342 '\\[ibuffer-do-shell-command-file]' - Run a shell command with the
2343 buffer's file as an argument.
2344 '\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This
2345 is a very flexible command. For example, if you want to make all
2346 of the marked buffers read only, try using (toggle-read-only 1) as
2348 '\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form
2350 '\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer,
2351 but don't kill the associated buffer.
2352 '\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion.
2356 '\\[ibuffer-mark-forward]' - Mark the buffer at point.
2357 '\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark
2358 all unmarked buffers.
2359 '\\[ibuffer-unmark-forward]' - Unmark the buffer at point.
2360 '\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the
2362 '\\[ibuffer-unmark-all]' - Unmark all marked buffers.
2363 '\\[ibuffer-mark-by-mode]' - Mark buffers by major mode.
2364 '\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers.
2365 This means that the buffer is modified, and has an associated file.
2366 '\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers,
2367 regardless of whether or not they have an associated file.
2368 '\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and
2370 '\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have
2371 an associated file, but that file doesn't currently exist.
2372 '\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers.
2373 '\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode.
2374 '\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc.
2375 '\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'.
2376 '\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion.
2377 '\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp.
2378 '\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp.
2379 '\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp.
2383 '\\[ibuffer-filter-by-mode]' - Add a filter by major mode.
2384 '\\[ibuffer-filter-by-used-mode]' - Add a filter by major mode now in use.
2385 '\\[ibuffer-filter-by-name]' - Add a filter by buffer name.
2386 '\\[ibuffer-filter-by-content]' - Add a filter by buffer content.
2387 '\\[ibuffer-filter-by-filename]' - Add a filter by filename.
2388 '\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size.
2389 '\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size.
2390 '\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate.
2391 '\\[ibuffer-save-filters]' - Save the current filters with a name.
2392 '\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters.
2393 '\\[ibuffer-add-saved-filters]' - Add saved filters to current filters.
2394 '\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR.
2395 '\\[ibuffer-pop-filter]' - Remove the top filter.
2396 '\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter.
2397 '\\[ibuffer-decompose-filter]' - Break down the topmost filter.
2398 '\\[ibuffer-filter-disable]' - Remove all filtering currently in effect.
2400 Filter group commands:
2402 '\\[ibuffer-filters-to-filter-group]' - Create filter group from filters.
2403 '\\[ibuffer-pop-filter-group]' - Remove top filter group.
2404 '\\[ibuffer-forward-filter-group]' - Move to the next filter group.
2405 '\\[ibuffer-backward-filter-group]' - Move to the previous filter group.
2406 '\\[ibuffer-clear-filter-groups]' - Remove all active filter groups.
2407 '\\[ibuffer-save-filter-groups]' - Save the current groups with a name.
2408 '\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups.
2409 '\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups.
2413 '\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes.
2414 '\\[ibuffer-invert-sorting]' - Reverse the current sorting order.
2415 '\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically.
2416 '\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time.
2417 '\\[ibuffer-do-sort-by-size]' - Sort the buffers by size.
2418 '\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode.
2422 '\\[ibuffer-switch-format]' - Change the current display format.
2423 '\\[forward-line]' - Move point to the next line.
2424 '\\[previous-line]' - Move point to the previous line.
2425 '\\[ibuffer-update]' - As above, but add new buffers to the list.
2426 '\\[ibuffer-quit]' - Bury the Ibuffer buffer.
2427 '\\[describe-mode]' - This help.
2428 '\\[ibuffer-diff-with-file]' - View the differences between this buffer
2429 and its associated file.
2430 '\\[ibuffer-visit-buffer]' - View the buffer on this line.
2431 '\\[ibuffer-visit-buffer-other-window]' - As above, but in another window.
2432 '\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select
2434 '\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line.
2436 ** Information on Filtering:
2438 You can filter your ibuffer view via different critera. Each Ibuffer
2439 buffer has its own stack of active filters. For example, suppose you
2440 are working on an Emacs Lisp project. You can create an Ibuffer
2441 buffer displays buffers in just `emacs-lisp' modes via
2442 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there
2443 is just one entry on the filtering stack.
2445 You can also combine filters. The various filtering commands push a
2446 new filter onto the stack, and the filters combine to show just
2447 buffers which satisfy ALL criteria on the stack. For example, suppose
2448 you only want to see buffers in `emacs-lisp' mode, whose names begin
2449 with \"gnus\". You can accomplish this via:
2450 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2451 \\[ibuffer-filter-by-name] ^gnus RET'.
2453 Additionally, you can OR the top two filters together with
2454 '\\[ibuffer-or-filters]'. To see all buffers in either
2455 `emacs-lisp-mode' or `lisp-interaction-mode', type:
2457 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filter-by-mode] lisp-interaction-mode RET \\[ibuffer-or-filters]'.
2459 Filters can also be saved and restored using mnemonic names: see the
2460 functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'.
2462 To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and
2463 to disable all filtering currently in effect, use
2464 '\\[ibuffer-filter-disable]'.
2468 Once one has mastered filters, the next logical step up is \"filter
2469 groups\". A filter group is basically a named group of buffers which
2470 match a filter, which are displayed together in an Ibuffer buffer. To
2471 create a filter group, simply use the regular functions to create a
2472 filter, and then type '\\[ibuffer-filters-to-filter-group]'.
2474 A quick example will make things clearer. Suppose that one wants to
2475 group all of one's Emacs Lisp buffers together. To do this, type
2477 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filters-to-filter-group] RET emacs lisp buffers RET'
2479 You may, of course, name the group whatever you want; it doesn't have
2480 to be \"emacs lisp buffers\". Filter groups may be composed of any
2481 arbitrary combination of filters.
2483 Just like filters themselves, filter groups act as a stack. Buffers
2484 will not be displayed multiple times if they would be included in
2485 multiple filter groups; instead, the first filter group is used. The
2486 filter groups are displayed in this order of precedence.
2488 You may rearrange filter groups by using the regular
2489 '\\[ibuffer-kill-line]' and '\\[ibuffer-yank]' pair. Yanked groups
2490 will be inserted before the group at point."
2491 (kill-all-local-variables)
2492 (use-local-map ibuffer-mode-map
)
2493 (setq major-mode
'ibuffer-mode
)
2494 (setq mode-name
"Ibuffer")
2495 (setq buffer-read-only t
)
2496 (buffer-disable-undo)
2497 (setq truncate-lines ibuffer-truncate-lines
)
2498 ;; This makes things less ugly for Emacs 21 users with a non-nil
2499 ;; `show-trailing-whitespace'.
2500 (setq show-trailing-whitespace nil
)
2501 ;; disable `show-paren-mode' buffer-locally
2502 (if (bound-and-true-p show-paren-mode
)
2503 (set (make-local-variable 'show-paren-mode
) nil
))
2504 (set (make-local-variable 'revert-buffer-function
)
2506 (set (make-local-variable 'ibuffer-sorting-mode
)
2507 ibuffer-default-sorting-mode
)
2508 (set (make-local-variable 'ibuffer-sorting-reversep
)
2509 ibuffer-default-sorting-reversep
)
2510 (set (make-local-variable 'ibuffer-shrink-to-minimum-size
)
2511 ibuffer-default-shrink-to-minimum-size
)
2512 (set (make-local-variable 'ibuffer-display-maybe-show-predicates
)
2513 ibuffer-default-display-maybe-show-predicates
)
2514 (set (make-local-variable 'ibuffer-filtering-qualifiers
) nil
)
2515 (set (make-local-variable 'ibuffer-filter-groups
) nil
)
2516 (set (make-local-variable 'ibuffer-filter-group-kill-ring
) nil
)
2517 (set (make-local-variable 'ibuffer-hidden-filter-groups
) nil
)
2518 (set (make-local-variable 'ibuffer-compiled-formats
) nil
)
2519 (set (make-local-variable 'ibuffer-cached-formats
) nil
)
2520 (set (make-local-variable 'ibuffer-cached-eliding-string
) nil
)
2521 (set (make-local-variable 'ibuffer-cached-elide-long-columns
) nil
)
2522 (set (make-local-variable 'ibuffer-current-format
) nil
)
2523 (set (make-local-variable 'ibuffer-restore-window-config-on-quit
) nil
)
2524 (set (make-local-variable 'ibuffer-did-modification
) nil
)
2525 (set (make-local-variable 'ibuffer-tmp-hide-regexps
) nil
)
2526 (set (make-local-variable 'ibuffer-tmp-show-regexps
) nil
)
2527 (define-key ibuffer-mode-map
[menu-bar edit
] 'undefined
)
2528 (define-key ibuffer-mode-map
[menu-bar operate
] (cons "Operate" ibuffer-mode-operate-map
))
2529 (ibuffer-update-format)
2530 (when ibuffer-default-directory
2531 (setq default-directory ibuffer-default-directory
))
2532 (add-hook 'change-major-mode-hook
'font-lock-defontify nil t
)
2533 (run-mode-hooks 'ibuffer-mode-hook
)
2534 ;; called after mode hooks to allow the user to add filters
2535 (ibuffer-update-mode-name))
2539 (run-hooks 'ibuffer-load-hook
)
2542 ;; coding: iso-8859-1
2545 ;;; arch-tag: 72581688-0603-4954-b8cf-837c700f62e8
2546 ;;; ibuffer.el ends here