1 ;;; ibuffer.el --- operate on buffers like dired
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 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 (and buffer-file-name
146 (string-match ibuffer-compressed-file-name-regexp
149 (20 (string-match "^*" (buffer-name)) font-lock-keyword-face
)
150 (25 (and (string-match "^ " (buffer-name))
151 (null buffer-file-name
))
153 (30 (memq major-mode ibuffer-help-buffer-modes
) font-lock-comment-face
)
154 (35 (eq major-mode
'dired-mode
) font-lock-function-name-face
))
155 "An alist describing how to fontify buffers.
156 Each element should be of the form (PRIORITY FORM FACE), where
157 PRIORITY is an integer, FORM is an arbitrary form to evaluate in the
158 buffer, and FACE is the face to use for fontification. If the FORM
159 evaluates to non-nil, then FACE will be put on the buffer name. The
160 element with the highest PRIORITY takes precedence.
162 If you change this variable, you must kill the Ibuffer buffer and
163 recreate it for the change to take effect."
165 (list (integer :tag
"Priority")
166 (sexp :tag
"Test Form")
170 (defcustom ibuffer-use-other-window nil
171 "If non-nil, display Ibuffer in another window by default."
175 (defcustom ibuffer-default-shrink-to-minimum-size nil
176 "If non-nil, minimize the size of the Ibuffer window by default."
179 (defvar ibuffer-shrink-to-minimum-size nil
)
181 (defcustom ibuffer-display-summary t
182 "If non-nil, summarize Ibuffer columns."
186 (defcustom ibuffer-truncate-lines t
187 "If non-nil, do not display continuation lines."
191 (defcustom ibuffer-case-fold-search case-fold-search
192 "If non-nil, ignore case when searching."
196 (defcustom ibuffer-default-sorting-mode
'recency
197 "The criteria by which to sort the buffers.
199 Note that this variable is local to each Ibuffer buffer. Thus, you
200 can have multiple Ibuffer buffers open, each with a different sorted
201 view of the buffers."
202 :type
'(choice (const :tag
"Last view time" :value recency
)
203 (const :tag
"Lexicographic" :value alphabetic
)
204 (const :tag
"Buffer size" :value size
)
205 (const :tag
"Major mode" :value major-mode
))
207 (defvar ibuffer-sorting-mode nil
)
209 (defcustom ibuffer-default-sorting-reversep nil
210 "If non-nil, reverse the default sorting order."
213 (defvar ibuffer-sorting-reversep nil
)
215 (defcustom ibuffer-elide-long-columns nil
216 "If non-nil, then elide column entries which exceed their max length."
219 (make-obsolete-variable 'ibuffer-elide-long-columns
220 "use the :elide argument of `ibuffer-formats'."
223 (defcustom ibuffer-eliding-string
"..."
224 "The string to use for eliding long columns."
228 (defcustom ibuffer-maybe-show-predicates
`(,(lambda (buf)
229 (and (string-match "^ " (buffer-name buf
))
230 (null buffer-file-name
))))
231 "A list of predicates for buffers to display conditionally.
233 A predicate can be a regexp or a function.
234 If a regexp, then it will be matched against the buffer's name.
235 If a function, it will be called with the buffer as an argument, and
236 should return non-nil if this buffer should be shown.
238 Viewing of buffers hidden because of these predicates may be customized
239 via `ibuffer-default-display-maybe-show-predicates' and is toggled by
240 giving a non-nil prefix argument to `ibuffer-update'.
241 Note that this specialized filtering occurs before real filtering."
242 :type
'(repeat (choice regexp function
))
245 (defcustom ibuffer-default-display-maybe-show-predicates nil
246 "Non-nil means show buffers that match `ibuffer-maybe-show-predicates'."
250 (defvar ibuffer-display-maybe-show-predicates nil
)
252 (defvar ibuffer-current-format nil
)
254 (defcustom ibuffer-movement-cycle t
255 "If non-nil, then forward and backwards movement commands cycle."
259 (defcustom ibuffer-modified-char ?
*
260 "The character to display for modified buffers."
264 (defcustom ibuffer-read-only-char ?%
265 "The character to display for read-only buffers."
269 (defcustom ibuffer-marked-char ?
>
270 "The character to display for marked buffers."
274 (defcustom ibuffer-deletion-char ?D
275 "The character to display for buffers marked for deletion."
279 (defcustom ibuffer-expert nil
280 "If non-nil, don't ask for confirmation of \"dangerous\" operations."
284 (defcustom ibuffer-view-ibuffer nil
285 "If non-nil, display the current Ibuffer buffer itself.
286 Note that this has a drawback - the data about the current Ibuffer
287 buffer will most likely be inaccurate. This includes modification
292 (defcustom ibuffer-always-show-last-buffer nil
293 "If non-nil, always display the previous buffer.
294 This variable takes precedence over filtering, and even
295 `ibuffer-never-show-predicates'."
296 :type
'(choice (const :tag
"Always" :value t
)
297 (const :tag
"Never" :value nil
)
298 (const :tag
"Always except minibuffer" :value
:nomini
))
301 (defcustom ibuffer-jump-offer-only-visible-buffers nil
302 "If non-nil, only offer buffers visible in the Ibuffer buffer
303 in completion lists of the `ibuffer-jump-to-buffer' command."
307 (defcustom ibuffer-use-header-line
(boundp 'header-line-format
)
308 "If non-nil, display a header line containing current filters."
312 (defcustom ibuffer-default-directory nil
313 "The default directory to use for a new Ibuffer buffer.
314 If nil, inherit the directory of the buffer in which `ibuffer' was
315 called. Otherwise, this variable should be a string naming a
316 directory, like `default-directory'."
317 :type
'(choice (const :tag
"Inherit" :value nil
)
321 (defcustom ibuffer-help-buffer-modes
322 '(help-mode apropos-mode Info-mode Info-edit-mode
)
323 "List of \"Help\" major modes."
324 :type
'(repeat function
)
327 (defcustom ibuffer-compressed-file-name-regexp
329 (regexp-opt '("arj" "bgz" "bz2" "gz" "lzh" "taz" "tgz" "zip" "z"))
331 "Regexp to match compressed file names."
335 (defcustom ibuffer-hook nil
336 "Hook run when `ibuffer' is called."
339 (define-obsolete-variable-alias 'ibuffer-hooks
340 'ibuffer-hook
"22.1")
342 (defcustom ibuffer-mode-hook nil
343 "Hook run upon entry into `ibuffer-mode'."
346 (define-obsolete-variable-alias 'ibuffer-mode-hooks
347 'ibuffer-mode-hook
"22.1")
349 (defcustom ibuffer-load-hook nil
350 "Hook run when Ibuffer is loaded."
354 (defcustom ibuffer-marked-face
'font-lock-warning-face
355 "Face used for displaying marked buffers."
359 (defcustom ibuffer-deletion-face
'font-lock-type-face
360 "Face used for displaying buffers marked for deletion."
364 (defcustom ibuffer-title-face
'font-lock-type-face
365 "Face used for the title string."
369 (defcustom ibuffer-filter-group-name-face
'bold
370 "Face used for displaying filtering group names."
374 (defcustom ibuffer-directory-abbrev-alist nil
375 "An alist of file name abbreviations like `directory-abbrev-alist'."
376 :type
'(repeat (cons :format
"%v"
383 (defvar ibuffer-mode-map nil
)
384 (defvar ibuffer-mode-operate-map nil
)
385 (defvar ibuffer-mode-groups-popup nil
)
386 (unless ibuffer-mode-map
387 (let ((map (make-sparse-keymap))
388 (operate-map (make-sparse-keymap "Operate"))
389 (groups-map (make-sparse-keymap "Filter Groups")))
390 (define-key map
(kbd "0") 'digit-argument
)
391 (define-key map
(kbd "1") 'digit-argument
)
392 (define-key map
(kbd "2") 'digit-argument
)
393 (define-key map
(kbd "3") 'digit-argument
)
394 (define-key map
(kbd "4") 'digit-argument
)
395 (define-key map
(kbd "5") 'digit-argument
)
396 (define-key map
(kbd "6") 'digit-argument
)
397 (define-key map
(kbd "7") 'digit-argument
)
398 (define-key map
(kbd "8") 'digit-argument
)
399 (define-key map
(kbd "9") 'digit-argument
)
401 (define-key map
(kbd "m") 'ibuffer-mark-forward
)
402 (define-key map
(kbd "t") 'ibuffer-toggle-marks
)
403 (define-key map
(kbd "u") 'ibuffer-unmark-forward
)
404 (define-key map
(kbd "=") 'ibuffer-diff-with-file
)
405 (define-key map
(kbd "j") 'ibuffer-jump-to-buffer
)
406 (define-key map
(kbd "M-g") 'ibuffer-jump-to-buffer
)
407 (define-key map
(kbd "DEL") 'ibuffer-unmark-backward
)
408 (define-key map
(kbd "M-DEL") 'ibuffer-unmark-all
)
409 (define-key map
(kbd "* *") 'ibuffer-unmark-all
)
410 (define-key map
(kbd "* M") 'ibuffer-mark-by-mode
)
411 (define-key map
(kbd "* m") 'ibuffer-mark-modified-buffers
)
412 (define-key map
(kbd "* u") 'ibuffer-mark-unsaved-buffers
)
413 (define-key map
(kbd "* s") 'ibuffer-mark-special-buffers
)
414 (define-key map
(kbd "* r") 'ibuffer-mark-read-only-buffers
)
415 (define-key map
(kbd "* /") 'ibuffer-mark-dired-buffers
)
416 (define-key map
(kbd "* e") 'ibuffer-mark-dissociated-buffers
)
417 (define-key map
(kbd "* h") 'ibuffer-mark-help-buffers
)
418 (define-key map
(kbd "* z") 'ibuffer-mark-compressed-file-buffers
)
419 (define-key map
(kbd ".") 'ibuffer-mark-old-buffers
)
421 (define-key map
(kbd "d") 'ibuffer-mark-for-delete
)
422 (define-key map
(kbd "C-d") 'ibuffer-mark-for-delete-backwards
)
423 (define-key map
(kbd "k") 'ibuffer-mark-for-delete
)
424 (define-key map
(kbd "x") 'ibuffer-do-kill-on-deletion-marks
)
426 ;; immediate operations
427 (define-key map
(kbd "n") 'ibuffer-forward-line
)
428 (define-key map
(kbd "<down>") 'ibuffer-forward-line
)
429 (define-key map
(kbd "SPC") 'forward-line
)
430 (define-key map
(kbd "p") 'ibuffer-backward-line
)
431 (define-key map
(kbd "<up>") 'ibuffer-backward-line
)
432 (define-key map
(kbd "M-}") 'ibuffer-forward-next-marked
)
433 (define-key map
(kbd "M-{") 'ibuffer-backwards-next-marked
)
434 (define-key map
(kbd "l") 'ibuffer-redisplay
)
435 (define-key map
(kbd "g") 'ibuffer-update
)
436 (define-key map
"`" 'ibuffer-switch-format
)
437 (define-key map
"-" 'ibuffer-add-to-tmp-hide
)
438 (define-key map
"+" 'ibuffer-add-to-tmp-show
)
439 (define-key map
"b" 'ibuffer-bury-buffer
)
440 (define-key map
(kbd ",") 'ibuffer-toggle-sorting-mode
)
441 (define-key map
(kbd "s i") 'ibuffer-invert-sorting
)
442 (define-key map
(kbd "s a") 'ibuffer-do-sort-by-alphabetic
)
443 (define-key map
(kbd "s v") 'ibuffer-do-sort-by-recency
)
444 (define-key map
(kbd "s s") 'ibuffer-do-sort-by-size
)
445 (define-key map
(kbd "s m") 'ibuffer-do-sort-by-major-mode
)
447 (define-key map
(kbd "/ m") 'ibuffer-filter-by-mode
)
448 (define-key map
(kbd "/ M") 'ibuffer-filter-by-used-mode
)
449 (define-key map
(kbd "/ n") 'ibuffer-filter-by-name
)
450 (define-key map
(kbd "/ c") 'ibuffer-filter-by-content
)
451 (define-key map
(kbd "/ e") 'ibuffer-filter-by-predicate
)
452 (define-key map
(kbd "/ f") 'ibuffer-filter-by-filename
)
453 (define-key map
(kbd "/ >") 'ibuffer-filter-by-size-gt
)
454 (define-key map
(kbd "/ <") 'ibuffer-filter-by-size-lt
)
455 (define-key map
(kbd "/ r") 'ibuffer-switch-to-saved-filters
)
456 (define-key map
(kbd "/ a") 'ibuffer-add-saved-filters
)
457 (define-key map
(kbd "/ x") 'ibuffer-delete-saved-filters
)
458 (define-key map
(kbd "/ d") 'ibuffer-decompose-filter
)
459 (define-key map
(kbd "/ s") 'ibuffer-save-filters
)
460 (define-key map
(kbd "/ p") 'ibuffer-pop-filter
)
461 (define-key map
(kbd "/ !") 'ibuffer-negate-filter
)
462 (define-key map
(kbd "/ t") 'ibuffer-exchange-filters
)
463 (define-key map
(kbd "/ TAB") 'ibuffer-exchange-filters
)
464 (define-key map
(kbd "/ o") 'ibuffer-or-filter
)
465 (define-key map
(kbd "/ g") 'ibuffer-filters-to-filter-group
)
466 (define-key map
(kbd "/ P") 'ibuffer-pop-filter-group
)
467 (define-key map
(kbd "/ D") 'ibuffer-decompose-filter-group
)
468 (define-key map
(kbd "/ /") 'ibuffer-filter-disable
)
470 (define-key map
(kbd "M-n") 'ibuffer-forward-filter-group
)
471 (define-key map
(kbd "<right>") 'ibuffer-forward-filter-group
)
472 (define-key map
(kbd "M-p") 'ibuffer-backward-filter-group
)
473 (define-key map
(kbd "<left>") 'ibuffer-backward-filter-group
)
474 (define-key map
(kbd "M-j") 'ibuffer-jump-to-filter-group
)
475 (define-key map
(kbd "C-k") 'ibuffer-kill-line
)
476 (define-key map
(kbd "C-y") 'ibuffer-yank
)
477 (define-key map
(kbd "/ S") 'ibuffer-save-filter-groups
)
478 (define-key map
(kbd "/ R") 'ibuffer-switch-to-saved-filter-groups
)
479 (define-key map
(kbd "/ X") 'ibuffer-delete-saved-filter-groups
)
480 (define-key map
(kbd "/ \\") 'ibuffer-clear-filter-groups
)
482 (define-key map
(kbd "q") 'ibuffer-quit
)
483 (define-key map
(kbd "h") 'describe-mode
)
484 (define-key map
(kbd "?") 'describe-mode
)
486 (define-key map
(kbd "% n") 'ibuffer-mark-by-name-regexp
)
487 (define-key map
(kbd "% m") 'ibuffer-mark-by-mode-regexp
)
488 (define-key map
(kbd "% f") 'ibuffer-mark-by-file-name-regexp
)
490 (define-key map
(kbd "C-t") 'ibuffer-visit-tags-table
)
492 (define-key map
(kbd "|") 'ibuffer-do-shell-command-pipe
)
493 (define-key map
(kbd "!") 'ibuffer-do-shell-command-file
)
494 (define-key map
(kbd "~") 'ibuffer-do-toggle-modified
)
496 (define-key map
(kbd "A") 'ibuffer-do-view
)
497 (define-key map
(kbd "D") 'ibuffer-do-delete
)
498 (define-key map
(kbd "E") 'ibuffer-do-eval
)
499 (define-key map
(kbd "F") 'ibuffer-do-shell-command-file
)
500 (define-key map
(kbd "I") 'ibuffer-do-query-replace-regexp
)
501 (define-key map
(kbd "H") 'ibuffer-do-view-other-frame
)
502 (define-key map
(kbd "N") 'ibuffer-do-shell-command-pipe-replace
)
503 (define-key map
(kbd "M") 'ibuffer-do-toggle-modified
)
504 (define-key map
(kbd "O") 'ibuffer-do-occur
)
505 (define-key map
(kbd "P") 'ibuffer-do-print
)
506 (define-key map
(kbd "Q") 'ibuffer-do-query-replace
)
507 (define-key map
(kbd "R") 'ibuffer-do-rename-uniquely
)
508 (define-key map
(kbd "S") 'ibuffer-do-save
)
509 (define-key map
(kbd "T") 'ibuffer-do-toggle-read-only
)
510 (define-key map
(kbd "U") 'ibuffer-do-replace-regexp
)
511 (define-key map
(kbd "V") 'ibuffer-do-revert
)
512 (define-key map
(kbd "W") 'ibuffer-do-view-and-eval
)
513 (define-key map
(kbd "X") 'ibuffer-do-shell-command-pipe
)
515 (define-key map
(kbd "k") 'ibuffer-do-kill-lines
)
516 (define-key map
(kbd "w") 'ibuffer-copy-filename-as-kill
)
518 (define-key map
(kbd "RET") 'ibuffer-visit-buffer
)
519 (define-key map
(kbd "e") 'ibuffer-visit-buffer
)
520 (define-key map
(kbd "f") 'ibuffer-visit-buffer
)
521 (define-key map
(kbd "C-x C-f") 'ibuffer-find-file
)
522 (define-key map
(kbd "o") 'ibuffer-visit-buffer-other-window
)
523 (define-key map
(kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect
)
524 (define-key map
(kbd "M-o") 'ibuffer-visit-buffer-1-window
)
525 (define-key map
(kbd "v") 'ibuffer-do-view
)
526 (define-key map
(kbd "C-x v") 'ibuffer-do-view-horizontally
)
527 (define-key map
(kbd "C-c C-a") 'ibuffer-auto-mode
)
528 (define-key map
(kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window
)
529 (define-key map
(kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame
)
531 (define-key map
[menu-bar view
]
532 (cons "View" (make-sparse-keymap "View")))
534 (define-key-after map
[menu-bar view visit-buffer
]
535 '(menu-item "View this buffer" ibuffer-visit-buffer
))
536 (define-key-after map
[menu-bar view visit-buffer-other-window
]
537 '(menu-item "View (other window)" ibuffer-visit-buffer-other-window
))
538 (define-key-after map
[menu-bar view visit-buffer-other-frame
]
539 '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame
))
540 (define-key-after map
[menu-bar view ibuffer-update
]
541 '(menu-item "Update" ibuffer-update
542 :help
"Regenerate the list of buffers"))
543 (define-key-after map
[menu-bar view switch-format
]
544 '(menu-item "Switch display format" ibuffer-switch-format
545 :help
"Toggle between available values of `ibuffer-formats'"))
547 (define-key-after map
[menu-bar view dashes
]
550 (define-key-after map
[menu-bar view sort
]
551 (cons "Sort" (make-sparse-keymap "Sort")))
553 (define-key-after map
[menu-bar view sort do-sort-by-major-mode
]
554 '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode
))
555 (define-key-after map
[menu-bar view sort do-sort-by-size
]
556 '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size
))
557 (define-key-after map
[menu-bar view sort do-sort-by-alphabetic
]
558 '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic
559 :help
"Sort by the alphabetic order of buffer name"))
560 (define-key-after map
[menu-bar view sort do-sort-by-recency
]
561 '(menu-item "Sort by view time" ibuffer-do-sort-by-recency
562 :help
"Sort by the last time the buffer was displayed"))
563 (define-key-after map
[menu-bar view sort dashes
]
565 (define-key-after map
[menu-bar view sort invert-sorting
]
566 '(menu-item "Reverse sorting order" ibuffer-invert-sorting
))
567 (define-key-after map
[menu-bar view sort toggle-sorting-mode
]
568 '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode
569 :help
"Switch between the various sorting criteria"))
571 (define-key-after map
[menu-bar view filter
]
572 (cons "Filter" (make-sparse-keymap "Filter")))
574 (define-key-after map
[menu-bar view filter filter-disable
]
575 '(menu-item "Disable all filtering" ibuffer-filter-disable
576 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
577 (define-key-after map
[menu-bar view filter filter-by-mode
]
578 '(menu-item "Add filter by major mode..." ibuffer-filter-by-mode
))
579 (define-key-after map
[menu-bar view filter filter-by-mode
]
580 '(menu-item "Add filter by major mode in use..." ibuffer-filter-by-used-mode
))
581 (define-key-after map
[menu-bar view filter filter-by-name
]
582 '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name
))
583 (define-key-after map
[menu-bar view filter filter-by-filename
]
584 '(menu-item "Add filter by filename..." ibuffer-filter-by-filename
))
585 (define-key-after map
[menu-bar view filter filter-by-size-lt
]
586 '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt
))
587 (define-key-after map
[menu-bar view filter filter-by-size-gt
]
588 '(menu-item "Add filter by size greater than..." ibuffer-filter-by-size-gt
))
589 (define-key-after map
[menu-bar view filter filter-by-content
]
590 '(menu-item "Add filter by content (regexp)..." ibuffer-filter-by-content
))
591 (define-key-after map
[menu-bar view filter filter-by-predicate
]
592 '(menu-item "Add filter by Lisp predicate..." ibuffer-filter-by-predicate
))
593 (define-key-after map
[menu-bar view filter pop-filter
]
594 '(menu-item "Remove top filter" ibuffer-pop-filter
595 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
596 (define-key-after map
[menu-bar view filter or-filter
]
597 '(menu-item "OR top two filters" ibuffer-or-filter
598 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
599 (cdr ibuffer-filtering-qualifiers
))
600 :help
"Create a new filter which is the logical OR of the top two filters"))
601 (define-key-after map
[menu-bar view filter negate-filter
]
602 '(menu-item "Negate top filter" ibuffer-negate-filter
603 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
604 (define-key-after map
[menu-bar view filter decompose-filter
]
605 '(menu-item "Decompose top filter" ibuffer-decompose-filter
606 :enable
(and (featurep 'ibuf-ext
) (memq (car ibuffer-filtering-qualifiers
) '(or saved not
)))
607 :help
"Break down a complex filter like OR or NOT"))
608 (define-key-after map
[menu-bar view filter exchange-filters
]
609 '(menu-item "Swap top two filters" ibuffer-exchange-filters
610 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
611 (cdr ibuffer-filtering-qualifiers
))))
612 (define-key-after map
[menu-bar view filter save-filters
]
613 '(menu-item "Save current filters permanently..." ibuffer-save-filters
614 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
615 :help
"Use a mnemnonic name to store current filter stack"))
616 (define-key-after map
[menu-bar view filter switch-to-saved-filters
]
617 '(menu-item "Restore permanently saved filters..." ibuffer-switch-to-saved-filters
618 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)
619 :help
"Replace current filters with a saved stack"))
620 (define-key-after map
[menu-bar view filter add-saved-filters
]
621 '(menu-item "Add to permanently saved filters..." ibuffer-add-saved-filters
622 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)
623 :help
"Include already saved stack with current filters"))
624 (define-key-after map
[menu-bar view filter delete-saved-filters
]
625 '(menu-item "Delete permanently saved filters..."
626 ibuffer-delete-saved-filters
627 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filters
)))
631 (define-key-after groups-map
[filters-to-filter-group
]
632 '(menu-item "Create filter group from current filters..."
633 ibuffer-filters-to-filter-group
634 :enable
(and (featurep 'ibuf-ext
) ibuffer-filtering-qualifiers
)))
635 (define-key-after groups-map
[forward-filter-group
]
636 '(menu-item "Move point to the next filter group"
637 ibuffer-forward-filter-group
))
638 (define-key-after groups-map
[backward-filter-group
]
639 '(menu-item "Move point to the previous filter group"
640 ibuffer-backward-filter-group
))
641 (define-key-after groups-map
[jump-to-filter-group
]
642 '(menu-item "Move point to a specific filter group..."
643 ibuffer-jump-to-filter-group
))
644 (define-key-after groups-map
[kill-filter-group
]
645 '(menu-item "Kill filter group named..."
646 ibuffer-kill-filter-group
647 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
648 (define-key-after groups-map
[yank-filter-group
]
649 '(menu-item "Yank last killed filter group before..."
650 ibuffer-yank-filter-group
651 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-group-kill-ring
)))
652 (define-key-after groups-map
[pop-filter-group
]
653 '(menu-item "Remove top filter group"
654 ibuffer-pop-filter-group
655 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
656 (define-key-after groups-map
[clear-filter-groups
]
657 '(menu-item "Remove all filter groups"
658 ibuffer-clear-filter-groups
659 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
660 (define-key-after groups-map
[pop-filter-group
]
661 '(menu-item "Decompose filter group..."
662 ibuffer-pop-filter-group
663 :help
"\"Unmake\" a filter group"
664 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)))
665 (define-key-after groups-map
[save-filter-groups
]
666 '(menu-item "Save current filter groups permanently..."
667 ibuffer-save-filter-groups
668 :enable
(and (featurep 'ibuf-ext
) ibuffer-filter-groups
)
669 :help
"Use a mnemnonic name to store current filter groups"))
670 (define-key-after groups-map
[switch-to-saved-filter-groups
]
671 '(menu-item "Restore permanently saved filters..."
672 ibuffer-switch-to-saved-filter-groups
673 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)
674 :help
"Replace current filters with a saved stack"))
675 (define-key-after groups-map
[delete-saved-filter-groups
]
676 '(menu-item "Delete permanently saved filter groups..."
677 ibuffer-delete-saved-filter-groups
678 :enable
(and (featurep 'ibuf-ext
) ibuffer-saved-filter-groups
)))
679 (define-key-after groups-map
[set-filter-groups-by-mode
]
680 '(menu-item "Set current filter groups to filter by mode"
681 ibuffer-set-filter-groups-by-mode
))
683 (define-key-after map
[menu-bar view filter-groups
]
684 (cons "Filter Groups" groups-map
))
686 (define-key-after map
[menu-bar view dashes2
]
688 (define-key-after map
[menu-bar view diff-with-file
]
689 '(menu-item "Diff with file" ibuffer-diff-with-file
690 :help
"View the differences between this buffer and its file"))
691 (define-key-after map
[menu-bar view auto-mode
]
692 '(menu-item "Toggle Auto Mode" ibuffer-auto-mode
693 :help
"Attempt to automatically update the Ibuffer buffer"))
694 (define-key-after map
[menu-bar view customize
]
695 '(menu-item "Customize Ibuffer" ibuffer-customize
696 :help
"Use Custom to customize Ibuffer"))
698 (define-key-after map
[menu-bar mark
]
699 (cons "Mark" (make-sparse-keymap "Mark")))
701 (define-key-after map
[menu-bar mark toggle-marks
]
702 '(menu-item "Toggle marks" ibuffer-toggle-marks
703 :help
"Unmark marked buffers, and mark unmarked buffers"))
704 (define-key-after map
[menu-bar mark mark-forward
]
705 '(menu-item "Mark" ibuffer-mark-forward
706 :help
"Mark the buffer at point"))
707 (define-key-after map
[menu-bar mark unmark-forward
]
708 '(menu-item "Unmark" ibuffer-unmark-forward
709 :help
"Unmark the buffer at point"))
710 (define-key-after map
[menu-bar mark mark-by-mode
]
711 '(menu-item "Mark by mode..." ibuffer-mark-by-mode
712 :help
"Mark all buffers in a particular major mode"))
713 (define-key-after map
[menu-bar mark mark-modified-buffers
]
714 '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers
715 :help
"Mark all buffers which have been modified"))
716 (define-key-after map
[menu-bar mark mark-unsaved-buffers
]
717 '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers
718 :help
"Mark all buffers which have a file and are modified"))
719 (define-key-after map
[menu-bar mark mark-read-only-buffers
]
720 '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers
721 :help
"Mark all buffers which are read-only"))
722 (define-key-after map
[menu-bar mark mark-special-buffers
]
723 '(menu-item "Mark special buffers" ibuffer-mark-special-buffers
724 :help
"Mark all buffers whose name begins with a *"))
725 (define-key-after map
[menu-bar mark mark-dired-buffers
]
726 '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers
727 :help
"Mark buffers in dired-mode"))
728 (define-key-after map
[menu-bar mark mark-dissociated-buffers
]
729 '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers
730 :help
"Mark buffers with a non-existent associated file"))
731 (define-key-after map
[menu-bar mark mark-help-buffers
]
732 '(menu-item "Mark help buffers" ibuffer-mark-help-buffers
733 :help
"Mark buffers in help-mode"))
734 (define-key-after map
[menu-bar mark mark-compressed-file-buffers
]
735 '(menu-item "Mark compressed file buffers" ibuffer-mark-compressed-file-buffers
736 :help
"Mark buffers which have a file that is compressed"))
737 (define-key-after map
[menu-bar mark mark-old-buffers
]
738 '(menu-item "Mark old buffers" ibuffer-mark-old-buffers
739 :help
"Mark buffers which have not been viewed recently"))
740 (define-key-after map
[menu-bar mark unmark-all
]
741 '(menu-item "Unmark All" ibuffer-unmark-all
))
743 (define-key-after map
[menu-bar mark dashes
]
746 (define-key-after map
[menu-bar mark mark-by-name-regexp
]
747 '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
748 :help
"Mark buffers whose name matches a regexp"))
749 (define-key-after map
[menu-bar mark mark-by-mode-regexp
]
750 '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp
751 :help
"Mark buffers whose major mode name matches a regexp"))
752 (define-key-after map
[menu-bar mark mark-by-file-name-regexp
]
753 '(menu-item "Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp
754 :help
"Mark buffers whose file name matches a regexp"))
756 ;; Operate map is added later
758 (define-key-after operate-map
[do-view
]
759 '(menu-item "View" ibuffer-do-view
))
760 (define-key-after operate-map
[do-view-other-frame
]
761 '(menu-item "View (separate frame)" ibuffer-do-view-other-frame
))
762 (define-key-after operate-map
[do-save
]
763 '(menu-item "Save" ibuffer-do-save
))
764 (define-key-after operate-map
[do-replace-regexp
]
765 '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp
766 :help
"Replace text inside marked buffers"))
767 (define-key-after operate-map
[do-query-replace
]
768 '(menu-item "Query Replace..." ibuffer-do-query-replace
769 :help
"Replace text in marked buffers, asking each time"))
770 (define-key-after operate-map
[do-query-replace-regexp
]
771 '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp
772 :help
"Replace text in marked buffers by regexp, asking each time"))
773 (define-key-after operate-map
[do-print
]
774 '(menu-item "Print" ibuffer-do-print
))
775 (define-key-after operate-map
[do-toggle-modified
]
776 '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified
))
777 (define-key-after operate-map
[do-revert
]
778 '(menu-item "Revert" ibuffer-do-revert
779 :help
"Revert marked buffers to their associated file"))
780 (define-key-after operate-map
[do-rename-uniquely
]
781 '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely
782 :help
"Rename marked buffers to a new, unique name"))
783 (define-key-after operate-map
[do-delete
]
784 '(menu-item "Kill" ibuffer-do-delete
))
785 (define-key-after operate-map
[do-occur
]
786 '(menu-item "List lines matching..." ibuffer-do-occur
787 :help
"View all lines in marked buffers matching a regexp"))
788 (define-key-after operate-map
[do-shell-command-pipe
]
789 '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe
790 :help
"For each marked buffer, send its contents to a shell command"))
791 (define-key-after operate-map
[do-shell-command-pipe-replace
]
792 '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace
793 :help
"For each marked buffer, replace its contents with output of shell command"))
794 (define-key-after operate-map
[do-shell-command-file
]
795 '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file
796 :help
"For each marked buffer, run a shell command with its file as argument"))
797 (define-key-after operate-map
[do-eval
]
798 '(menu-item "Eval..." ibuffer-do-eval
799 :help
"Evaluate a Lisp form in each marked buffer"))
800 (define-key-after operate-map
[do-view-and-eval
]
801 '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval
802 :help
"Evaluate a Lisp form in each marked buffer while viewing it"))
804 (setq ibuffer-mode-map map
805 ibuffer-mode-operate-map operate-map
806 ibuffer-mode-groups-popup
(copy-keymap groups-map
))))
808 (define-key ibuffer-mode-groups-popup
[kill-filter-group
]
809 '(menu-item "Kill filter group"
811 :enable
(and (featurep 'ibuf-ext
)
812 ibuffer-filter-groups
)))
813 (define-key ibuffer-mode-groups-popup
[yank-filter-group
]
814 '(menu-item "Yank last killed filter group"
816 :enable
(and (featurep 'ibuf-ext
)
817 ibuffer-filter-group-kill-ring
)))
819 (defvar ibuffer-name-map
820 (let ((map (make-sparse-keymap)))
821 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
822 (define-key map
[(mouse-2)] 'ibuffer-mouse-visit-buffer
)
823 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
826 (defvar ibuffer-mode-name-map
827 (let ((map (make-sparse-keymap)))
828 (define-key map
[(mouse-2)] 'ibuffer-mouse-filter-by-mode
)
829 (define-key map
(kbd "RET") 'ibuffer-interactive-filter-by-mode
)
832 (defvar ibuffer-mode-filter-group-map
833 (let ((map (make-sparse-keymap)))
834 (define-key map
[(mouse-1)] 'ibuffer-mouse-toggle-mark
)
835 (define-key map
[(mouse-2)] 'ibuffer-mouse-toggle-filter-group
)
836 (define-key map
(kbd "RET") 'ibuffer-toggle-filter-group
)
837 (define-key map
[down-mouse-3
] 'ibuffer-mouse-popup-menu
)
840 (defvar ibuffer-restore-window-config-on-quit nil
841 "If non-nil, restore previous window configuration upon exiting `ibuffer'.")
843 (defvar ibuffer-prev-window-config nil
844 "Window configuration before starting Ibuffer.")
846 (defvar ibuffer-did-modification nil
)
848 (defvar ibuffer-compiled-formats nil
)
849 (defvar ibuffer-cached-formats nil
)
850 (defvar ibuffer-cached-eliding-string nil
)
851 (defvar ibuffer-cached-elide-long-columns
0)
853 (defvar ibuffer-sorting-functions-alist nil
854 "An alist of functions which describe how to sort buffers.
856 Note: You most likely do not want to modify this variable directly;
857 use `define-ibuffer-sorter' instead.
859 The alist elements are constructed like (NAME DESCRIPTION FUNCTION)
860 Where NAME is a symbol describing the sorting method, DESCRIPTION is a
861 short string which will be displayed in the minibuffer and menu, and
862 FUNCTION is a function of two arguments, which will be the buffers to
865 ;;; Utility functions
866 (defun ibuffer-columnize-and-insert-list (list &optional pad-width
)
867 "Insert LIST into the current buffer in as many columns as possible.
868 The maximum number of columns is determined by the current window
869 width and the longest string in LIST."
872 (let ((width (window-width))
873 (max (+ (apply #'max
(mapcar #'length list
))
875 (let ((columns (/ width max
)))
876 (when (zerop columns
)
879 (dotimes (i (1- columns
))
880 (insert (concat (car list
) (make-string (- max
(length (car list
)))
882 (setq list
(cdr list
)))
883 (when (not (null list
))
887 (defsubst ibuffer-current-mark
()
888 (cadr (get-text-property (line-beginning-position)
889 'ibuffer-properties
)))
891 (defun ibuffer-mouse-toggle-mark (event)
892 "Toggle the marked status of the buffer chosen with the mouse."
895 (let ((pt (save-excursion
896 (mouse-set-point event
)
898 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
899 (ibuffer-toggle-marks it
)
901 (let ((mark (ibuffer-current-mark)))
902 (setq buffer-read-only nil
)
903 (if (eq mark ibuffer-marked-char
)
904 (ibuffer-set-mark ?\s
)
905 (ibuffer-set-mark ibuffer-marked-char
)))))
906 (setq buffer-read-only t
)))
908 (defun ibuffer-find-file (file &optional wildcards
)
909 "Like `find-file', but default to the directory of the buffer at point."
911 (let ((default-directory (let ((buf (ibuffer-current-buffer)))
912 (if (buffer-live-p buf
)
913 (with-current-buffer buf
915 default-directory
))))
916 (list (read-file-name "Find file: " default-directory
)
918 (find-file file wildcards
))
920 (defun ibuffer-mouse-visit-buffer (event)
921 "Visit the buffer chosen with the mouse."
925 (mouse-set-point event
)
926 (ibuffer-current-buffer t
))))
928 (defun ibuffer-mouse-popup-menu (event)
929 "Display a menu of operations."
931 (let ((eventpt (posn-point (event-end event
)))
934 (if (get-text-property eventpt
'ibuffer-filter-group-name
)
937 (popup-menu ibuffer-mode-groups-popup
))
938 (let ((inhibit-read-only t
))
940 ;; hm. we could probably do this in a better fashion
941 (ibuffer-unmark-all ?
\r)
944 (ibuffer-set-mark ibuffer-marked-char
))
946 (popup-menu ibuffer-mode-operate-map
)))))
947 (setq buffer-read-only t
)
948 (if (= eventpt
(point))
949 (goto-char origpt
)))))
951 (defun ibuffer-skip-properties (props direction
)
952 (while (and (not (eobp))
954 (dolist (prop props hit
)
955 (when (get-text-property (point) prop
)
957 (forward-line direction
)
958 (beginning-of-line)))
960 (defun ibuffer-customize ()
961 "Begin customizing Ibuffer interactively."
963 (customize-group 'ibuffer
))
965 (defun ibuffer-backward-line (&optional arg skip-group-names
)
966 "Move backwards ARG lines, wrapping around the list if necessary."
968 (or arg
(setq arg
1))
972 (when (and ibuffer-movement-cycle
973 (or (get-text-property (point) 'ibuffer-title
)
974 (and skip-group-names
975 (get-text-property (point)
976 'ibuffer-filter-group-name
))))
977 (goto-char (point-max))
979 (ibuffer-skip-properties (append '(ibuffer-summary)
980 (when skip-group-names
981 '(ibuffer-filter-group-name)))
983 ;; Handle the special case of no buffers.
984 (when (get-text-property (point) 'ibuffer-title
)
989 (defun ibuffer-forward-line (&optional arg skip-group-names
)
990 "Move forward ARG lines, wrapping around the list if necessary."
992 (or arg
(setq arg
1))
994 (when (and ibuffer-movement-cycle
996 (get-text-property (point) 'ibuffer-summary
)))
997 (goto-char (point-min)))
998 (when (or (get-text-property (point) 'ibuffer-title
)
999 (and skip-group-names
1000 (get-text-property (point) 'ibuffer-filter-group-name
)))
1003 (ibuffer-skip-properties (append '(ibuffer-title)
1004 (when skip-group-names
1005 '(ibuffer-filter-group-name)))
1008 (ibuffer-backward-line (- arg
))
1011 (when (and ibuffer-movement-cycle
1013 (get-text-property (point) 'ibuffer-summary
)))
1014 (goto-char (point-min)))
1016 (ibuffer-skip-properties (append '(ibuffer-title)
1017 (when skip-group-names
1018 '(ibuffer-filter-group-name)))
1021 (defun ibuffer-visit-buffer (&optional single
)
1022 "Visit the buffer on this line.
1023 If optional argument SINGLE is non-nil, then also ensure there is only
1026 (let ((buf (ibuffer-current-buffer t
)))
1027 (bury-buffer (current-buffer))
1028 (switch-to-buffer buf
)
1030 (delete-other-windows))))
1032 (defun ibuffer-visit-buffer-other-window (&optional noselect
)
1033 "Visit the buffer on this line in another window."
1035 (let ((buf (ibuffer-current-buffer t
)))
1036 (bury-buffer (current-buffer))
1038 (let ((curwin (selected-window)))
1040 (select-window curwin
))
1041 (switch-to-buffer-other-window buf
))))
1043 (defun ibuffer-visit-buffer-other-window-noselect ()
1044 "Visit the buffer on this line in another window, but don't select it."
1046 (ibuffer-visit-buffer-other-window t
))
1048 (defun ibuffer-visit-buffer-other-frame ()
1049 "Visit the buffer on this line in another frame."
1051 (let ((buf (ibuffer-current-buffer t
)))
1052 (bury-buffer (current-buffer))
1053 (switch-to-buffer-other-frame buf
)))
1055 (defun ibuffer-visit-buffer-1-window ()
1056 "Visit the buffer on this line, and delete other windows."
1058 (ibuffer-visit-buffer t
))
1060 (defun ibuffer-bury-buffer ()
1061 "Bury the buffer on this line."
1063 (let ((buf (ibuffer-current-buffer t
))
1064 (line (+ 1 (count-lines 1 (point)))))
1066 (ibuffer-update nil t
)
1069 (defun ibuffer-visit-tags-table ()
1070 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
1072 (let ((file (buffer-file-name (ibuffer-current-buffer t
))))
1074 (visit-tags-table file
)
1075 (error "Specified buffer has no file"))))
1077 (defun ibuffer-do-view (&optional other-frame
)
1078 "View marked buffers, or the buffer on the current line.
1079 If optional argument OTHER-FRAME is non-nil, then display each
1080 marked buffer in a new frame. Otherwise, display each buffer as
1081 a new window in the current frame, splitting vertically."
1083 (ibuffer-do-view-1 (if other-frame
'other-frame
'vertically
)))
1085 (defun ibuffer-do-view-horizontally (&optional other-frame
)
1086 "As `ibuffer-do-view', but split windows horizontally."
1088 (ibuffer-do-view-1 (if other-frame
'other-frame
'horizontally
)))
1090 (defun ibuffer-do-view-1 (type)
1091 (let ((marked-bufs (ibuffer-get-marked-buffers)))
1092 (when (null marked-bufs
)
1093 (setq marked-bufs
(list (ibuffer-current-buffer t
))))
1094 (unless (and (eq type
'other-frame
)
1095 (not ibuffer-expert
)
1096 (> (length marked-bufs
) 3)
1097 (not (y-or-n-p (format "Really create a new frame for %s buffers? "
1098 (length marked-bufs
)))))
1099 (set-buffer-modified-p nil
)
1100 (delete-other-windows)
1101 (switch-to-buffer (pop marked-bufs
))
1102 (let ((height (/ (1- (if (eq type
'horizontally
) (frame-width)
1104 (1+ (length marked-bufs
)))))
1105 (mapcar (if (eq type
'other-frame
)
1107 (let ((curframe (selected-frame)))
1108 (select-frame (make-frame))
1109 (switch-to-buffer buf
)
1110 (select-frame curframe
)))
1112 (split-window nil height
(eq type
'horizontally
))
1114 (switch-to-buffer buf
)))
1117 (defun ibuffer-do-view-other-frame ()
1118 "View each of the marked buffers in a separate frame."
1120 (ibuffer-do-view t
))
1122 (defsubst ibuffer-map-marked-lines
(func)
1123 (prog1 (ibuffer-map-on-mark ibuffer-marked-char func
)
1124 (ibuffer-redisplay t
)))
1126 (defun ibuffer-shrink-to-fit (&optional owin
)
1127 (fit-window-to-buffer nil
(when owin
(/ (frame-height)
1128 (length (window-list (selected-frame)))))))
1130 (defun ibuffer-confirm-operation-on (operation names
)
1131 "Display a buffer asking whether to perform OPERATION on NAMES."
1133 (if (= (length names
) 1)
1134 (y-or-n-p (format "Really %s buffer %s? " operation
(car names
)))
1135 (let ((buf (get-buffer-create "*Ibuffer confirmation*")))
1136 (with-current-buffer buf
1137 (setq buffer-read-only nil
)
1139 (ibuffer-columnize-and-insert-list names
)
1140 (goto-char (point-min))
1141 (setq buffer-read-only t
))
1142 (let ((lastwin (car (last (window-list nil
'nomini
)))))
1143 ;; Now attempt to display the buffer...
1144 (save-window-excursion
1145 (select-window lastwin
)
1146 ;; The window might be too small to split; in that case,
1147 ;; try a few times to increase its size before giving up.
1157 (if (or (> (incf attempts
) 4)
1158 (and (stringp (cadr err
))
1159 ;; This definitely falls in the
1160 ;; ghetto hack category...
1161 (not (string-match "too small" (cadr err
)))))
1162 (apply #'signal err
)
1163 (enlarge-window 3))))))
1164 (select-window (next-window))
1165 (switch-to-buffer buf
)
1168 (fit-window-to-buffer)
1169 (y-or-n-p (format "Really %s %d buffers? "
1170 operation
(length names
))))
1171 (kill-buffer buf
))))))))
1173 (defsubst ibuffer-map-lines-nomodify
(function)
1174 "As `ibuffer-map-lines', but don't set the modification flag."
1175 (ibuffer-map-lines function t
))
1177 (defun ibuffer-buffer-names-with-mark (mark)
1178 (let ((ibuffer-buffer-names-with-mark-result nil
))
1179 (ibuffer-map-lines-nomodify
1181 (when (char-equal mark mk
)
1182 (push (buffer-name buf
)
1183 ibuffer-buffer-names-with-mark-result
))))
1184 ibuffer-buffer-names-with-mark-result
))
1186 (defsubst ibuffer-marked-buffer-names
()
1187 (ibuffer-buffer-names-with-mark ibuffer-marked-char
))
1189 (defsubst ibuffer-deletion-marked-buffer-names
()
1190 (ibuffer-buffer-names-with-mark ibuffer-deletion-char
))
1192 (defun ibuffer-count-marked-lines (&optional all
)
1194 (ibuffer-map-lines-nomodify
1195 #'(lambda (buf mark
)
1196 (not (char-equal mark ?\s
))))
1197 (ibuffer-map-lines-nomodify
1198 #'(lambda (buf mark
)
1199 (char-equal mark ibuffer-marked-char
)))))
1201 (defsubst ibuffer-count-deletion-lines
()
1202 (ibuffer-map-lines-nomodify
1203 #'(lambda (buf mark
)
1204 (char-equal mark ibuffer-deletion-char
))))
1206 (defsubst ibuffer-map-deletion-lines
(func)
1207 (ibuffer-map-on-mark ibuffer-deletion-char func
))
1209 (define-ibuffer-op ibuffer-do-save
()
1210 "Save marked buffers as with `save-buffer'."
1214 (when (buffer-modified-p buf
)
1215 (if (not (with-current-buffer buf
1217 ;; handle the case where we're prompted
1219 (save-window-excursion
1220 (switch-to-buffer buf
)
1222 (with-current-buffer buf
1226 (define-ibuffer-op ibuffer-do-toggle-modified
()
1227 "Toggle modification flag of marked buffers."
1228 (:opstring
"(un)marked as modified"
1230 (set-buffer-modified-p (not (buffer-modified-p))))
1232 (define-ibuffer-op ibuffer-do-toggle-read-only
()
1233 "Toggle read only status in marked buffers."
1234 (:opstring
"toggled read only status in"
1238 (define-ibuffer-op ibuffer-do-delete
()
1239 "Kill marked buffers as with `kill-this-buffer'."
1241 :active-opstring
"kill"
1245 (if (kill-buffer buf
)
1249 (define-ibuffer-op ibuffer-do-kill-on-deletion-marks
()
1250 "Kill buffers marked for deletion as with `kill-this-buffer'."
1252 :active-opstring
"kill"
1257 (if (kill-buffer buf
)
1261 (defun ibuffer-unmark-all (mark)
1262 "Unmark all buffers with mark MARK."
1263 (interactive "cRemove marks (RET means all):")
1264 (if (= (ibuffer-count-marked-lines t
) 0)
1265 (message "No buffers marked; use 'm' to mark a buffer")
1267 ((char-equal mark ibuffer-marked-char
)
1268 (ibuffer-map-marked-lines
1269 #'(lambda (buf mark
)
1270 (ibuffer-set-mark-1 ?\s
)
1272 ((char-equal mark ibuffer-deletion-char
)
1273 (ibuffer-map-deletion-lines
1274 #'(lambda (buf mark
)
1275 (ibuffer-set-mark-1 ?\s
)
1279 #'(lambda (buf mark
)
1280 (when (not (char-equal mark ?\s
))
1281 (ibuffer-set-mark-1 ?\s
))
1283 (ibuffer-redisplay t
))
1285 (defun ibuffer-toggle-marks (&optional group
)
1286 "Toggle which buffers are marked.
1287 In other words, unmarked buffers become marked, and marked buffers
1289 If point is on a group name, then this function operates on that
1292 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1296 #'(lambda (buf mark
)
1297 (cond ((eq mark ibuffer-marked-char
)
1298 (ibuffer-set-mark-1 ?\s
)
1301 (ibuffer-set-mark-1 ibuffer-marked-char
)
1306 (message "%s buffers marked" count
))
1307 (ibuffer-redisplay t
))
1309 (defun ibuffer-mark-forward (arg)
1310 "Mark the buffer on this line, and move forward ARG lines.
1311 If point is on a group name, this function operates on that group."
1313 (ibuffer-mark-interactive arg ibuffer-marked-char
1))
1315 (defun ibuffer-unmark-forward (arg)
1316 "Unmark the buffer on this line, and move forward ARG lines.
1317 If point is on a group name, this function operates on that group."
1319 (ibuffer-mark-interactive arg ?\s
1))
1321 (defun ibuffer-unmark-backward (arg)
1322 "Unmark the buffer on this line, and move backward ARG lines.
1323 If point is on a group name, this function operates on that group."
1325 (ibuffer-mark-interactive arg ?\s -
1))
1327 (defun ibuffer-mark-interactive (arg mark movement
)
1328 (assert (eq major-mode
'ibuffer-mode
))
1329 (or arg
(setq arg
1))
1330 (ibuffer-forward-line 0)
1331 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name
)
1334 (ibuffer-mark-on-buffer #'identity mark it
))
1335 (ibuffer-forward-line 0 t
)
1336 (let ((inhibit-read-only t
))
1338 (ibuffer-set-mark mark
)
1339 (ibuffer-forward-line movement t
)
1340 (setq arg
(1- arg
))))))
1342 (defun ibuffer-set-mark (mark)
1343 (assert (eq major-mode
'ibuffer-mode
))
1344 (let ((inhibit-read-only t
))
1345 (ibuffer-set-mark-1 mark
)
1346 (setq ibuffer-did-modification t
)
1347 (ibuffer-redisplay-current)
1348 (beginning-of-line)))
1350 (defun ibuffer-set-mark-1 (mark)
1351 (let ((beg (line-beginning-position))
1352 (end (line-end-position)))
1353 (put-text-property beg end
'ibuffer-properties
1354 (list (ibuffer-current-buffer)
1357 (defun ibuffer-mark-for-delete (arg)
1358 "Mark the buffers on ARG lines forward for deletion.
1359 If point is on a group name, this function operates on that group."
1361 (ibuffer-mark-interactive arg ibuffer-deletion-char
1))
1363 (defun ibuffer-mark-for-delete-backwards (arg)
1364 "Mark the buffers on ARG lines backward for deletion.
1365 If point is on a group name, this function operates on that group."
1367 (ibuffer-mark-interactive arg ibuffer-deletion-char -
1))
1369 (defun ibuffer-current-buffer (&optional must-be-live
)
1370 (let ((buf (car (get-text-property (line-beginning-position)
1371 'ibuffer-properties
))))
1374 (unless (buffer-live-p buf
)
1375 (error (substitute-command-keys "Buffer %s has been killed; use `\\[ibuffer-update]' to update") buf
))
1376 (error "No buffer on this line")))
1379 (defun ibuffer-active-formats-name ()
1380 (if (boundp 'ibuffer-filter-format-alist
)
1382 (dolist (filter ibuffer-filtering-qualifiers ret
)
1383 (let ((val (assq (car filter
) ibuffer-filter-format-alist
)))
1385 (setq ret
(car filter
)))))
1391 (defun ibuffer-current-formats (uncompiledp)
1392 (let* ((name (ibuffer-active-formats-name)))
1393 (ibuffer-check-formats)
1394 (if (eq name
:ibuffer-formats
)
1397 ibuffer-compiled-formats
)
1400 ibuffer-filter-format-alist
1401 ibuffer-compiled-filter-formats
))))))
1403 (defun ibuffer-current-format (&optional uncompiledp
)
1404 (or ibuffer-current-format
1405 (setq ibuffer-current-format
0))
1406 (nth ibuffer-current-format
(ibuffer-current-formats uncompiledp
)))
1408 (defun ibuffer-expand-format-entry (form)
1409 (if (or (consp form
)
1411 (let ((sym (intern (concat "ibuffer-make-column-"
1412 (symbol-name (if (consp form
)
1415 (unless (or (fboundp sym
)
1416 (assq sym ibuffer-inline-columns
))
1417 (error "Unknown column %s in ibuffer-formats" form
))
1418 (let (min max align elide
)
1420 (setq min
(or (nth 1 form
) 0)
1421 max
(or (nth 2 form
) -
1)
1422 align
(or (nth 3 form
) :left
)
1423 elide
(or (nth 4 form
) nil
))
1428 (list sym min max align elide
)))
1431 (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p
)
1432 (let ((ellipsis (propertize ibuffer-eliding-string
'font-lock-face
'bold
)))
1433 (if (or elide
(with-no-warnings ibuffer-elide-long-columns
))
1438 (length ibuffer-eliding-string
)))
1440 (substring ,strvar
0 (- strlen
,(length ellipsis
)))
1445 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p
)
1449 `(substring ,strvar
0 ,maxvar
)))
1451 (defun ibuffer-compile-make-format-form (strvar widthform alignment
)
1452 (let* ((left `(make-string tmp2 ?\s
))
1453 (right `(make-string (- tmp1 tmp2
) ?\s
)))
1455 (setq tmp1
,widthform
1458 (:right
`(concat ,left
,right
,strvar
))
1459 (:center
`(concat ,left
,strvar
,right
))
1460 (:left
`(concat ,strvar
,left
,right
))
1461 (t (error "Invalid alignment %s" alignment
))))))
1463 (defun ibuffer-compile-format (format)
1465 ;; We use these variables to keep track of which variables
1466 ;; inside the generated function we need to bind, since
1467 ;; binding variables in Emacs takes time.
1468 str-used tmp1-used tmp2-used global-strlen-used
)
1469 (dolist (form format
)
1471 ;; Generate a form based on a particular format entry, like
1472 ;; " ", mark, or (mode 16 16 :right).
1474 ;; It's a string; all we need to do is insert it.
1476 (let* ((form (ibuffer-expand-format-entry form
))
1480 (align (nth 3 form
))
1481 (elide (nth 4 form
)))
1482 (let* ((from-end-p (when (minusp min
)
1489 min-used max-used strlen-used
)
1490 (when (or (not (integerp min
)) (>= min
0))
1491 ;; This is a complex case; they want it limited to a
1494 (setq str-used t strlen-used t global-strlen-used t
1495 tmp1-used t tmp2-used t
)
1496 ;; Generate code to limit the string to a minimum size.
1497 (setq minform
`(progn
1499 ,(ibuffer-compile-make-format-form
1501 `(- ,(if (integerp min
)
1506 (when (or (not (integerp max
)) (> max
0))
1507 (setq str-used t max-used t
)
1508 ;; Generate code to limit the string to a maximum size.
1509 (setq maxform
`(progn
1511 ,(ibuffer-compile-make-substring-form
1517 (setq strlen
(length str
))
1519 ,(ibuffer-compile-make-eliding-form 'str
1522 ;; Now, put these forms together with the rest of the code.
1524 ;; Is this an "inline" column? This means we have
1525 ;; to get the code from the
1526 ;; `ibuffer-inline-columns' alist and insert it
1527 ;; into our generated code. Otherwise, we just
1528 ;; generate a call to the column function.
1529 (ibuffer-aif (assq sym ibuffer-inline-columns
)
1531 `(,sym buffer mark
)))
1532 ;; You're not expected to understand this. Hell, I
1533 ;; don't even understand it, and I wrote it five
1535 (insertgenfn (ibuffer-aif (get sym
'ibuffer-column-summarizer
)
1536 ;; I really, really wish Emacs Lisp had closures.
1540 (put ',sym
'ibuffer-column-summary
1541 (cons ret
(get ',sym
'ibuffer-column-summary
)))
1545 (mincompform `(< strlen
,(if (integerp min
)
1548 (maxcompform `(> strlen
,(if (integerp max
)
1551 (if (or min-used max-used
)
1552 ;; The complex case, where we have to limit the
1553 ;; form to a maximum or minimum size.
1555 (when (and min-used
(not (integerp min
)))
1556 (push `(min ,min
) letbindings
))
1557 (when (and max-used
(not (integerp max
)))
1558 (push `(max ,max
) letbindings
))
1560 (if (and min-used max-used
)
1572 `(setq str
,callform
)
1574 `(strlen (length str
))))
1577 (append outforms
(list (funcall insertgenfn
'str sym
)))))
1578 ;; The simple case; just insert the string.
1579 (push (funcall insertgenfn callform sym
) outforms
))
1580 ;; Finally, return a `let' form which binds the
1581 ;; variables in `letbindings', and contains all the
1582 ;; code in `outforms'.
1587 ;; We don't want to unconditionally load the byte-compiler.
1588 (funcall (if (or ibuffer-always-compile-formats
1589 (featurep 'bytecomp
))
1592 ;; Here, we actually create a lambda form which
1593 ;; inserts all the generated forms for each entry
1594 ;; in the format string.
1595 (nconc (list 'lambda
'(buffer mark
))
1596 `((let ,(append (when str-used
1598 (when global-strlen-used
1604 ,@(nreverse result
))))))))
1606 (defun ibuffer-recompile-formats ()
1607 "Recompile `ibuffer-formats'."
1609 (setq ibuffer-compiled-formats
1610 (mapcar #'ibuffer-compile-format ibuffer-formats
))
1611 (when (boundp 'ibuffer-filter-format-alist
)
1612 (setq ibuffer-compiled-filter-formats
1613 (mapcar #'(lambda (entry)
1615 (mapcar #'(lambda (formats)
1616 (mapcar #'ibuffer-compile-format formats
))
1618 ibuffer-filter-format-alist
))))
1620 (defun ibuffer-clear-summary-columns (format)
1621 (dolist (form format
)
1622 (ibuffer-awhen (and (consp form
)
1623 (get (car form
) 'ibuffer-column-summarizer
))
1624 (put (car form
) 'ibuffer-column-summary nil
))))
1626 (defun ibuffer-check-formats ()
1627 (when (null ibuffer-formats
)
1628 (error "No formats!"))
1629 (let ((ext-loaded (featurep 'ibuf-ext
)))
1630 (when (or (null ibuffer-compiled-formats
)
1631 (null ibuffer-cached-formats
)
1632 (not (eq ibuffer-cached-formats ibuffer-formats
))
1633 (null ibuffer-cached-eliding-string
)
1634 (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string
))
1635 (eql 0 ibuffer-cached-elide-long-columns
)
1636 (not (eql ibuffer-cached-elide-long-columns
1637 (with-no-warnings ibuffer-elide-long-columns
)))
1639 (not (eq ibuffer-cached-filter-formats
1640 ibuffer-filter-format-alist
))
1641 (and ibuffer-filter-format-alist
1642 (null ibuffer-compiled-filter-formats
))))
1643 (message "Formats have changed, recompiling...")
1644 (ibuffer-recompile-formats)
1645 (setq ibuffer-cached-formats ibuffer-formats
1646 ibuffer-cached-eliding-string ibuffer-eliding-string
1647 ibuffer-cached-elide-long-columns
(with-no-warnings ibuffer-elide-long-columns
))
1649 (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist
))
1650 (message "Formats have changed, recompiling...done"))))
1652 (defvar ibuffer-inline-columns nil
)
1654 (define-ibuffer-column mark
(:name
" " :inline t
)
1657 (define-ibuffer-column read-only
(:name
"R" :inline t
)
1658 (if buffer-read-only
1659 (string ibuffer-read-only-char
)
1662 (define-ibuffer-column modified
(:name
"M" :inline t
)
1663 (if (buffer-modified-p)
1664 (string ibuffer-modified-char
)
1667 (define-ibuffer-column name
1670 ('mouse-face
'highlight
'keymap ibuffer-name-map
1671 'ibuffer-name-column t
1672 'help-echo
'(if tooltip-mode
1673 "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"
1674 "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate"))
1677 (let ((bufs (length strings
)))
1678 (cond ((zerop bufs
) "No buffers")
1679 ((= 1 bufs
) "1 buffer")
1680 (t (format "%s buffers" bufs
))))))
1681 (propertize (buffer-name) 'font-lock-face
(ibuffer-buffer-name-face buffer mark
)))
1683 (define-ibuffer-column size
1686 (lambda (column-strings)
1688 (dolist (string column-strings
)
1691 (+ (float (string-to-number string
))
1693 (format "%.0f" total
))))
1694 (format "%s" (buffer-size)))
1696 (define-ibuffer-column mode
1699 ('mouse-face
'highlight
1700 'keymap ibuffer-mode-name-map
1701 'help-echo
"mouse-2: filter by this mode"))
1702 (format "%s" mode-name
))
1704 (define-ibuffer-column process
1707 (let ((total (length (delete "" strings
))))
1708 (cond ((zerop total
) "No processes")
1709 ((= 1 total
) "1 process")
1710 (t (format "%d processes" total
))))))
1711 (ibuffer-aif (get-buffer-process buffer
)
1712 (format "(%s %s)" it
(process-status it
))
1715 (define-ibuffer-column filename
1718 (let ((total (length (delete "" strings
))))
1719 (cond ((zerop total
) "No files")
1720 ((= 1 total
) "1 file")
1721 (t (format "%d files" total
))))))
1722 (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist
))
1723 (abbreviate-file-name
1724 (or buffer-file-name
1725 (and (boundp 'dired-directory
)
1726 (if (stringp dired-directory
)
1728 (car dired-directory
)))
1731 (define-ibuffer-column filename-and-process
1732 (:name
"Filename/Process"
1735 (setq strings
(delete "" strings
))
1738 (dolist (string strings
)
1739 (if (string-match "\\(\?:\\`(\[\[:ascii:\]\]\+)\\)" string
)
1740 (progn (setq procs
(1+ procs
))
1741 (if (< (match-end 0) (length string
))
1742 (setq files
(1+ files
))))
1743 (setq files
(1+ files
))))
1744 (concat (cond ((zerop files
) "No files")
1745 ((= 1 files
) "1 file")
1746 (t (format "%d files" files
)))
1748 (cond ((zerop procs
) "no processes")
1749 ((= 1 procs
) "1 process")
1750 (t (format "%d processes" procs
)))))))
1751 (let ((proc (get-buffer-process buffer
))
1752 (filename (ibuffer-make-column-filename buffer mark
)))
1754 (concat (propertize (format "(%s %s)" proc
(process-status proc
))
1755 'font-lock-face
'italic
)
1756 (if (> (length filename
) 0)
1757 (format " %s" filename
)
1761 (defun ibuffer-format-column (str width alignment
)
1762 (let ((left (make-string (/ width
2) ?\s
))
1763 (right (make-string (- width
(/ width
2)) ?\s
)))
1765 (:right
(concat left right str
))
1766 (:center
(concat left str right
))
1767 (t (concat str left right
)))))
1769 (defun ibuffer-buffer-name-face (buf mark
)
1770 (cond ((char-equal mark ibuffer-marked-char
)
1771 ibuffer-marked-face
)
1772 ((char-equal mark ibuffer-deletion-char
)
1773 ibuffer-deletion-face
)
1777 (dolist (e ibuffer-fontification-alist result
)
1778 (when (and (> (car e
) level
)
1779 (with-current-buffer buf
1782 result
(nth 2 e
))))))))
1784 (defun ibuffer-insert-buffer-line (buffer mark format
)
1785 "Insert a line describing BUFFER and MARK using FORMAT."
1786 (assert (eq major-mode
'ibuffer-mode
))
1787 (let ((beg (point)))
1788 (funcall format buffer mark
)
1789 (put-text-property beg
(point) 'ibuffer-properties
(list buffer mark
)))
1792 ;; This function knows a bit too much of the internals. It would be
1793 ;; nice if it was all abstracted away.
1794 (defun ibuffer-redisplay-current ()
1795 (assert (eq major-mode
'ibuffer-mode
))
1799 (let ((curformat (mapcar #'ibuffer-expand-format-entry
1800 (ibuffer-current-format t
))))
1801 (ibuffer-clear-summary-columns curformat
)
1802 (let ((buf (ibuffer-current-buffer)))
1804 (let ((mark (ibuffer-current-mark)))
1806 (delete-region (point) (1+ (line-end-position)))
1807 (ibuffer-insert-buffer-line
1809 (ibuffer-current-format)))
1810 (when ibuffer-shrink-to-minimum-size
1811 (ibuffer-shrink-to-fit)))))))
1813 (defun ibuffer-map-on-mark (mark func
)
1816 (if (char-equal mark mk
)
1817 (funcall func buf mark
)
1820 (defun ibuffer-map-lines (function &optional nomodify group
)
1821 "Call FUNCTION for each buffer.
1822 Don't set the ibuffer modification flag iff NOMODIFY is non-nil.
1824 If optional argument GROUP is non-nil, then only call FUNCTION on
1825 buffers in filtering group GROUP.
1827 FUNCTION is called with two arguments:
1828 the buffer object itself and the current mark symbol."
1829 (assert (eq major-mode
'ibuffer-mode
))
1830 (ibuffer-forward-line 0)
1831 (let* ((orig-target-line (1+ (count-lines (save-excursion
1832 (goto-char (point-min))
1833 (ibuffer-forward-line 0)
1836 (target-line-offset orig-target-line
)
1837 (ibuffer-map-lines-total 0)
1838 (ibuffer-map-lines-count 0))
1841 (setq buffer-read-only nil
)
1842 (goto-char (point-min))
1843 (ibuffer-forward-line 0 t
)
1844 (while (and (not (eobp))
1845 (not (get-text-property (point) 'ibuffer-summary
))
1847 (ibuffer-forward-line 0 t
)
1849 (not (get-text-property (point) 'ibuffer-summary
)))))
1851 (if (buffer-live-p (ibuffer-current-buffer))
1852 (when (or (null group
)
1853 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group
)
1857 (ibuffer-current-buffer)
1858 (ibuffer-current-mark))))
1859 ;; Kill the line if the buffer is dead
1861 ;; A given mapping function should return:
1862 ;; `nil' if it chose not to affect the buffer
1863 ;; `kill' means the remove line from the buffer list
1865 (incf ibuffer-map-lines-total
)
1866 (cond ((null result
)
1869 (delete-region (line-beginning-position)
1870 (1+ (line-end-position)))
1871 (incf ibuffer-map-lines-count
)
1872 (when (< ibuffer-map-lines-total
1874 (decf target-line-offset
)))
1876 (incf ibuffer-map-lines-count
)
1877 (forward-line 1)))))
1878 ibuffer-map-lines-count
)
1880 (setq buffer-read-only t
)
1882 (set-buffer-modified-p nil
))
1883 (goto-char (point-min))
1884 (ibuffer-forward-line 0)
1885 (ibuffer-forward-line (1- target-line-offset
))))))
1887 (defun ibuffer-get-marked-buffers ()
1888 "Return a list of buffer objects currently marked."
1890 (mapcar #'(lambda (e)
1891 (when (eq (cdr e
) ibuffer-marked-char
)
1893 (ibuffer-current-state-list))))
1895 (defun ibuffer-current-state-list (&optional pos
)
1896 "Return a list like (BUF . MARK) of all buffers in an ibuffer.
1897 If POS is non-nil, return a list like (BUF MARK POINT), where POINT is
1898 the value of point at the beginning of the line for that buffer."
1899 (let ((ibuffer-current-state-list-tmp '()))
1900 ;; ah, if only we had closures. I bet this will mysteriously
1901 ;; break later. Don't blame me.
1903 (ibuffer-map-lines-nomodify
1904 #'(lambda (buf mark
)
1905 (when (buffer-live-p buf
)
1906 (push (list buf mark
(point)) ibuffer-current-state-list-tmp
))))
1907 (ibuffer-map-lines-nomodify
1908 #'(lambda (buf mark
)
1909 (when (buffer-live-p buf
)
1910 (push (cons buf mark
) ibuffer-current-state-list-tmp
)))))
1911 (nreverse ibuffer-current-state-list-tmp
)))
1913 (defun ibuffer-current-buffers-with-marks (curbufs)
1914 "Return a list like (BUF . MARK) of all open buffers."
1915 (let ((bufs (ibuffer-current-state-list)))
1916 (mapcar #'(lambda (buf) (let ((e (assq buf bufs
)))
1922 (defun ibuffer-buf-matches-predicates (buf predicates
)
1924 (name (buffer-name buf
)))
1925 (dolist (pred predicates
)
1926 (when (if (stringp pred
)
1927 (string-match pred name
)
1932 (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all
)
1933 (let ((ext-loaded (featurep 'ibuf-ext
)))
1936 ;; element should be like (BUFFER . MARK)
1938 (let* ((buf (car e
)))
1940 ;; This takes precedence over anything else
1941 (or (and ibuffer-always-show-last-buffer
1943 (funcall (if ext-loaded
1944 #'ibuffer-ext-visible-p
1945 #'ibuffer-visible-p
)
1946 buf all ibuffer-buf
))
1950 (defun ibuffer-visible-p (buf all
&optional ibuffer-buf
)
1953 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates
)))
1954 (or ibuffer-view-ibuffer
1956 (not (eq ibuffer-buf buf
))))))
1958 ;; This function is a special case; it's not defined by
1959 ;; `ibuffer-define-sorter'.
1960 (defun ibuffer-do-sort-by-recency ()
1961 "Sort the buffers by last view time."
1963 (setq ibuffer-sorting-mode
'recency
)
1964 (ibuffer-redisplay t
))
1966 (defun ibuffer-update-format ()
1967 (when (null ibuffer-current-format
)
1968 (setq ibuffer-current-format
0))
1969 (when (null ibuffer-formats
)
1970 (error "Ibuffer error: no formats!")))
1972 (defun ibuffer-switch-format ()
1973 "Switch the current display format."
1975 (assert (eq major-mode
'ibuffer-mode
))
1976 (unless (consp ibuffer-formats
)
1977 (error "Ibuffer error: No formats!"))
1978 (setq ibuffer-current-format
1979 (if (>= ibuffer-current-format
(1- (length (ibuffer-current-formats nil
))))
1981 (1+ ibuffer-current-format
)))
1982 (ibuffer-update-format)
1983 (ibuffer-redisplay t
))
1985 (defun ibuffer-update-title-and-summary (format)
1986 (assert (eq major-mode
'ibuffer-mode
))
1987 ;; Don't do funky font-lock stuff here
1988 (let ((after-change-functions nil
))
1989 (if (get-text-property (point-min) 'ibuffer-title
)
1990 (delete-region (point-min)
1991 (next-single-property-change
1992 (point-min) 'ibuffer-title
)))
1993 (goto-char (point-min))
1994 (add-text-properties
1997 (let ((opos (point)))
1998 ;; Insert the title names.
1999 (dolist (element format
)
2001 (if (stringp element
)
2003 (let ((sym (car element
))
2004 (min (cadr element
))
2005 ;; (max (caddr element))
2006 (align (cadddr element
)))
2007 ;; Ignore a negative min when we're inserting the title
2010 (let* ((name (or (get sym
'ibuffer-column-name
)
2011 (error "Unknown column %s in ibuffer-formats" sym
)))
2012 (len (length name
)))
2014 (ibuffer-format-column name
2018 (add-text-properties opos
(point) `(ibuffer-title-header t
))
2020 ;; Add the underlines
2021 (let ((str (save-excursion
2024 (buffer-substring (point) (line-end-position)))))
2025 (apply #'insert
(mapcar
2027 (if (not (or (char-equal c ?\s
)
2028 (char-equal c ?
\n)))
2034 `(ibuffer-title t font-lock-face
,ibuffer-title-face
))
2035 ;; Now, insert the summary columns.
2036 (goto-char (point-max))
2037 (if (get-text-property (1- (point-max)) 'ibuffer-summary
)
2038 (delete-region (previous-single-property-change
2039 (point-max) 'ibuffer-summary
)
2041 (if ibuffer-display-summary
2042 (add-text-properties
2046 (dolist (element format
)
2048 (if (stringp element
)
2049 (make-string (length element
) ?\s
)
2050 (let ((sym (car element
)))
2051 (let ((min (cadr element
))
2052 ;; (max (caddr element))
2053 (align (cadddr element
)))
2054 ;; Ignore a negative min when we're inserting the title
2057 (let* ((summary (if (get sym
'ibuffer-column-summarizer
)
2058 (funcall (get sym
'ibuffer-column-summarizer
)
2059 (get sym
'ibuffer-column-summary
))
2060 (make-string (length (get sym
'ibuffer-column-name
))
2062 (len (length summary
)))
2064 (ibuffer-format-column summary
2069 `(ibuffer-summary t
)))))
2071 (defun ibuffer-update-mode-name ()
2072 (setq mode-name
(format "Ibuffer by %s" (if ibuffer-sorting-mode
2073 ibuffer-sorting-mode
2075 (when ibuffer-sorting-reversep
2076 (setq mode-name
(concat mode-name
" [rev]")))
2077 (when (and (featurep 'ibuf-ext
)
2079 (setq mode-name
(concat mode-name
" (Auto)")))
2081 (when (featurep 'ibuf-ext
)
2082 (dolist (qualifier ibuffer-filtering-qualifiers
)
2084 (concat result
(ibuffer-format-qualifier qualifier
))))
2085 (if ibuffer-use-header-line
2086 (setq header-line-format
2087 (when ibuffer-filtering-qualifiers
2088 (replace-regexp-in-string "%" "%%"
2089 (concat mode-name result
))))
2091 (setq mode-name
(concat mode-name result
))
2092 (when (boundp 'header-line-format
)
2093 (setq header-line-format nil
)))))))
2095 (defun ibuffer-redisplay (&optional silent
)
2096 "Redisplay the current list of buffers.
2097 This does not show new buffers; use `ibuffer-update' for that.
2099 If optional arg SILENT is non-nil, do not display progress messages."
2101 (ibuffer-forward-line 0)
2103 (message "Redisplaying current buffer list..."))
2104 (let ((blist (ibuffer-current-state-list)))
2106 (if (and (featurep 'ibuf-ext
)
2107 (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups
))
2108 (message "No buffers! (note: filtering in effect)")
2109 (error "No buffers!")))
2110 (ibuffer-redisplay-engine blist t
)
2111 (ibuffer-update-mode-name)
2113 (message "Redisplaying current buffer list...done"))
2114 (ibuffer-forward-line 0)))
2116 (defun ibuffer-update (arg &optional silent
)
2117 "Regenerate the list of all buffers.
2119 Prefix arg non-nil means to toggle whether buffers that match
2120 `ibuffer-maybe-show-predicates' should be displayed.
2122 If optional arg SILENT is non-nil, do not display progress messages."
2125 (setq ibuffer-display-maybe-show-predicates
2126 (not ibuffer-display-maybe-show-predicates
)))
2127 (ibuffer-forward-line 0)
2128 (let* ((bufs (buffer-list))
2129 (blist (ibuffer-filter-buffers
2133 (eq ibuffer-always-show-last-buffer
2135 (minibufferp (cadr bufs
)))
2138 (ibuffer-current-buffers-with-marks bufs
)
2139 ibuffer-display-maybe-show-predicates
)))
2141 (if (and (featurep 'ibuf-ext
)
2142 ibuffer-filtering-qualifiers
)
2143 (message "No buffers! (note: filtering in effect)")
2144 (error "No buffers!")))
2146 (message "Updating buffer list..."))
2147 (ibuffer-redisplay-engine blist arg
)
2148 (ibuffer-update-mode-name)
2150 (message "Updating buffer list...done")))
2151 (if (eq ibuffer-shrink-to-minimum-size
'onewindow
)
2152 (ibuffer-shrink-to-fit t
)
2153 (when ibuffer-shrink-to-minimum-size
2154 (ibuffer-shrink-to-fit)))
2155 (ibuffer-forward-line 0))
2157 (defun ibuffer-sort-bufferlist (bmarklist)
2158 (let* ((sortdat (assq ibuffer-sorting-mode
2159 ibuffer-sorting-functions-alist
))
2160 (func (caddr sortdat
)))
2162 ;; actually sort the buffers
2163 (if (and sortdat func
)
2164 (sort bmarklist func
)
2166 ;; perhaps reverse the sorted buffer list
2167 (if ibuffer-sorting-reversep
2171 (defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist
)
2172 (add-text-properties
2175 (insert "[ " display-name
" ]")
2177 `(ibuffer-filter-group-name
2179 font-lock-face
,ibuffer-filter-group-name-face
2180 keymap
,ibuffer-mode-filter-group-map
2181 mouse-face highlight
2182 help-echo
,(let ((echo '(if tooltip-mode
2183 "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group"
2184 "mouse-1: toggle marks mouse-2: hide/show")))
2185 (if (> (length filter-string
) 0)
2186 `(concat ,filter-string
2187 (if tooltip-mode
"\n" " ")
2195 (dolist (entry bmarklist
)
2196 (ibuffer-insert-buffer-line (car entry
) (cdr entry
) format
))
2198 'ibuffer-filter-group
2201 (defun ibuffer-redisplay-engine (bmarklist &optional ignore
)
2202 (assert (eq major-mode
'ibuffer-mode
))
2203 (let* ((--ibuffer-insert-buffers-and-marks-format
2204 (ibuffer-current-format))
2205 (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry
2206 (ibuffer-current-format t
)))
2207 (orig (count-lines (point-min) (point)))
2208 ;; Inhibit font-lock caching tricks, since we're modifying the
2209 ;; entire buffer at once
2210 (after-change-functions nil
)
2211 (ext-loaded (featurep 'ibuf-ext
))
2212 (bgroups (if ext-loaded
2213 (ibuffer-generate-filter-groups bmarklist
)
2214 (list (cons "Default" bmarklist
)))))
2215 (ibuffer-clear-summary-columns --ibuffer-expanded-format
)
2218 (setq buffer-read-only nil
)
2220 (ibuffer-update-format)
2221 (dolist (group (nreverse bgroups
))
2222 (let* ((name (car group
))
2223 (disabled (and ext-loaded
2224 (member name ibuffer-hidden-filter-groups
)))
2225 (bmarklist (cdr group
)))
2226 (unless (and (null bmarklist
)
2229 (null ibuffer-show-empty-filter-groups
))
2230 (ibuffer-insert-filter-group
2232 (if disabled
(concat name
" ...") name
)
2234 (ibuffer-format-filter-group-data name
)
2236 --ibuffer-insert-buffers-and-marks-format
2239 (ibuffer-sort-bufferlist bmarklist
))))))
2240 (ibuffer-update-title-and-summary --ibuffer-expanded-format
))
2241 (setq buffer-read-only t
)
2242 (set-buffer-modified-p ibuffer-did-modification
)
2243 (setq ibuffer-did-modification nil
)
2244 (goto-line (1+ orig
)))))
2246 (defun ibuffer-quit ()
2247 "Quit this `ibuffer' session.
2248 Try to restore the previous window configuration iff
2249 `ibuffer-restore-window-config-on-quit' is non-nil."
2251 (if ibuffer-restore-window-config-on-quit
2254 (unless (= (count-windows) 1)
2255 (set-window-configuration ibuffer-prev-window-config
)))
2259 (defun ibuffer-list-buffers (&optional files-only
)
2260 "Display a list of buffers, in another window.
2261 If optional argument FILES-ONLY is non-nil, then add a filter for
2262 buffers which are visiting a file."
2264 (ibuffer t nil
(when files-only
2265 '((filename .
".*"))) t
))
2268 (defun ibuffer-other-window (&optional files-only
)
2269 "Like `ibuffer', but displayed in another window by default.
2270 If optional argument FILES-ONLY is non-nil, then add a filter for
2271 buffers which are visiting a file."
2273 (ibuffer t nil
(when files-only
2274 '((filename .
".*")))))
2277 (defun ibuffer (&optional other-window-p name qualifiers noselect
2278 shrink filter-groups formats
)
2279 "Begin using Ibuffer to edit a list of buffers.
2280 Type 'h' after entering ibuffer for more information.
2282 All arguments are optional.
2283 OTHER-WINDOW-P says to use another window.
2284 NAME specifies the name of the buffer (defaults to \"*Ibuffer*\").
2285 QUALIFIERS is an initial set of filtering qualifiers to use;
2286 see `ibuffer-filtering-qualifiers'.
2287 NOSELECT means don't select the Ibuffer buffer.
2288 SHRINK means shrink the buffer to minimal size. The special
2289 value `onewindow' means always use another window.
2290 FILTER-GROUPS is an initial set of filtering groups to use;
2291 see `ibuffer-filter-groups'.
2292 FORMATS is the value to use for `ibuffer-formats'.
2293 If specified, then the variable `ibuffer-formats' will have
2294 that value locally in this buffer."
2296 (when ibuffer-use-other-window
2297 (setq other-window-p t
))
2298 (setq ibuffer-prev-window-config
(current-window-configuration))
2299 (let ((buf (get-buffer-create (or name
"*Ibuffer*"))))
2301 (funcall (if noselect
#'(lambda (buf) (display-buffer buf t
)) #'pop-to-buffer
) buf
)
2302 (funcall (if noselect
#'display-buffer
#'switch-to-buffer
) buf
))
2303 (with-current-buffer buf
2304 (save-selected-window
2305 ;; We switch to the buffer's window in order to be able
2306 ;; to modify the value of point
2307 (select-window (get-buffer-window buf
0))
2308 (or (eq major-mode
'ibuffer-mode
)
2310 (setq ibuffer-restore-window-config-on-quit other-window-p
)
2312 (setq ibuffer-shrink-to-minimum-size shrink
))
2315 (setq ibuffer-filtering-qualifiers qualifiers
))
2318 (setq ibuffer-filter-groups filter-groups
))
2320 (set (make-local-variable 'ibuffer-formats
) formats
))
2321 (ibuffer-update nil
)
2322 ;; Skip the group name by default.
2323 (ibuffer-forward-line 0 t
)
2326 (setq buffer-read-only nil
)
2327 (run-hooks 'ibuffer-hook
))
2328 (setq buffer-read-only t
))
2329 (unless ibuffer-expert
2330 (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))))))
2332 (put 'ibuffer-mode
'mode-class
'special
)
2333 (defun ibuffer-mode ()
2334 "A major mode for viewing a list of buffers.
2335 In Ibuffer, you can conveniently perform many operations on the
2336 currently open buffers, in addition to filtering your view to a
2337 particular subset of them, and sorting by various criteria.
2339 Operations on marked buffers:
2341 '\\[ibuffer-do-save]' - Save the marked buffers
2342 '\\[ibuffer-do-view]' - View the marked buffers in this frame.
2343 '\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame.
2344 '\\[ibuffer-do-revert]' - Revert the marked buffers.
2345 '\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers.
2346 '\\[ibuffer-do-delete]' - Kill the marked buffers.
2347 '\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked
2349 '\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers.
2350 '\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression.
2351 '\\[ibuffer-do-print]' - Print the marked buffers.
2352 '\\[ibuffer-do-occur]' - List lines in all marked buffers which match
2353 a given regexp (like the function `occur').
2354 '\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked
2355 buffers to a shell command.
2356 '\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked
2357 buffers with the output of a shell command.
2358 '\\[ibuffer-do-shell-command-file]' - Run a shell command with the
2359 buffer's file as an argument.
2360 '\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This
2361 is a very flexible command. For example, if you want to make all
2362 of the marked buffers read only, try using (toggle-read-only 1) as
2364 '\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form
2366 '\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer,
2367 but don't kill the associated buffer.
2368 '\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion.
2372 '\\[ibuffer-mark-forward]' - Mark the buffer at point.
2373 '\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark
2374 all unmarked buffers.
2375 '\\[ibuffer-unmark-forward]' - Unmark the buffer at point.
2376 '\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the
2378 '\\[ibuffer-unmark-all]' - Unmark all marked buffers.
2379 '\\[ibuffer-mark-by-mode]' - Mark buffers by major mode.
2380 '\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers.
2381 This means that the buffer is modified, and has an associated file.
2382 '\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers,
2383 regardless of whether or not they have an associated file.
2384 '\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and
2386 '\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have
2387 an associated file, but that file doesn't currently exist.
2388 '\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers.
2389 '\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode.
2390 '\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc.
2391 '\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'.
2392 '\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion.
2393 '\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp.
2394 '\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp.
2395 '\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp.
2399 '\\[ibuffer-filter-by-mode]' - Add a filter by major mode.
2400 '\\[ibuffer-filter-by-used-mode]' - Add a filter by major mode now in use.
2401 '\\[ibuffer-filter-by-name]' - Add a filter by buffer name.
2402 '\\[ibuffer-filter-by-content]' - Add a filter by buffer content.
2403 '\\[ibuffer-filter-by-filename]' - Add a filter by filename.
2404 '\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size.
2405 '\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size.
2406 '\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate.
2407 '\\[ibuffer-save-filters]' - Save the current filters with a name.
2408 '\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters.
2409 '\\[ibuffer-add-saved-filters]' - Add saved filters to current filters.
2410 '\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR.
2411 '\\[ibuffer-pop-filter]' - Remove the top filter.
2412 '\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter.
2413 '\\[ibuffer-decompose-filter]' - Break down the topmost filter.
2414 '\\[ibuffer-filter-disable]' - Remove all filtering currently in effect.
2416 Filter group commands:
2418 '\\[ibuffer-filters-to-filter-group]' - Create filter group from filters.
2419 '\\[ibuffer-pop-filter-group]' - Remove top filter group.
2420 '\\[ibuffer-forward-filter-group]' - Move to the next filter group.
2421 '\\[ibuffer-backward-filter-group]' - Move to the previous filter group.
2422 '\\[ibuffer-clear-filter-groups]' - Remove all active filter groups.
2423 '\\[ibuffer-save-filter-groups]' - Save the current groups with a name.
2424 '\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups.
2425 '\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups.
2429 '\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes.
2430 '\\[ibuffer-invert-sorting]' - Reverse the current sorting order.
2431 '\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically.
2432 '\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time.
2433 '\\[ibuffer-do-sort-by-size]' - Sort the buffers by size.
2434 '\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode.
2438 '\\[ibuffer-switch-format]' - Change the current display format.
2439 '\\[forward-line]' - Move point to the next line.
2440 '\\[previous-line]' - Move point to the previous line.
2441 '\\[ibuffer-update]' - As above, but add new buffers to the list.
2442 '\\[ibuffer-quit]' - Bury the Ibuffer buffer.
2443 '\\[describe-mode]' - This help.
2444 '\\[ibuffer-diff-with-file]' - View the differences between this buffer
2445 and its associated file.
2446 '\\[ibuffer-visit-buffer]' - View the buffer on this line.
2447 '\\[ibuffer-visit-buffer-other-window]' - As above, but in another window.
2448 '\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select
2450 '\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line.
2452 ** Information on Filtering:
2454 You can filter your ibuffer view via different critera. Each Ibuffer
2455 buffer has its own stack of active filters. For example, suppose you
2456 are working on an Emacs Lisp project. You can create an Ibuffer
2457 buffer displays buffers in just `emacs-lisp' modes via
2458 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there
2459 is just one entry on the filtering stack.
2461 You can also combine filters. The various filtering commands push a
2462 new filter onto the stack, and the filters combine to show just
2463 buffers which satisfy ALL criteria on the stack. For example, suppose
2464 you only want to see buffers in `emacs-lisp' mode, whose names begin
2465 with \"gnus\". You can accomplish this via:
2466 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2467 \\[ibuffer-filter-by-name] ^gnus RET'.
2469 Additionally, you can OR the top two filters together with
2470 '\\[ibuffer-or-filters]'. To see all buffers in either
2471 `emacs-lisp-mode' or `lisp-interaction-mode', type:
2473 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filter-by-mode] lisp-interaction-mode RET \\[ibuffer-or-filters]'.
2475 Filters can also be saved and restored using mnemonic names: see the
2476 functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'.
2478 To remove the top filter on the stack, use '\\[ibuffer-pop-filter]', and
2479 to disable all filtering currently in effect, use
2480 '\\[ibuffer-filter-disable]'.
2484 Once one has mastered filters, the next logical step up is \"filter
2485 groups\". A filter group is basically a named group of buffers which
2486 match a filter, which are displayed together in an Ibuffer buffer. To
2487 create a filter group, simply use the regular functions to create a
2488 filter, and then type '\\[ibuffer-filters-to-filter-group]'.
2490 A quick example will make things clearer. Suppose that one wants to
2491 group all of one's Emacs Lisp buffers together. To do this, type
2493 '\\[ibuffer-filter-by-mode] emacs-lisp-mode RET \\[ibuffer-filters-to-filter-group] RET emacs lisp buffers RET'
2495 You may, of course, name the group whatever you want; it doesn't have
2496 to be \"emacs lisp buffers\". Filter groups may be composed of any
2497 arbitrary combination of filters.
2499 Just like filters themselves, filter groups act as a stack. Buffers
2500 will not be displayed multiple times if they would be included in
2501 multiple filter groups; instead, the first filter group is used. The
2502 filter groups are displayed in this order of precedence.
2504 You may rearrange filter groups by using the regular
2505 '\\[ibuffer-kill-line]' and '\\[ibuffer-yank]' pair. Yanked groups
2506 will be inserted before the group at point."
2507 (kill-all-local-variables)
2508 (use-local-map ibuffer-mode-map
)
2509 (setq major-mode
'ibuffer-mode
)
2510 (setq mode-name
"Ibuffer")
2511 (setq buffer-read-only t
)
2512 (buffer-disable-undo)
2513 (setq truncate-lines ibuffer-truncate-lines
)
2514 ;; This makes things less ugly for Emacs 21 users with a non-nil
2515 ;; `show-trailing-whitespace'.
2516 (setq show-trailing-whitespace nil
)
2517 ;; disable `show-paren-mode' buffer-locally
2518 (if (bound-and-true-p show-paren-mode
)
2519 (set (make-local-variable 'show-paren-mode
) nil
))
2520 (set (make-local-variable 'revert-buffer-function
)
2522 (set (make-local-variable 'ibuffer-sorting-mode
)
2523 ibuffer-default-sorting-mode
)
2524 (set (make-local-variable 'ibuffer-sorting-reversep
)
2525 ibuffer-default-sorting-reversep
)
2526 (set (make-local-variable 'ibuffer-shrink-to-minimum-size
)
2527 ibuffer-default-shrink-to-minimum-size
)
2528 (set (make-local-variable 'ibuffer-display-maybe-show-predicates
)
2529 ibuffer-default-display-maybe-show-predicates
)
2530 (set (make-local-variable 'ibuffer-filtering-qualifiers
) nil
)
2531 (set (make-local-variable 'ibuffer-filter-groups
) nil
)
2532 (set (make-local-variable 'ibuffer-filter-group-kill-ring
) nil
)
2533 (set (make-local-variable 'ibuffer-hidden-filter-groups
) nil
)
2534 (set (make-local-variable 'ibuffer-compiled-formats
) nil
)
2535 (set (make-local-variable 'ibuffer-cached-formats
) nil
)
2536 (set (make-local-variable 'ibuffer-cached-eliding-string
) nil
)
2537 (set (make-local-variable 'ibuffer-cached-elide-long-columns
) nil
)
2538 (set (make-local-variable 'ibuffer-current-format
) nil
)
2539 (set (make-local-variable 'ibuffer-restore-window-config-on-quit
) nil
)
2540 (set (make-local-variable 'ibuffer-did-modification
) nil
)
2541 (set (make-local-variable 'ibuffer-tmp-hide-regexps
) nil
)
2542 (set (make-local-variable 'ibuffer-tmp-show-regexps
) nil
)
2543 (define-key ibuffer-mode-map
[menu-bar edit
] 'undefined
)
2544 (define-key ibuffer-mode-map
[menu-bar operate
] (cons "Operate" ibuffer-mode-operate-map
))
2545 (ibuffer-update-format)
2546 (when ibuffer-default-directory
2547 (setq default-directory ibuffer-default-directory
))
2548 (add-hook 'change-major-mode-hook
'font-lock-defontify nil t
)
2549 (run-mode-hooks 'ibuffer-mode-hook
)
2550 ;; called after mode hooks to allow the user to add filters
2551 (ibuffer-update-mode-name))
2555 (run-hooks 'ibuffer-load-hook
)
2558 ;; coding: iso-8859-1
2561 ;;; arch-tag: 72581688-0603-4954-b8cf-837c700f62e8
2562 ;;; ibuffer.el ends here