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