* src/alloc.c: Avoid O(N²) complexity when unchaining markers (bug#24548).
[emacs.git] / lisp / ibuffer.el
blob0fd29719344e88bea70ad741f8b0347930b4cb65
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-eliding-string "..."
228 "The string to use for eliding long columns."
229 :type 'string
230 :group 'ibuffer)
232 (defcustom ibuffer-maybe-show-predicates `(,(lambda (buf)
233 (and (string-match "^ " (buffer-name buf))
234 (null buffer-file-name))))
235 "A list of predicates for buffers to display conditionally.
237 A predicate can be a regexp or a function.
238 If a regexp, then it will be matched against the buffer's name.
239 If a function, it will be called with the buffer as an argument, and
240 should return non-nil if this buffer should be shown.
242 Viewing of buffers hidden because of these predicates may be customized
243 via `ibuffer-default-display-maybe-show-predicates' and is toggled by
244 giving a non-nil prefix argument to `ibuffer-update'.
245 Note that this specialized filtering occurs before real filtering."
246 :type '(repeat (choice regexp function))
247 :group 'ibuffer)
249 (defcustom ibuffer-default-display-maybe-show-predicates nil
250 "Non-nil means show buffers that match `ibuffer-maybe-show-predicates'."
251 :type 'boolean
252 :group 'ibuffer)
254 (defvar ibuffer-display-maybe-show-predicates nil)
256 (defvar ibuffer-current-format nil)
258 (defcustom ibuffer-movement-cycle t
259 "If non-nil, then forward and backwards movement commands cycle."
260 :type 'boolean
261 :group 'ibuffer)
263 (defcustom ibuffer-modified-char ?*
264 "The character to display for modified buffers."
265 :type 'character
266 :group 'ibuffer)
268 (defcustom ibuffer-read-only-char ?%
269 "The character to display for read-only buffers."
270 :type 'character
271 :group 'ibuffer)
273 (defcustom ibuffer-marked-char ?>
274 "The character to display for marked buffers."
275 :type 'character
276 :group 'ibuffer)
278 (defcustom ibuffer-locked-char ?L
279 "The character to display for locked buffers."
280 :version "26.1"
281 :type 'character
282 :group 'ibuffer)
284 (defcustom ibuffer-deletion-char ?D
285 "The character to display for buffers marked for deletion."
286 :type 'character
287 :group 'ibuffer)
289 (defcustom ibuffer-expert nil
290 "If non-nil, don't ask for confirmation of \"dangerous\" operations."
291 :type 'boolean
292 :group 'ibuffer)
294 (defcustom ibuffer-view-ibuffer nil
295 "If non-nil, display the current Ibuffer buffer itself.
296 Note that this has a drawback - the data about the current Ibuffer
297 buffer will most likely be inaccurate. This includes modification
298 state, size, etc."
299 :type 'boolean
300 :group 'ibuffer)
302 (defcustom ibuffer-always-show-last-buffer nil
303 "If non-nil, always display the previous buffer.
304 This variable takes precedence over filtering, and even
305 `ibuffer-never-show-predicates'."
306 :type '(choice (const :tag "Always" :value t)
307 (const :tag "Never" :value nil)
308 (const :tag "Always except minibuffer" :value :nomini))
309 :group 'ibuffer)
311 (defcustom ibuffer-jump-offer-only-visible-buffers nil
312 "If non-nil, only offer buffers visible in the Ibuffer buffer
313 in completion lists of the `ibuffer-jump-to-buffer' command."
314 :type 'boolean
315 :group 'ibuffer)
317 (defcustom ibuffer-use-header-line (boundp 'header-line-format)
318 "If non-nil, display a header line containing current filters."
319 :type 'boolean
320 :group 'ibuffer)
322 (defcustom ibuffer-default-directory nil
323 "The default directory to use for a new Ibuffer buffer.
324 If nil, inherit the directory of the buffer in which `ibuffer' was
325 called. Otherwise, this variable should be a string naming a
326 directory, like `default-directory'."
327 :type '(choice (const :tag "Inherit" :value nil)
328 string)
329 :group 'ibuffer)
331 (defcustom ibuffer-help-buffer-modes
332 '(help-mode apropos-mode Info-mode Info-edit-mode)
333 "List of \"Help\" major modes."
334 :type '(repeat function)
335 :group 'ibuffer)
337 (defcustom ibuffer-compressed-file-name-regexp
338 "\\.\\(arj\\|bgz\\|bz2\\|gz\\|lzh\\|taz\\|tgz\\|xz\\|zip\\|z\\)$"
339 "Regexp to match compressed file names."
340 :version "24.1" ; added xz
341 :type 'regexp
342 :group 'ibuffer)
344 (defcustom ibuffer-hook nil
345 "Hook run when `ibuffer' is called."
346 :type 'hook
347 :group 'ibuffer)
349 (defcustom ibuffer-mode-hook nil
350 "Hook run upon entry into `ibuffer-mode'."
351 :type 'hook
352 :options '(ibuffer-auto-mode)
353 :group 'ibuffer)
355 (defcustom ibuffer-load-hook nil
356 "Hook run when Ibuffer is loaded."
357 :type 'hook
358 :group 'ibuffer)
360 (defcustom ibuffer-marked-face 'warning
361 "Face used for displaying marked buffers."
362 :type 'face
363 :group 'ibuffer)
365 (defcustom ibuffer-deletion-face 'error
366 "Face used for displaying buffers marked for deletion."
367 :type 'face
368 :group 'ibuffer)
370 (defcustom ibuffer-title-face 'font-lock-type-face
371 "Face used for the title string."
372 :type 'face
373 :group 'ibuffer)
375 (defcustom ibuffer-filter-group-name-face 'bold
376 "Face used for displaying filtering group names."
377 :type 'face
378 :group 'ibuffer)
380 (defcustom ibuffer-directory-abbrev-alist nil
381 "An alist of file name abbreviations like `directory-abbrev-alist'."
382 :type '(repeat (cons :format "%v"
383 :value ("" . "")
384 (regexp :tag "From")
385 (regexp :tag "To")))
386 :group 'ibuffer)
388 (defvar ibuffer-mode-groups-popup
389 (let ((groups-map (make-sparse-keymap "Filter Groups")))
390 ;; Filter groups
392 (define-key-after groups-map [filters-to-filter-group]
393 '(menu-item "Create filter group from current filters..."
394 ibuffer-filters-to-filter-group
395 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
396 (define-key-after groups-map [forward-filter-group]
397 '(menu-item "Move point to the next filter group"
398 ibuffer-forward-filter-group))
399 (define-key-after groups-map [backward-filter-group]
400 '(menu-item "Move point to the previous filter group"
401 ibuffer-backward-filter-group))
402 (define-key-after groups-map [jump-to-filter-group]
403 '(menu-item "Move point to a specific filter group..."
404 ibuffer-jump-to-filter-group))
405 (define-key-after groups-map [kill-filter-group]
406 '(menu-item "Kill filter group named..."
407 ibuffer-kill-filter-group
408 :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
409 (define-key-after groups-map [yank-filter-group]
410 '(menu-item "Yank last killed filter group before..."
411 ibuffer-yank-filter-group
412 :enable (and (featurep 'ibuf-ext) ibuffer-filter-group-kill-ring)))
413 (define-key-after groups-map [pop-filter-group]
414 '(menu-item "Remove top filter group"
415 ibuffer-pop-filter-group
416 :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
417 (define-key-after groups-map [clear-filter-groups]
418 '(menu-item "Remove all filter groups"
419 ibuffer-clear-filter-groups
420 :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
421 (define-key-after groups-map [pop-filter-group]
422 '(menu-item "Decompose filter group..."
423 ibuffer-pop-filter-group
424 :help "\"Unmake\" a filter group"
425 :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)))
426 (define-key-after groups-map [save-filter-groups]
427 '(menu-item "Save current filter groups permanently..."
428 ibuffer-save-filter-groups
429 :enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)
430 :help "Use a mnemonic name to store current filter groups"))
431 (define-key-after groups-map [switch-to-saved-filter-groups]
432 '(menu-item "Restore permanently saved filters..."
433 ibuffer-switch-to-saved-filter-groups
434 :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)
435 :help "Replace current filters with a saved stack"))
436 (define-key-after groups-map [delete-saved-filter-groups]
437 '(menu-item "Delete permanently saved filter groups..."
438 ibuffer-delete-saved-filter-groups
439 :enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)))
440 (define-key-after groups-map [set-filter-groups-by-mode]
441 '(menu-item "Set current filter groups to filter by mode"
442 ibuffer-set-filter-groups-by-mode))
444 groups-map))
446 (defvar ibuffer-mode-map
447 (let ((map (make-keymap)))
448 (define-key map (kbd "0") 'digit-argument)
449 (define-key map (kbd "1") 'digit-argument)
450 (define-key map (kbd "2") 'digit-argument)
451 (define-key map (kbd "3") 'digit-argument)
452 (define-key map (kbd "4") 'digit-argument)
453 (define-key map (kbd "5") 'digit-argument)
454 (define-key map (kbd "6") 'digit-argument)
455 (define-key map (kbd "7") 'digit-argument)
456 (define-key map (kbd "8") 'digit-argument)
457 (define-key map (kbd "9") 'digit-argument)
459 (define-key map (kbd "m") 'ibuffer-mark-forward)
460 (define-key map (kbd "t") 'ibuffer-toggle-marks)
461 (define-key map (kbd "u") 'ibuffer-unmark-forward)
462 (define-key map (kbd "=") 'ibuffer-diff-with-file)
463 (define-key map (kbd "j") 'ibuffer-jump-to-buffer)
464 (define-key map (kbd "M-g") 'ibuffer-jump-to-buffer)
465 (define-key map (kbd "M-s a C-s") 'ibuffer-do-isearch)
466 (define-key map (kbd "M-s a M-C-s") 'ibuffer-do-isearch-regexp)
467 (define-key map (kbd "M-s a C-o") 'ibuffer-do-occur)
468 (define-key map (kbd "DEL") 'ibuffer-unmark-backward)
469 (define-key map (kbd "M-DEL") 'ibuffer-unmark-all)
470 (define-key map (kbd "* *") 'ibuffer-unmark-all)
471 (define-key map (kbd "* c") 'ibuffer-change-marks)
472 (define-key map (kbd "U") 'ibuffer-unmark-all-marks)
473 (define-key map (kbd "* M") 'ibuffer-mark-by-mode)
474 (define-key map (kbd "* m") 'ibuffer-mark-modified-buffers)
475 (define-key map (kbd "* u") 'ibuffer-mark-unsaved-buffers)
476 (define-key map (kbd "* s") 'ibuffer-mark-special-buffers)
477 (define-key map (kbd "* r") 'ibuffer-mark-read-only-buffers)
478 (define-key map (kbd "* /") 'ibuffer-mark-dired-buffers)
479 (define-key map (kbd "* e") 'ibuffer-mark-dissociated-buffers)
480 (define-key map (kbd "* h") 'ibuffer-mark-help-buffers)
481 (define-key map (kbd "* z") 'ibuffer-mark-compressed-file-buffers)
482 (define-key map (kbd ".") 'ibuffer-mark-old-buffers)
484 (define-key map (kbd "d") 'ibuffer-mark-for-delete)
485 (define-key map (kbd "C-d") 'ibuffer-mark-for-delete-backwards)
486 (define-key map (kbd "k") 'ibuffer-mark-for-delete)
487 (define-key map (kbd "x") 'ibuffer-do-kill-on-deletion-marks)
489 ;; immediate operations
490 (define-key map (kbd "n") 'ibuffer-forward-line)
491 (define-key map (kbd "SPC") 'forward-line)
492 (define-key map (kbd "p") 'ibuffer-backward-line)
493 (define-key map (kbd "M-}") 'ibuffer-forward-next-marked)
494 (define-key map (kbd "M-{") 'ibuffer-backwards-next-marked)
495 (define-key map (kbd "l") 'ibuffer-redisplay)
496 (define-key map (kbd "g") 'ibuffer-update)
497 (define-key map "`" 'ibuffer-switch-format)
498 (define-key map "-" 'ibuffer-add-to-tmp-hide)
499 (define-key map "+" 'ibuffer-add-to-tmp-show)
500 (define-key map "b" 'ibuffer-bury-buffer)
501 (define-key map (kbd ",") 'ibuffer-toggle-sorting-mode)
502 (define-key map (kbd "s i") 'ibuffer-invert-sorting)
503 (define-key map (kbd "s a") 'ibuffer-do-sort-by-alphabetic)
504 (define-key map (kbd "s v") 'ibuffer-do-sort-by-recency)
505 (define-key map (kbd "s s") 'ibuffer-do-sort-by-size)
506 (define-key map (kbd "s f") 'ibuffer-do-sort-by-filename/process)
507 (define-key map (kbd "s m") 'ibuffer-do-sort-by-major-mode)
509 (define-key map (kbd "/ RET") 'ibuffer-filter-by-mode)
510 (define-key map (kbd "/ m") 'ibuffer-filter-by-used-mode)
511 (define-key map (kbd "/ M") 'ibuffer-filter-by-derived-mode)
512 (define-key map (kbd "/ n") 'ibuffer-filter-by-name)
513 (define-key map (kbd "/ E") 'ibuffer-filter-by-process)
514 (define-key map (kbd "/ *") 'ibuffer-filter-by-starred-name)
515 (define-key map (kbd "/ f") 'ibuffer-filter-by-filename)
516 (define-key map (kbd "/ b") 'ibuffer-filter-by-basename)
517 (define-key map (kbd "/ .") 'ibuffer-filter-by-file-extension)
518 (define-key map (kbd "/ <") 'ibuffer-filter-by-size-lt)
519 (define-key map (kbd "/ >") 'ibuffer-filter-by-size-gt)
520 (define-key map (kbd "/ i") 'ibuffer-filter-by-modified)
521 (define-key map (kbd "/ v") 'ibuffer-filter-by-visiting-file)
522 (define-key map (kbd "/ c") 'ibuffer-filter-by-content)
523 (define-key map (kbd "/ e") 'ibuffer-filter-by-predicate)
525 (define-key map (kbd "/ r") 'ibuffer-switch-to-saved-filters)
526 (define-key map (kbd "/ a") 'ibuffer-add-saved-filters)
527 (define-key map (kbd "/ x") 'ibuffer-delete-saved-filters)
528 (define-key map (kbd "/ d") 'ibuffer-decompose-filter)
529 (define-key map (kbd "/ s") 'ibuffer-save-filters)
530 (define-key map (kbd "/ p") 'ibuffer-pop-filter)
531 (define-key map (kbd "/ <up>") 'ibuffer-pop-filter)
532 (define-key map (kbd "/ !") 'ibuffer-negate-filter)
533 (define-key map (kbd "/ t") 'ibuffer-exchange-filters)
534 (define-key map (kbd "/ TAB") 'ibuffer-exchange-filters)
535 (define-key map (kbd "/ o") 'ibuffer-or-filter)
536 (define-key map (kbd "/ |") 'ibuffer-or-filter)
537 (define-key map (kbd "/ &") 'ibuffer-and-filter)
538 (define-key map (kbd "/ g") 'ibuffer-filters-to-filter-group)
539 (define-key map (kbd "/ P") 'ibuffer-pop-filter-group)
540 (define-key map (kbd "/ S-<up>") 'ibuffer-pop-filter-group)
541 (define-key map (kbd "/ D") 'ibuffer-decompose-filter-group)
542 (define-key map (kbd "/ /") 'ibuffer-filter-disable)
544 (define-key map (kbd "M-n") 'ibuffer-forward-filter-group)
545 (define-key map "\t" 'ibuffer-forward-filter-group)
546 (define-key map (kbd "M-p") 'ibuffer-backward-filter-group)
547 (define-key map [backtab] 'ibuffer-backward-filter-group)
548 (define-key map (kbd "M-j") 'ibuffer-jump-to-filter-group)
549 (define-key map (kbd "C-k") 'ibuffer-kill-line)
550 (define-key map (kbd "C-y") 'ibuffer-yank)
551 (define-key map (kbd "/ S") 'ibuffer-save-filter-groups)
552 (define-key map (kbd "/ R") 'ibuffer-switch-to-saved-filter-groups)
553 (define-key map (kbd "/ X") 'ibuffer-delete-saved-filter-groups)
554 (define-key map (kbd "/ \\") 'ibuffer-clear-filter-groups)
556 (define-key map (kbd "% n") 'ibuffer-mark-by-name-regexp)
557 (define-key map (kbd "% m") 'ibuffer-mark-by-mode-regexp)
558 (define-key map (kbd "% f") 'ibuffer-mark-by-file-name-regexp)
559 (define-key map (kbd "% g") 'ibuffer-mark-by-content-regexp)
560 (define-key map (kbd "% L") 'ibuffer-mark-by-locked)
562 (define-key map (kbd "C-t") 'ibuffer-visit-tags-table)
564 (define-key map (kbd "|") 'ibuffer-do-shell-command-pipe)
565 (define-key map (kbd "!") 'ibuffer-do-shell-command-file)
566 (define-key map (kbd "~") 'ibuffer-do-toggle-modified)
567 ;; marked operations
568 (define-key map (kbd "A") 'ibuffer-do-view)
569 (define-key map (kbd "D") 'ibuffer-do-delete)
570 (define-key map (kbd "E") 'ibuffer-do-eval)
571 (define-key map (kbd "F") 'ibuffer-do-shell-command-file)
572 (define-key map (kbd "I") 'ibuffer-do-query-replace-regexp)
573 (define-key map (kbd "H") 'ibuffer-do-view-other-frame)
574 (define-key map (kbd "N") 'ibuffer-do-shell-command-pipe-replace)
575 (define-key map (kbd "M") 'ibuffer-do-toggle-modified)
576 (define-key map (kbd "O") 'ibuffer-do-occur)
577 (define-key map (kbd "P") 'ibuffer-do-print)
578 (define-key map (kbd "Q") 'ibuffer-do-query-replace)
579 (define-key map (kbd "R") 'ibuffer-do-rename-uniquely)
580 (define-key map (kbd "S") 'ibuffer-do-save)
581 (define-key map (kbd "T") 'ibuffer-do-toggle-read-only)
582 (define-key map (kbd "r") 'ibuffer-do-replace-regexp)
583 (define-key map (kbd "V") 'ibuffer-do-revert)
584 (define-key map (kbd "W") 'ibuffer-do-view-and-eval)
585 (define-key map (kbd "X") 'ibuffer-do-shell-command-pipe)
587 (define-key map (kbd "k") 'ibuffer-do-kill-lines)
588 (define-key map (kbd "w") 'ibuffer-copy-filename-as-kill)
589 (define-key map (kbd "B") 'ibuffer-copy-buffername-as-kill)
591 (define-key map (kbd "RET") 'ibuffer-visit-buffer)
592 (define-key map (kbd "e") 'ibuffer-visit-buffer)
593 (define-key map (kbd "f") 'ibuffer-visit-buffer)
594 (define-key map (kbd "C-x C-f") 'ibuffer-find-file)
595 (define-key map (kbd "o") 'ibuffer-visit-buffer-other-window)
596 (define-key map (kbd "C-o") 'ibuffer-visit-buffer-other-window-noselect)
597 (define-key map (kbd "M-o") 'ibuffer-visit-buffer-1-window)
598 (define-key map (kbd "v") 'ibuffer-do-view)
599 (define-key map (kbd "C-x v") 'ibuffer-do-view-horizontally)
600 (define-key map (kbd "C-c C-a") 'ibuffer-auto-mode)
601 (define-key map (kbd "C-x 4 RET") 'ibuffer-visit-buffer-other-window)
602 (define-key map (kbd "C-x 5 RET") 'ibuffer-visit-buffer-other-frame)
604 (define-key map [menu-bar view]
605 (cons "View" (make-sparse-keymap "View")))
607 (define-key-after map [menu-bar view visit-buffer]
608 '(menu-item "View this buffer" ibuffer-visit-buffer))
609 (define-key-after map [menu-bar view visit-buffer-other-window]
610 '(menu-item "View (other window)" ibuffer-visit-buffer-other-window))
611 (define-key-after map [menu-bar view visit-buffer-other-frame]
612 '(menu-item "View (other frame)" ibuffer-visit-buffer-other-frame))
613 (define-key-after map [menu-bar view ibuffer-update]
614 '(menu-item "Update" ibuffer-update
615 :help "Regenerate the list of buffers"))
616 (define-key-after map [menu-bar view switch-format]
617 '(menu-item "Switch display format" ibuffer-switch-format
618 :help "Toggle between available values of `ibuffer-formats'"))
620 (define-key-after map [menu-bar view dashes]
621 '("--"))
623 (define-key-after map [menu-bar view sort]
624 (cons "Sort" (make-sparse-keymap "Sort")))
626 (define-key-after map [menu-bar view sort do-sort-by-major-mode]
627 '(menu-item "Sort by major mode" ibuffer-do-sort-by-major-mode))
628 (define-key-after map [menu-bar view sort do-sort-by-size]
629 '(menu-item "Sort by buffer size" ibuffer-do-sort-by-size))
630 (define-key-after map [menu-bar view sort do-sort-by-alphabetic]
631 '(menu-item "Sort lexicographically" ibuffer-do-sort-by-alphabetic
632 :help "Sort by the alphabetic order of buffer name"))
633 (define-key-after map [menu-bar view sort do-sort-by-recency]
634 '(menu-item "Sort by view time" ibuffer-do-sort-by-recency
635 :help "Sort by the last time the buffer was displayed"))
636 (define-key-after map [menu-bar view sort dashes]
637 '("--"))
638 (define-key-after map [menu-bar view sort invert-sorting]
639 '(menu-item "Reverse sorting order" ibuffer-invert-sorting))
640 (define-key-after map [menu-bar view sort toggle-sorting-mode]
641 '(menu-item "Switch sorting mode" ibuffer-toggle-sorting-mode
642 :help "Switch between the various sorting criteria"))
644 (define-key-after map [menu-bar view filter]
645 (cons "Filter" (make-sparse-keymap "Filter")))
647 (define-key-after map [menu-bar view filter filter-disable]
648 '(menu-item "Disable all filtering" ibuffer-filter-disable
649 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
650 (define-key-after map [menu-bar view filter filter-by-mode]
651 '(menu-item "Add filter by any major mode..." ibuffer-filter-by-mode))
652 (define-key-after map [menu-bar view filter filter-by-used-mode]
653 '(menu-item "Add filter by a major mode in use..."
654 ibuffer-filter-by-used-mode))
655 (define-key-after map [menu-bar view filter filter-by-derived-mode]
656 '(menu-item "Add filter by derived mode..."
657 ibuffer-filter-by-derived-mode))
658 (define-key-after map [menu-bar view filter filter-by-name]
659 '(menu-item "Add filter by buffer name..." ibuffer-filter-by-name))
660 (define-key-after map [menu-bar view filter filter-by-starred-name]
661 '(menu-item "Add filter by starred buffer name..."
662 ibuffer-filter-by-starred-name
663 :help "List buffers whose names begin with a star"))
664 (define-key-after map [menu-bar view filter filter-by-filename]
665 '(menu-item "Add filter by full filename..." ibuffer-filter-by-filename
666 :help
667 (concat "For a buffer associated with file '/a/b/c.d', "
668 "list buffer if a given pattern matches '/a/b/c.d'")))
669 (define-key-after map [menu-bar view filter filter-by-basename]
670 '(menu-item "Add filter by file basename..."
671 ibuffer-filter-by-basename
672 :help (concat "For a buffer associated with file '/a/b/c.d', "
673 "list buffer if a given pattern matches 'c.d'")))
674 (define-key-after map [menu-bar view filter filter-by-file-extension]
675 '(menu-item "Add filter by file name extension..."
676 ibuffer-filter-by-file-extension
677 :help (concat "For a buffer associated with file '/a/b/c.d', "
678 "list buffer if a given pattern matches 'd'")))
679 (define-key-after map [menu-bar view filter filter-by-directory]
680 '(menu-item "Add filter by filename's directory..."
681 ibuffer-filter-by-directory
682 :help
683 (concat "For a buffer associated with file '/a/b/c.d', "
684 "list buffer if a given pattern matches '/a/b'")))
685 (define-key-after map [menu-bar view filter filter-by-size-lt]
686 '(menu-item "Add filter by size less than..." ibuffer-filter-by-size-lt))
687 (define-key-after map [menu-bar view filter filter-by-size-gt]
688 '(menu-item "Add filter by size greater than..."
689 ibuffer-filter-by-size-gt))
690 (define-key-after map [menu-bar view filter filter-by-modified]
691 '(menu-item "Add filter by modified buffer" ibuffer-filter-by-modified
692 :help "List buffers that are marked as modified"))
693 (define-key-after map [menu-bar view filter filter-by-visiting-file]
694 '(menu-item "Add filter by buffer visiting a file"
695 ibuffer-filter-by-visiting-file
696 :help "List buffers that are visiting files"))
697 (define-key-after map [menu-bar view filter filter-by-content]
698 '(menu-item "Add filter by content (regexp)..."
699 ibuffer-filter-by-content))
700 (define-key-after map [menu-bar view filter filter-by-predicate]
701 '(menu-item "Add filter by Lisp predicate..."
702 ibuffer-filter-by-predicate))
703 (define-key-after map [menu-bar view filter pop-filter]
704 '(menu-item "Remove top filter" ibuffer-pop-filter
705 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
706 (define-key-after map [menu-bar view filter and-filter]
707 '(menu-item "AND top two filters" ibuffer-and-filter
708 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
709 (cdr ibuffer-filtering-qualifiers))
710 :help
711 "Create a new filter which is the logical AND of the top two filters"))
712 (define-key-after map [menu-bar view filter or-filter]
713 '(menu-item "OR top two filters" ibuffer-or-filter
714 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
715 (cdr ibuffer-filtering-qualifiers))
716 :help
717 "Create a new filter which is the logical OR of the top two filters"))
718 (define-key-after map [menu-bar view filter negate-filter]
719 '(menu-item "Negate top filter" ibuffer-negate-filter
720 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)))
721 (define-key-after map [menu-bar view filter decompose-filter]
722 '(menu-item "Decompose top filter" ibuffer-decompose-filter
723 :enable (and (featurep 'ibuf-ext)
724 (memq (car ibuffer-filtering-qualifiers) '(or saved not)))
725 :help "Break down a complex filter like OR or NOT"))
726 (define-key-after map [menu-bar view filter exchange-filters]
727 '(menu-item "Swap top two filters" ibuffer-exchange-filters
728 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
729 (cdr ibuffer-filtering-qualifiers))))
730 (define-key-after map [menu-bar view filter save-filters]
731 '(menu-item "Save current filters permanently..." ibuffer-save-filters
732 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
733 :help "Use a mnemonic name to store current filter stack"))
734 (define-key-after map [menu-bar view filter switch-to-saved-filters]
735 '(menu-item "Restore permanently saved filters..."
736 ibuffer-switch-to-saved-filters
737 :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)
738 :help "Replace current filters with a saved stack"))
739 (define-key-after map [menu-bar view filter add-saved-filters]
740 '(menu-item "Add to permanently saved filters..."
741 ibuffer-add-saved-filters
742 :enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
743 :help "Include already saved stack with current filters"))
744 (define-key-after map [menu-bar view filter delete-saved-filters]
745 '(menu-item "Delete permanently saved filters..."
746 ibuffer-delete-saved-filters
747 :enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)))
749 (define-key-after map [menu-bar view filter-groups]
750 (cons "Filter Groups" ibuffer-mode-groups-popup))
752 (define-key-after map [menu-bar view dashes2]
753 '("--"))
754 (define-key-after map [menu-bar view auto-mode]
755 '(menu-item "Auto Mode" ibuffer-auto-mode
756 :button (:toggle . ibuffer-auto-mode)
757 :help "Attempt to automatically update the Ibuffer buffer"))
759 (define-key-after map [menu-bar mark]
760 (cons "Mark" (make-sparse-keymap "Mark")))
762 (define-key-after map [menu-bar mark toggle-marks]
763 '(menu-item "Toggle marks" ibuffer-toggle-marks
764 :help "Unmark marked buffers, and mark unmarked buffers"))
765 (define-key-after map [menu-bar mark change-marks]
766 '(menu-item "Change marks" ibuffer-change-marks
767 :help "Change OLD mark for marked buffers with NEW"))
768 (define-key-after map [menu-bar mark mark-forward]
769 '(menu-item "Mark" ibuffer-mark-forward
770 :help "Mark the buffer at point"))
771 (define-key-after map [menu-bar mark unmark-forward]
772 '(menu-item "Unmark" ibuffer-unmark-forward
773 :help "Unmark the buffer at point"))
774 (define-key-after map [menu-bar mark mark-by-mode]
775 '(menu-item "Mark by mode..." ibuffer-mark-by-mode
776 :help "Mark all buffers in a particular major mode"))
777 (define-key-after map [menu-bar mark mark-modified-buffers]
778 '(menu-item "Mark modified buffers" ibuffer-mark-modified-buffers
779 :help "Mark all buffers which have been modified"))
780 (define-key-after map [menu-bar mark mark-unsaved-buffers]
781 '(menu-item "Mark unsaved buffers" ibuffer-mark-unsaved-buffers
782 :help "Mark all buffers which have a file and are modified"))
783 (define-key-after map [menu-bar mark mark-read-only-buffers]
784 '(menu-item "Mark read-only buffers" ibuffer-mark-read-only-buffers
785 :help "Mark all buffers which are read-only"))
786 (define-key-after map [menu-bar mark mark-special-buffers]
787 '(menu-item "Mark special buffers" ibuffer-mark-special-buffers
788 :help "Mark all buffers whose name begins with a *"))
789 (define-key-after map [menu-bar mark mark-dired-buffers]
790 '(menu-item "Mark dired buffers" ibuffer-mark-dired-buffers
791 :help "Mark buffers in dired-mode"))
792 (define-key-after map [menu-bar mark mark-dissociated-buffers]
793 '(menu-item "Mark dissociated buffers" ibuffer-mark-dissociated-buffers
794 :help "Mark buffers with a non-existent associated file"))
795 (define-key-after map [menu-bar mark mark-help-buffers]
796 '(menu-item "Mark help buffers" ibuffer-mark-help-buffers
797 :help "Mark buffers in help-mode"))
798 (define-key-after map [menu-bar mark mark-compressed-file-buffers]
799 '(menu-item "Mark compressed file buffers"
800 ibuffer-mark-compressed-file-buffers
801 :help "Mark buffers which have a file that is compressed"))
802 (define-key-after map [menu-bar mark mark-old-buffers]
803 '(menu-item "Mark old buffers" ibuffer-mark-old-buffers
804 :help "Mark buffers which have not been viewed recently"))
805 (define-key-after map [menu-bar mark unmark-all]
806 '(menu-item "Unmark All" ibuffer-unmark-all))
807 (define-key-after map [menu-bar mark unmark-all-marks]
808 '(menu-item "Unmark All buffers" ibuffer-unmark-all-marks))
810 (define-key-after map [menu-bar mark dashes]
811 '("--"))
813 (define-key-after map [menu-bar mark mark-by-name-regexp]
814 '(menu-item "Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
815 :help "Mark buffers whose name matches a regexp"))
816 (define-key-after map [menu-bar mark mark-by-mode-regexp]
817 '(menu-item "Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp
818 :help "Mark buffers whose major mode name matches a regexp"))
819 (define-key-after map [menu-bar mark mark-by-file-name-regexp]
820 '(menu-item "Mark by file name (regexp)..."
821 ibuffer-mark-by-file-name-regexp
822 :help "Mark buffers whose file name matches a regexp"))
823 (define-key-after map [menu-bar mark ibuffer-mark-by-content-regexp]
824 '(menu-item "Mark by content (regexp)..."
825 ibuffer-mark-by-content-regexp
826 :help "Mark buffers whose content matches a regexp"))
827 (define-key-after map [menu-bar mark mark-by-locked]
828 '(menu-item "Mark by locked buffers..." ibuffer-mark-by-locked
829 :help "Mark all locked buffers"))
831 map))
833 (defvar ibuffer-mode-operate-map
834 (let ((operate-map (make-sparse-keymap "Operate")))
835 (define-key-after operate-map [do-view]
836 '(menu-item "View" ibuffer-do-view))
837 (define-key-after operate-map [do-view-other-frame]
838 '(menu-item "View (separate frame)" ibuffer-do-view-other-frame))
839 (define-key-after operate-map [do-save]
840 '(menu-item "Save" ibuffer-do-save))
841 (define-key-after operate-map [do-replace-regexp]
842 '(menu-item "Replace (regexp)..." ibuffer-do-replace-regexp
843 :help "Replace text inside marked buffers"))
844 (define-key-after operate-map [do-query-replace]
845 '(menu-item "Query Replace..." ibuffer-do-query-replace
846 :help "Replace text in marked buffers, asking each time"))
847 (define-key-after operate-map [do-query-replace-regexp]
848 '(menu-item "Query Replace (regexp)..." ibuffer-do-query-replace-regexp
849 :help "Replace text in marked buffers by regexp, asking each time"))
850 (define-key-after operate-map [do-print]
851 '(menu-item "Print" ibuffer-do-print))
852 (define-key-after operate-map [do-toggle-modified]
853 '(menu-item "Toggle modification flag" ibuffer-do-toggle-modified))
854 (define-key-after operate-map [do-revert]
855 '(menu-item "Revert" ibuffer-do-revert
856 :help "Revert marked buffers to their associated file"))
857 (define-key-after operate-map [do-rename-uniquely]
858 '(menu-item "Rename Uniquely" ibuffer-do-rename-uniquely
859 :help "Rename marked buffers to a new, unique name"))
860 (define-key-after operate-map [do-delete]
861 '(menu-item "Kill" ibuffer-do-delete))
862 (define-key-after operate-map [do-occur]
863 '(menu-item "List lines matching..." ibuffer-do-occur
864 :help "View all lines in marked buffers matching a regexp"))
865 (define-key-after operate-map [do-shell-command-pipe]
866 '(menu-item "Pipe to shell command..." ibuffer-do-shell-command-pipe
867 :help "For each marked buffer, send its contents to a shell command"))
868 (define-key-after operate-map [do-shell-command-pipe-replace]
869 '(menu-item "Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace
870 :help "For each marked buffer, replace its contents with output of shell command"))
871 (define-key-after operate-map [do-shell-command-file]
872 '(menu-item "Shell command on buffer's file..." ibuffer-do-shell-command-file
873 :help "For each marked buffer, run a shell command with its file as argument"))
874 (define-key-after operate-map [do-eval]
875 '(menu-item "Eval..." ibuffer-do-eval
876 :help "Evaluate a Lisp form in each marked buffer"))
877 (define-key-after operate-map [do-view-and-eval]
878 '(menu-item "Eval (viewing buffer)..." ibuffer-do-view-and-eval
879 :help "Evaluate a Lisp form in each marked buffer while viewing it"))
880 (define-key-after operate-map [diff-with-file]
881 '(menu-item "Diff with file" ibuffer-diff-with-file
882 :help "View the differences between this buffer and its file"))
884 operate-map))
886 (define-key ibuffer-mode-groups-popup [kill-filter-group]
887 '(menu-item "Kill filter group"
888 ibuffer-kill-line
889 :enable (and (featurep 'ibuf-ext)
890 ibuffer-filter-groups)))
891 (define-key ibuffer-mode-groups-popup [yank-filter-group]
892 '(menu-item "Yank last killed filter group"
893 ibuffer-yank
894 :enable (and (featurep 'ibuf-ext)
895 ibuffer-filter-group-kill-ring)))
897 (defvar ibuffer-name-map
898 (let ((map (make-sparse-keymap)))
899 (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark)
900 (define-key map [(mouse-2)] 'ibuffer-mouse-visit-buffer)
901 (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu)
902 map))
904 (defvar ibuffer-filename/process-header-map
905 (let ((map (make-sparse-keymap)))
906 (define-key map [(mouse-1)] 'ibuffer-do-sort-by-filename/process)
907 map))
909 (defvar ibuffer-mode-name-map
910 (let ((map (make-sparse-keymap)))
911 (define-key map [(mouse-2)] 'ibuffer-mouse-filter-by-mode)
912 (define-key map (kbd "RET") 'ibuffer-interactive-filter-by-mode)
913 map))
915 (defvar ibuffer-name-header-map
916 (let ((map (make-sparse-keymap)))
917 (define-key map [(mouse-1)] 'ibuffer-do-sort-by-alphabetic)
918 map))
920 (defvar ibuffer-size-header-map
921 (let ((map (make-sparse-keymap)))
922 (define-key map [(mouse-1)] 'ibuffer-do-sort-by-size)
923 map))
925 (defvar ibuffer-mode-header-map
926 (let ((map (make-sparse-keymap)))
927 (define-key map [(mouse-1)] 'ibuffer-do-sort-by-major-mode)
928 map))
930 (defvar ibuffer-mode-filter-group-map
931 (let ((map (make-sparse-keymap)))
932 (define-key map [(mouse-1)] 'ibuffer-mouse-toggle-mark)
933 (define-key map [(mouse-2)] 'ibuffer-mouse-toggle-filter-group)
934 (define-key map (kbd "RET") 'ibuffer-toggle-filter-group)
935 (define-key map [down-mouse-3] 'ibuffer-mouse-popup-menu)
936 map))
938 (defvar ibuffer-did-modification nil)
940 (defvar ibuffer-compiled-formats nil)
941 (defvar ibuffer-cached-formats nil)
942 (defvar ibuffer-cached-eliding-string nil)
944 (defvar ibuffer-sorting-functions-alist nil
945 "An alist of functions which describe how to sort buffers.
947 Note: You most likely do not want to modify this variable directly;
948 use `define-ibuffer-sorter' instead.
950 The alist elements are constructed like (NAME DESCRIPTION FUNCTION)
951 Where NAME is a symbol describing the sorting method, DESCRIPTION is a
952 short string which will be displayed in the minibuffer and menu, and
953 FUNCTION is a function of two arguments, which will be the buffers to
954 compare.")
956 ;;; Utility functions
957 (defun ibuffer-columnize-and-insert-list (list &optional pad-width)
958 "Insert LIST into the current buffer in as many columns as possible.
959 The maximum number of columns is determined by the current window
960 width and the longest string in LIST."
961 (unless pad-width
962 (setq pad-width 3))
963 (let ((width (window-width))
964 (max (+ (apply #'max (mapcar #'length list))
965 pad-width)))
966 (let ((columns (/ width max)))
967 (when (zerop columns)
968 (setq columns 1))
969 (while list
970 (dotimes (_ (1- columns))
971 (insert (concat (car list) (make-string (- max (length (car list)))
972 ?\s)))
973 (setq list (cdr list)))
974 (when (not (null list))
975 (insert (pop list)))
976 (insert "\n")))))
978 (defsubst ibuffer-current-mark ()
979 (cadr (get-text-property (line-beginning-position)
980 'ibuffer-properties)))
982 (defun ibuffer-mouse-toggle-mark (event)
983 "Toggle the marked status of the buffer chosen with the mouse."
984 (interactive "e")
985 (unwind-protect
986 (let ((pt (save-excursion
987 (mouse-set-point event)
988 (point))))
989 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
990 (ibuffer-toggle-marks it)
991 (goto-char pt)
992 (let ((mark (ibuffer-current-mark)))
993 (setq buffer-read-only nil)
994 (if (eq mark ibuffer-marked-char)
995 (ibuffer-set-mark ?\s)
996 (ibuffer-set-mark ibuffer-marked-char)))))
997 (setq buffer-read-only t)))
999 (defun ibuffer-find-file (file &optional wildcards)
1000 "Like `find-file', but default to the directory of the buffer at point."
1001 (interactive
1002 (let ((default-directory (let ((buf (ibuffer-current-buffer)))
1003 (if (buffer-live-p buf)
1004 (with-current-buffer buf
1005 default-directory)
1006 default-directory))))
1007 (list (read-file-name "Find file: " default-directory)
1008 t)))
1009 (find-file file wildcards))
1011 (defun ibuffer-mouse-visit-buffer (event)
1012 "Visit the buffer chosen with the mouse."
1013 (interactive "e")
1014 (switch-to-buffer
1015 (save-excursion
1016 (mouse-set-point event)
1017 (ibuffer-current-buffer t))))
1019 (defun ibuffer-mouse-popup-menu (event)
1020 "Display a menu of operations."
1021 (interactive "e")
1022 (let ((eventpt (posn-point (event-end event)))
1023 (origpt (point)))
1024 (unwind-protect
1025 (if (get-text-property eventpt 'ibuffer-filter-group-name)
1026 (progn
1027 (goto-char eventpt)
1028 (popup-menu ibuffer-mode-groups-popup))
1029 (let ((inhibit-read-only t))
1030 (ibuffer-save-marks
1031 (ibuffer-unmark-all-marks)
1032 (save-excursion
1033 (goto-char eventpt)
1034 (ibuffer-set-mark ibuffer-marked-char))
1035 (save-excursion
1036 (popup-menu ibuffer-mode-operate-map)))))
1037 (setq buffer-read-only t)
1038 (if (= eventpt (point))
1039 (goto-char origpt)))))
1041 (defun ibuffer-skip-properties (props direction)
1042 (while (and (not (eobp))
1043 (let ((hit nil))
1044 (dolist (prop props hit)
1045 (when (get-text-property (point) prop)
1046 (setq hit t)))))
1047 (forward-line direction)
1048 (beginning-of-line)))
1050 (defun ibuffer-customize ()
1051 "Begin customizing Ibuffer interactively."
1052 (interactive)
1053 (customize-group 'ibuffer))
1055 (defun ibuffer-backward-line (&optional arg skip-group-names)
1056 "Move backwards ARG lines, wrapping around the list if necessary."
1057 (interactive "P")
1058 (or arg (setq arg 1))
1059 (beginning-of-line)
1060 (while (> arg 0)
1061 (forward-line -1)
1062 (when (and ibuffer-movement-cycle
1063 (or (get-text-property (point) 'ibuffer-title)
1064 (and skip-group-names
1065 (get-text-property (point)
1066 'ibuffer-filter-group-name))))
1067 (goto-char (point-max))
1068 (beginning-of-line))
1069 (ibuffer-skip-properties (append '(ibuffer-summary)
1070 (when skip-group-names
1071 '(ibuffer-filter-group-name)))
1073 ;; Handle the special case of no buffers.
1074 (when (get-text-property (point) 'ibuffer-title)
1075 (forward-line 1)
1076 (setq arg 1))
1077 (cl-decf arg)))
1079 (defun ibuffer-forward-line (&optional arg skip-group-names)
1080 "Move forward ARG lines, wrapping around the list if necessary."
1081 (interactive "P")
1082 (or arg (setq arg 1))
1083 (beginning-of-line)
1084 (when (and ibuffer-movement-cycle
1085 (or (eobp)
1086 (get-text-property (point) 'ibuffer-summary)))
1087 (goto-char (point-min)))
1088 (when (or (get-text-property (point) 'ibuffer-title)
1089 (and skip-group-names
1090 (get-text-property (point) 'ibuffer-filter-group-name)))
1091 (when (> arg 0)
1092 (cl-decf arg))
1093 (ibuffer-skip-properties (append '(ibuffer-title)
1094 (when skip-group-names
1095 '(ibuffer-filter-group-name)))
1097 (if (< arg 0)
1098 (ibuffer-backward-line (- arg))
1099 (while (> arg 0)
1100 (forward-line 1)
1101 (when (and ibuffer-movement-cycle
1102 (or (eobp)
1103 (get-text-property (point) 'ibuffer-summary)))
1104 (goto-char (point-min)))
1105 (cl-decf arg)
1106 (ibuffer-skip-properties (append '(ibuffer-title)
1107 (when skip-group-names
1108 '(ibuffer-filter-group-name)))
1109 1))))
1111 (defun ibuffer-visit-buffer (&optional single)
1112 "Visit the buffer on this line.
1113 If optional argument SINGLE is non-nil, then also ensure there is only
1114 one window."
1115 (interactive "P")
1116 (let ((buf (ibuffer-current-buffer t)))
1117 (switch-to-buffer buf)
1118 (when single
1119 (delete-other-windows))))
1121 (defun ibuffer-visit-buffer-other-window (&optional noselect)
1122 "Visit the buffer on this line in another window."
1123 (interactive)
1124 (let ((buf (ibuffer-current-buffer t)))
1125 (bury-buffer (current-buffer))
1126 (if noselect
1127 (let ((curwin (selected-window)))
1128 (pop-to-buffer buf)
1129 (select-window curwin))
1130 (switch-to-buffer-other-window buf))))
1132 (defun ibuffer-visit-buffer-other-window-noselect ()
1133 "Visit the buffer on this line in another window, but don't select it."
1134 (interactive)
1135 (ibuffer-visit-buffer-other-window t))
1137 (defun ibuffer-visit-buffer-other-frame ()
1138 "Visit the buffer on this line in another frame."
1139 (interactive)
1140 (let ((buf (ibuffer-current-buffer t)))
1141 (bury-buffer (current-buffer))
1142 (switch-to-buffer-other-frame buf)))
1144 (defun ibuffer-visit-buffer-1-window ()
1145 "Visit the buffer on this line, and delete other windows."
1146 (interactive)
1147 (ibuffer-visit-buffer t))
1149 (defun ibuffer-bury-buffer ()
1150 "Bury the buffer on this line."
1151 (interactive)
1152 (let ((buf (ibuffer-current-buffer t))
1153 (line (+ 1 (count-lines 1 (point)))))
1154 (bury-buffer buf)
1155 (ibuffer-update nil t)
1156 (goto-char (point-min))
1157 (forward-line (1- line))))
1159 (defun ibuffer-visit-tags-table ()
1160 "Visit the tags table in the buffer on this line. See `visit-tags-table'."
1161 (interactive)
1162 (let ((file (buffer-file-name (ibuffer-current-buffer t))))
1163 (if file
1164 (visit-tags-table file)
1165 (error "Specified buffer has no file"))))
1167 (defun ibuffer-do-view (&optional other-frame)
1168 "View marked buffers, or the buffer on the current line.
1169 If optional argument OTHER-FRAME is non-nil, then display each
1170 marked buffer in a new frame. Otherwise, display each buffer as
1171 a new window in the current frame, splitting vertically."
1172 (interactive)
1173 (ibuffer-do-view-1 (if other-frame 'other-frame 'vertically)))
1175 (defun ibuffer-do-view-horizontally (&optional other-frame)
1176 "As `ibuffer-do-view', but split windows horizontally."
1177 (interactive)
1178 (ibuffer-do-view-1 (if other-frame 'other-frame 'horizontally)))
1180 (defun ibuffer-do-view-1 (type)
1181 (let ((marked-bufs (or (ibuffer-get-marked-buffers)
1182 (list (ibuffer-current-buffer t)))))
1183 (unless (and (eq type 'other-frame)
1184 (not ibuffer-expert)
1185 (> (length marked-bufs) 3)
1186 (not (y-or-n-p (format "Really create a new frame for %s buffers? "
1187 (length marked-bufs)))))
1188 (unless (eq type 'other-frame)
1189 (set-buffer-modified-p nil)
1190 (delete-other-windows)
1191 (switch-to-buffer (pop marked-bufs)))
1192 (let ((height (/ (1- (if (eq type 'horizontally) (frame-width)
1193 (frame-height)))
1194 (1+ (length marked-bufs)))))
1195 (mapcar (if (eq type 'other-frame)
1196 (lambda (buf)
1197 (let ((curframe (selected-frame)))
1198 (select-frame (make-frame))
1199 (switch-to-buffer buf)
1200 (select-frame curframe)))
1201 (lambda (buf)
1202 (split-window nil height (eq type 'horizontally))
1203 (other-window 1)
1204 (switch-to-buffer buf)))
1205 marked-bufs)))))
1207 (defun ibuffer-do-view-other-frame ()
1208 "View each of the marked buffers in a separate frame."
1209 (interactive)
1210 (ibuffer-do-view t))
1212 (defsubst ibuffer-map-marked-lines (func)
1213 (prog1 (ibuffer-map-on-mark ibuffer-marked-char func)
1214 (ibuffer-redisplay t)))
1216 (defun ibuffer-shrink-to-fit (&optional owin)
1217 ;; Make sure that redisplay is performed, otherwise there can be a
1218 ;; bad interaction with code in the window-scroll-functions hook
1219 (redisplay t)
1220 (fit-window-to-buffer nil (when owin (/ (frame-height)
1221 (length (window-list (selected-frame)))))))
1223 (defun ibuffer-confirm-operation-on (operation names)
1224 "Display a buffer asking whether to perform OPERATION on NAMES."
1225 (or ibuffer-expert
1226 (if (= (length names) 1)
1227 (y-or-n-p (format "Really %s buffer %s? " operation (car names)))
1228 (let ((buf (get-buffer-create "*Ibuffer confirmation*")))
1229 (with-current-buffer buf
1230 (setq buffer-read-only nil)
1231 (erase-buffer)
1232 (ibuffer-columnize-and-insert-list names)
1233 (goto-char (point-min))
1234 (setq buffer-read-only t))
1235 (let ((windows (nreverse (window-list nil 'nomini)))
1236 lastwin)
1237 (while (window-parameter (car windows) 'window-side)
1238 (setq windows (cdr windows)))
1239 (setq lastwin (car windows))
1240 ;; Now attempt to display the buffer...
1241 (save-window-excursion
1242 (select-window lastwin)
1243 ;; The window might be too small to split; in that case,
1244 ;; try a few times to increase its size before giving up.
1245 (let ((attempts 0)
1246 (trying t))
1247 (while trying
1248 (condition-case err
1249 (progn
1250 (split-window)
1251 (setq trying nil))
1252 (error
1253 ;; Handle a failure
1254 (if (or (> (cl-incf attempts) 4)
1255 (and (stringp (cadr err))
1256 ;; This definitely falls in the
1257 ;; ghetto hack category...
1258 (not (string-match-p "too small" (cadr err)))))
1259 (signal (car err) (cdr err))
1260 (enlarge-window 3))))))
1261 (select-window (next-window))
1262 (switch-to-buffer buf)
1263 (unwind-protect
1264 (progn
1265 (fit-window-to-buffer)
1266 (y-or-n-p (format "Really %s %d buffers? "
1267 operation (length names))))
1268 (kill-buffer buf))))))))
1270 (defsubst ibuffer-map-lines-nomodify (function)
1271 "As `ibuffer-map-lines', but don't set the modification flag."
1272 (ibuffer-map-lines function t))
1274 (defun ibuffer-buffer-names-with-mark (mark)
1275 (let ((ibuffer-buffer-names-with-mark-result nil))
1276 (ibuffer-map-lines-nomodify
1277 (lambda (buf mk)
1278 (when (eq mark mk)
1279 (push (buffer-name buf)
1280 ibuffer-buffer-names-with-mark-result))))
1281 ibuffer-buffer-names-with-mark-result))
1283 (defsubst ibuffer-marked-buffer-names ()
1284 (ibuffer-buffer-names-with-mark ibuffer-marked-char))
1286 (defsubst ibuffer-deletion-marked-buffer-names ()
1287 (ibuffer-buffer-names-with-mark ibuffer-deletion-char))
1289 (defun ibuffer-count-marked-lines (&optional all)
1290 (if all
1291 (ibuffer-map-lines-nomodify
1292 (lambda (_buf mark)
1293 (not (eq mark ?\s))))
1294 (ibuffer-map-lines-nomodify
1295 (lambda (_buf mark)
1296 (eq mark ibuffer-marked-char)))))
1298 (defsubst ibuffer-count-deletion-lines ()
1299 (ibuffer-map-lines-nomodify
1300 (lambda (_buf mark)
1301 (eq mark ibuffer-deletion-char))))
1303 (defsubst ibuffer-map-deletion-lines (func)
1304 (ibuffer-map-on-mark ibuffer-deletion-char func))
1306 (defsubst ibuffer-assert-ibuffer-mode ()
1307 (cl-assert (derived-mode-p 'ibuffer-mode)))
1309 (defun ibuffer-buffer-file-name ()
1310 (cond
1311 ((buffer-file-name))
1312 ((bound-and-true-p list-buffers-directory))
1313 ((let ((dirname (and (boundp 'dired-directory)
1314 (if (stringp dired-directory)
1315 dired-directory
1316 (car dired-directory)))))
1317 (and dirname (expand-file-name dirname))))))
1319 (define-ibuffer-op ibuffer-do-save ()
1320 "Save marked buffers as with `save-buffer'."
1321 (:complex t
1322 :opstring "saved"
1323 :modifier-p :maybe)
1324 (when (buffer-modified-p buf)
1325 (if (not (with-current-buffer buf
1326 buffer-file-name))
1327 ;; handle the case where we're prompted
1328 ;; for a file name
1329 (save-window-excursion
1330 (switch-to-buffer buf)
1331 (save-buffer))
1332 (with-current-buffer buf
1333 (save-buffer))))
1336 (define-ibuffer-op ibuffer-do-toggle-modified ()
1337 "Toggle modification flag of marked buffers."
1338 (:opstring "(un)marked as modified"
1339 :modifier-p t)
1340 (set-buffer-modified-p (not (buffer-modified-p))))
1342 (define-ibuffer-op ibuffer-do-toggle-read-only (&optional arg)
1343 "Toggle read only status in marked buffers.
1344 If optional ARG is a non-negative integer, make buffers read only.
1345 If ARG is a negative integer or 0, make buffers writable.
1346 Otherwise, toggle read only status."
1347 (:opstring "toggled read only status in"
1348 :interactive "P"
1349 :modifier-p t)
1350 (read-only-mode (if (integerp arg) arg 'toggle)))
1352 (define-ibuffer-op ibuffer-do-delete ()
1353 "Kill marked buffers as with `kill-this-buffer'."
1354 (:opstring "killed"
1355 :active-opstring "kill"
1356 :dangerous t
1357 :complex t
1358 :modifier-p t)
1359 (if (kill-buffer buf)
1360 'kill
1361 nil))
1363 (define-ibuffer-op ibuffer-do-kill-on-deletion-marks ()
1364 "Kill buffers marked for deletion as with `kill-this-buffer'."
1365 (:opstring "killed"
1366 :active-opstring "kill"
1367 :dangerous t
1368 :complex t
1369 :mark :deletion
1370 :modifier-p t)
1371 (if (kill-buffer buf)
1372 'kill
1373 nil))
1375 (defun ibuffer-unmark-all (mark)
1376 "Unmark all buffers with mark MARK."
1377 (interactive "cRemove marks (RET means all):")
1378 (if (= (ibuffer-count-marked-lines t) 0)
1379 (message "No buffers marked; use 'm' to mark a buffer")
1380 (let ((fn (lambda (_buf mk)
1381 (unless (eq mk ?\s)
1382 (ibuffer-set-mark-1 ?\s)) t)))
1383 (if (eq mark ?\r)
1384 (ibuffer-map-lines fn)
1385 (ibuffer-map-on-mark mark fn))))
1386 (ibuffer-redisplay t))
1388 (defun ibuffer-unmark-all-marks ()
1389 "Remove all marks from all marked buffers in Ibuffer."
1390 (interactive)
1391 ;; hm. we could probably do this in a better fashion
1392 (ibuffer-unmark-all ?\r))
1394 (defun ibuffer-toggle-marks (&optional group)
1395 "Toggle which buffers are marked.
1396 In other words, unmarked buffers become marked, and marked buffers
1397 become unmarked.
1398 If point is on a group name, then this function operates on that
1399 group."
1400 (interactive)
1401 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
1402 (setq group it))
1403 (let ((count
1404 (ibuffer-map-lines
1405 (lambda (_buf mark)
1406 (cond ((eq mark ibuffer-marked-char)
1407 (ibuffer-set-mark-1 ?\s)
1408 nil)
1409 ((eq mark ?\s)
1410 (ibuffer-set-mark-1 ibuffer-marked-char)
1413 nil)))
1414 nil group)))
1415 (message "%s buffers marked" count))
1416 (ibuffer-redisplay t))
1418 (defun ibuffer-change-marks (&optional old new)
1419 "Change all OLD marks to NEW marks.
1420 OLD and NEW are both characters used to mark buffers."
1421 (interactive
1422 (let* ((cursor-in-echo-area t)
1423 (old (progn (message "Change (old mark): ") (read-char)))
1424 (new (progn (message "Change %c marks to (new mark): " old)
1425 (read-char))))
1426 (list old new)))
1427 (if (or (eq old ?\r) (eq new ?\r))
1428 (ding)
1429 (let ((count
1430 (ibuffer-map-lines
1431 (lambda (_buf mark)
1432 (when (eq mark old)
1433 (ibuffer-set-mark new) t)))))
1434 (message "%s marks changed" count))))
1436 (defsubst ibuffer-get-region-and-prefix ()
1437 (let ((arg (prefix-numeric-value current-prefix-arg)))
1438 (if (use-region-p) (list (region-beginning) (region-end) arg)
1439 (list nil nil arg))))
1441 (defun ibuffer-mark-forward (start end arg)
1442 "Mark the buffers in the region, or ARG buffers.
1443 If point is on a group name, this function operates on that group."
1444 (interactive (ibuffer-get-region-and-prefix))
1445 (ibuffer-mark-region-or-n-with-char start end arg ibuffer-marked-char))
1447 (defun ibuffer-unmark-forward (start end arg)
1448 "Unmark the buffers in the region, or ARG buffers.
1449 If point is on a group name, this function operates on that group."
1450 (interactive (ibuffer-get-region-and-prefix))
1451 (ibuffer-mark-region-or-n-with-char start end arg ?\s))
1453 (defun ibuffer-unmark-backward (start end arg)
1454 "Unmark the buffers in the region, or previous ARG buffers.
1455 If point is on a group name, this function operates on that group."
1456 (interactive (ibuffer-get-region-and-prefix))
1457 (ibuffer-unmark-forward start end (- arg)))
1459 (defun ibuffer-mark-region-or-n-with-char (start end arg mark-char)
1460 (if (use-region-p)
1461 (let ((cur (point)) (line-count (count-lines start end)))
1462 (goto-char start)
1463 (ibuffer-mark-interactive line-count mark-char)
1464 (goto-char cur))
1465 (ibuffer-mark-interactive arg mark-char)))
1467 (defun ibuffer-mark-interactive (arg mark &optional movement)
1468 (ibuffer-assert-ibuffer-mode)
1469 (or arg (setq arg 1))
1470 ;; deprecated movement argument
1471 (when (and movement (< movement 0))
1472 (setq arg (- arg)))
1473 (ibuffer-forward-line 0)
1474 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group-name)
1475 (progn
1476 (require 'ibuf-ext)
1477 (ibuffer-mark-on-buffer #'identity mark it))
1478 (ibuffer-forward-line 0 t)
1479 (while (> arg 0)
1480 (ibuffer-set-mark mark)
1481 (ibuffer-forward-line 1 t)
1482 (setq arg (1- arg)))
1483 (while (< arg 0)
1484 (ibuffer-forward-line -1 t)
1485 (ibuffer-set-mark mark)
1486 (setq arg (1+ arg)))))
1488 (defun ibuffer-set-mark (mark)
1489 (ibuffer-assert-ibuffer-mode)
1490 (let ((inhibit-read-only t))
1491 (ibuffer-set-mark-1 mark)
1492 (setq ibuffer-did-modification t)
1493 (ibuffer-redisplay-current)
1494 (beginning-of-line)))
1496 (defun ibuffer-set-mark-1 (mark)
1497 (let ((beg (line-beginning-position))
1498 (end (line-end-position)))
1499 (put-text-property beg end 'ibuffer-properties
1500 (list (ibuffer-current-buffer)
1501 mark))))
1503 (defun ibuffer-mark-for-delete (start end arg)
1504 "Mark for deletion the buffers in the region, or ARG buffers.
1505 If point is on a group name, this function operates on that group."
1506 (interactive (ibuffer-get-region-and-prefix))
1507 (ibuffer-mark-region-or-n-with-char start end arg ibuffer-deletion-char))
1509 (defun ibuffer-mark-for-delete-backwards (arg)
1510 "Mark for deletion the ARG previous buffers.
1511 If point is on a group name, this function operates on that group."
1512 (interactive "p")
1513 (ibuffer-mark-interactive arg ibuffer-deletion-char -1))
1515 (defun ibuffer-current-buffer (&optional must-be-live)
1516 (let ((buf (car (get-text-property (line-beginning-position)
1517 'ibuffer-properties))))
1518 (when must-be-live
1519 (if (bufferp buf)
1520 (unless (buffer-live-p buf)
1521 (error "Buffer %s has been killed; %s" buf (substitute-command-keys "use `\\[ibuffer-update]' to update")))
1522 (error "No buffer on this line")))
1523 buf))
1525 (defun ibuffer-active-formats-name ()
1526 (if (boundp 'ibuffer-filter-format-alist)
1527 (let ((ret nil))
1528 (dolist (filter ibuffer-filtering-qualifiers ret)
1529 (let ((val (assq (car filter) ibuffer-filter-format-alist)))
1530 (when val
1531 (setq ret (car filter)))))
1532 (if ret
1534 :ibuffer-formats))
1535 :ibuffer-formats))
1537 (defun ibuffer-current-formats (uncompiledp)
1538 (let* ((name (ibuffer-active-formats-name)))
1539 (ibuffer-check-formats)
1540 (if (eq name :ibuffer-formats)
1541 (if uncompiledp
1542 ibuffer-formats
1543 ibuffer-compiled-formats)
1544 (cadr (assq name
1545 (if uncompiledp
1546 ibuffer-filter-format-alist
1547 ibuffer-compiled-filter-formats))))))
1549 (defun ibuffer-current-format (&optional uncompiledp)
1550 (or ibuffer-current-format
1551 (setq ibuffer-current-format 0))
1552 (nth ibuffer-current-format (ibuffer-current-formats uncompiledp)))
1554 (defun ibuffer-expand-format-entry (form)
1555 (if (or (consp form)
1556 (symbolp form))
1557 (let ((sym (intern (concat "ibuffer-make-column-"
1558 (symbol-name (if (consp form)
1559 (car form)
1560 form))))))
1561 (unless (or (fboundp sym)
1562 (assq sym ibuffer-inline-columns))
1563 (error "Unknown column %s in ibuffer-formats" form))
1564 (let (min max align elide)
1565 (if (consp form)
1566 (setq min (or (nth 1 form) 0)
1567 max (or (nth 2 form) -1)
1568 align (or (nth 3 form) :left)
1569 elide (or (nth 4 form) nil))
1570 (setq min 0
1571 max -1
1572 align :left
1573 elide nil))
1574 (list sym min max align elide)))
1575 form))
1577 (defun ibuffer-compile-make-eliding-form (strvar elide from-end-p)
1578 (let ((ellipsis (propertize ibuffer-eliding-string 'font-lock-face 'bold)))
1579 (if elide
1580 `(if (> strlen 5)
1581 ,(if from-end-p
1582 ;; FIXME: this should probably also be using
1583 ;; `truncate-string-to-width' (Bug#24972)
1584 `(concat ,ellipsis
1585 (substring ,strvar
1586 (string-width ibuffer-eliding-string)))
1587 `(concat
1588 (truncate-string-to-width
1589 ,strvar (- strlen (string-width ,ellipsis)) nil ?.)
1590 ,ellipsis))
1591 ,strvar)
1592 strvar)))
1594 (defun ibuffer-compile-make-substring-form (strvar maxvar from-end-p)
1595 (if from-end-p
1596 ;; FIXME: not sure if this case is correct (Bug#24972)
1597 `(truncate-string-to-width str strlen (- strlen ,maxvar) nil ?\s)
1598 `(truncate-string-to-width ,strvar ,maxvar nil ?\s)))
1600 (defun ibuffer-compile-make-format-form (strvar widthform alignment)
1601 (let* ((left `(make-string tmp2 ?\s))
1602 (right `(make-string (- tmp1 tmp2) ?\s)))
1603 `(progn
1604 (setq tmp1 ,widthform
1605 tmp2 (/ tmp1 2))
1606 ,(pcase alignment
1607 (:right `(concat ,left ,right ,strvar))
1608 (:center `(concat ,left ,strvar ,right))
1609 (:left `(concat ,strvar ,left ,right))
1610 (_ (error "Invalid alignment %s" alignment))))))
1612 (defun ibuffer-compile-format (format)
1613 (let ((result nil)
1614 ;; We use these variables to keep track of which variables
1615 ;; inside the generated function we need to bind, since
1616 ;; binding variables in Emacs takes time.
1617 (vars-used ()))
1618 (dolist (form format)
1619 (push
1620 ;; Generate a form based on a particular format entry, like
1621 ;; " ", mark, or (mode 16 16 :right).
1622 (if (stringp form)
1623 ;; It's a string; all we need to do is insert it.
1624 `(insert ,form)
1625 (let* ((form (ibuffer-expand-format-entry form))
1626 (sym (nth 0 form))
1627 (min (nth 1 form))
1628 (max (nth 2 form))
1629 (align (nth 3 form))
1630 (elide (nth 4 form)))
1631 (let* ((from-end-p (when (cl-minusp min)
1632 (setq min (- min))
1634 (letbindings nil)
1635 (outforms nil)
1636 minform
1637 maxform
1638 min-used max-used strlen-used)
1639 (when (or (not (integerp min)) (>= min 0))
1640 ;; This is a complex case; they want it limited to a
1641 ;; minimum size.
1642 (setq min-used t)
1643 (setq strlen-used t)
1644 (setq vars-used '(str strlen tmp1 tmp2))
1645 ;; Generate code to limit the string to a minimum size.
1646 (setq minform `(progn
1647 (setq str
1648 ,(ibuffer-compile-make-format-form
1649 'str
1650 `(- ,(if (integerp min)
1652 'min)
1653 strlen)
1654 align)))))
1655 (when (or (not (integerp max)) (> max 0))
1656 (setq max-used t)
1657 (cl-pushnew 'str vars-used)
1658 ;; Generate code to limit the string to a maximum size.
1659 (setq maxform `(progn
1660 (setq str
1661 ,(ibuffer-compile-make-substring-form
1662 'str
1663 (if (integerp max)
1665 'max)
1666 from-end-p))
1667 (setq strlen (string-width str))
1668 (setq str
1669 ,(ibuffer-compile-make-eliding-form
1670 'str elide from-end-p)))))
1671 ;; Now, put these forms together with the rest of the code.
1672 (let ((callform
1673 ;; Is this an "inline" column? This means we have
1674 ;; to get the code from the
1675 ;; `ibuffer-inline-columns' alist and insert it
1676 ;; into our generated code. Otherwise, we just
1677 ;; generate a call to the column function.
1678 (ibuffer-aif (assq sym ibuffer-inline-columns)
1679 (nth 1 it)
1680 `(or (,sym buffer mark) "")))
1681 ;; You're not expected to understand this. Hell, I
1682 ;; don't even understand it, and I wrote it five
1683 ;; minutes ago.
1684 (insertgenfn
1685 (if (get sym 'ibuffer-column-summarizer)
1686 ;; I really, really wish Emacs Lisp had closures.
1687 ;; FIXME: Elisp does have them now.
1688 (lambda (arg sym)
1689 `(insert
1690 (let ((ret ,arg))
1691 (put ',sym 'ibuffer-column-summary
1692 (cons ret (get ',sym
1693 'ibuffer-column-summary)))
1694 ret)))
1695 (lambda (arg _sym)
1696 `(insert ,arg))))
1697 (mincompform `(< strlen ,(if (integerp min)
1699 'min)))
1700 (maxcompform `(> strlen ,(if (integerp max)
1702 'max))))
1703 (if (or min-used max-used)
1704 ;; The complex case, where we have to limit the
1705 ;; form to a maximum or minimum size.
1706 (progn
1707 (when (and min-used (not (integerp min)))
1708 (push `(min ,min) letbindings))
1709 (when (and max-used (not (integerp max)))
1710 (push `(max ,max) letbindings))
1711 (push
1712 (if (and min-used max-used)
1713 `(if ,mincompform
1714 ,minform
1715 (if ,maxcompform
1716 ,maxform))
1717 (if min-used
1718 `(when ,mincompform
1719 ,minform)
1720 `(when ,maxcompform
1721 ,maxform)))
1722 outforms)
1723 (push `(setq str ,callform
1724 ,@(when strlen-used
1725 `(strlen (string-width str))))
1726 outforms)
1727 (setq outforms
1728 (append outforms
1729 (list (funcall insertgenfn 'str sym)))))
1730 ;; The simple case; just insert the string.
1731 (push (funcall insertgenfn callform sym) outforms))
1732 ;; Finally, return a `let' form which binds the
1733 ;; variables in `letbindings', and contains all the
1734 ;; code in `outforms'.
1735 `(let ,letbindings
1736 ,@outforms)))))
1737 result))
1738 ;; We don't want to unconditionally load the byte-compiler.
1739 (funcall (if (or ibuffer-always-compile-formats
1740 (featurep 'bytecomp))
1741 #'byte-compile
1742 #'identity)
1743 ;; Here, we actually create a lambda form which
1744 ;; inserts all the generated forms for each entry
1745 ;; in the format string.
1746 `(lambda (buffer mark)
1747 (let ,vars-used
1748 ,@(nreverse result))))))
1750 (defun ibuffer-recompile-formats ()
1751 "Recompile `ibuffer-formats'."
1752 (interactive)
1753 (setq ibuffer-compiled-formats
1754 (mapcar #'ibuffer-compile-format ibuffer-formats))
1755 (when (boundp 'ibuffer-filter-format-alist)
1756 (setq ibuffer-compiled-filter-formats
1757 (mapcar (lambda (entry)
1758 (cons (car entry)
1759 (mapcar (lambda (formats)
1760 (mapcar #'ibuffer-compile-format formats))
1761 (cdr entry))))
1762 ibuffer-filter-format-alist))))
1764 (defun ibuffer-clear-summary-columns (format)
1765 (dolist (form format)
1766 (when (and (consp form)
1767 (get (car form) 'ibuffer-column-summarizer))
1768 (put (car form) 'ibuffer-column-summary nil))))
1770 (defun ibuffer-check-formats ()
1771 (when (null ibuffer-formats)
1772 (error "No formats!"))
1773 (let ((ext-loaded (featurep 'ibuf-ext)))
1774 (when (or (null ibuffer-compiled-formats)
1775 (null ibuffer-cached-formats)
1776 (not (eq ibuffer-cached-formats ibuffer-formats))
1777 (null ibuffer-cached-eliding-string)
1778 (not (equal ibuffer-cached-eliding-string ibuffer-eliding-string))
1779 (and ext-loaded
1780 (not (eq ibuffer-cached-filter-formats
1781 ibuffer-filter-format-alist))
1782 (and ibuffer-filter-format-alist
1783 (null ibuffer-compiled-filter-formats))))
1784 (message "Formats have changed, recompiling...")
1785 (ibuffer-recompile-formats)
1786 (setq ibuffer-cached-formats ibuffer-formats
1787 ibuffer-cached-eliding-string ibuffer-eliding-string)
1788 (when ext-loaded
1789 (setq ibuffer-cached-filter-formats ibuffer-filter-format-alist))
1790 (message "Formats have changed, recompiling...done"))))
1792 (defvar ibuffer-inline-columns nil)
1794 (defface ibuffer-locked-buffer
1795 '((((background dark)) (:foreground "RosyBrown"))
1796 (t (:foreground "brown4")))
1797 "*Face used for locked buffers in Ibuffer."
1798 :version "26.1"
1799 :group 'ibuffer
1800 :group 'font-lock-highlighting-faces)
1801 (defvar ibuffer-locked-buffer 'ibuffer-locked-buffer)
1803 (define-ibuffer-column mark (:name " " :inline t)
1804 (string mark))
1806 (define-ibuffer-column read-only (:name "R" :inline t)
1807 (if buffer-read-only
1808 (string ibuffer-read-only-char)
1809 " "))
1811 (define-ibuffer-column locked
1812 (:name "L" :inline t :props ('font-lock-face 'ibuffer-locked-buffer))
1813 (if (and (boundp 'emacs-lock-mode) emacs-lock-mode)
1814 (string ibuffer-locked-char)
1815 " "))
1817 (define-ibuffer-column modified (:name "M" :inline t)
1818 (if (buffer-modified-p)
1819 (string ibuffer-modified-char)
1820 " "))
1822 (define-ibuffer-column name
1823 (:inline t
1824 :header-mouse-map ibuffer-name-header-map
1825 :props
1826 ('mouse-face 'highlight 'keymap ibuffer-name-map
1827 'ibuffer-name-column t
1828 'help-echo '(if tooltip-mode
1829 "mouse-1: mark this buffer\nmouse-2: select this buffer\nmouse-3: operate on this buffer"
1830 "mouse-1: mark buffer mouse-2: select buffer mouse-3: operate"))
1831 :summarizer
1832 (lambda (strings)
1833 (let ((bufs (length strings)))
1834 (cond ((zerop bufs) "No buffers")
1835 ((= 1 bufs) "1 buffer")
1836 (t (format "%s buffers" bufs))))))
1837 (let ((string (propertize (buffer-name)
1838 'font-lock-face
1839 (ibuffer-buffer-name-face buffer mark))))
1840 (if (not (seq-position string ?\n))
1841 string
1842 (replace-regexp-in-string
1843 "\n" (propertize "^J" 'font-lock-face 'escape-glyph) string))))
1845 (define-ibuffer-column size
1846 (:inline t
1847 :header-mouse-map ibuffer-size-header-map
1848 :summarizer
1849 (lambda (column-strings)
1850 (let ((total 0))
1851 (dolist (string column-strings)
1852 (setq total
1853 ;; like, ewww ...
1854 (+ (float (string-to-number string))
1855 total)))
1856 (format "%.0f" total))))
1857 (format "%s" (buffer-size)))
1859 (define-ibuffer-column mode
1860 (:inline t
1861 :header-mouse-map ibuffer-mode-header-map
1862 :props
1863 ('mouse-face 'highlight
1864 'keymap ibuffer-mode-name-map
1865 'help-echo "mouse-2: filter by this mode"))
1866 (format-mode-line mode-name nil nil (current-buffer)))
1868 (define-ibuffer-column process
1869 (:summarizer
1870 (lambda (strings)
1871 (let ((total (length (delete "" strings))))
1872 (cond ((zerop total) "No processes")
1873 ((= 1 total) "1 process")
1874 (t (format "%d processes" total))))))
1875 (ibuffer-aif (get-buffer-process buffer)
1876 (format "(%s %s)" it (process-status it))
1877 ""))
1879 (define-ibuffer-column filename
1880 (:summarizer
1881 (lambda (strings)
1882 (let ((total (length (delete "" strings))))
1883 (cond ((zerop total) "No files")
1884 ((= 1 total) "1 file")
1885 (t (format "%d files" total))))))
1886 (let ((directory-abbrev-alist ibuffer-directory-abbrev-alist))
1887 (abbreviate-file-name
1888 (or (ibuffer-buffer-file-name) ""))))
1890 (define-ibuffer-column filename-and-process
1891 (:name "Filename/Process"
1892 :header-mouse-map ibuffer-filename/process-header-map
1893 :summarizer
1894 (lambda (strings)
1895 (setq strings (delete "" strings))
1896 (let ((procs 0)
1897 (files 0))
1898 (dolist (string strings)
1899 (if (string-match "\\(?:\\`([[:ascii:]]+)\\)" string)
1900 (progn (setq procs (1+ procs))
1901 (if (< (match-end 0) (length string))
1902 (setq files (1+ files))))
1903 (setq files (1+ files))))
1904 (concat (cond ((zerop files) "No files")
1905 ((= 1 files) "1 file")
1906 (t (format "%d files" files)))
1907 ", "
1908 (cond ((zerop procs) "no processes")
1909 ((= 1 procs) "1 process")
1910 (t (format "%d processes" procs)))))))
1911 (let ((proc (get-buffer-process buffer))
1912 (filename (ibuffer-make-column-filename buffer mark)))
1913 (if proc
1914 (concat (propertize (format "(%s %s)" proc (process-status proc))
1915 'font-lock-face 'italic)
1916 (if (> (length filename) 0)
1917 (format " %s" filename)
1918 ""))
1919 filename)))
1921 (defun ibuffer-format-column (str width alignment)
1922 (let ((left (make-string (/ width 2) ?\s))
1923 (right (make-string (- width (/ width 2)) ?\s)))
1924 (pcase alignment
1925 (:right (concat left right str))
1926 (:center (concat left str right))
1927 (_ (concat str left right)))))
1929 (defun ibuffer-buffer-name-face (buf mark)
1930 (cond ((eq mark ibuffer-marked-char)
1931 ibuffer-marked-face)
1932 ((eq mark ibuffer-deletion-char)
1933 ibuffer-deletion-face)
1935 (let ((level -1)
1936 result)
1937 (dolist (e ibuffer-fontification-alist result)
1938 (when (and (> (car e) level)
1939 (with-current-buffer buf
1940 (eval (nth 1 e))))
1941 (setq level (car e)
1942 result (nth 2 e))))))))
1944 (defun ibuffer-insert-buffer-line (buffer mark format)
1945 "Insert a line describing BUFFER and MARK using FORMAT."
1946 (ibuffer-assert-ibuffer-mode)
1947 (let ((beg (point)))
1948 (funcall format buffer mark)
1949 (put-text-property beg (point) 'ibuffer-properties (list buffer mark)))
1950 (insert "\n"))
1952 ;; This function knows a bit too much of the internals. It would be
1953 ;; nice if it was all abstracted away.
1954 (defun ibuffer-redisplay-current ()
1955 (ibuffer-assert-ibuffer-mode)
1956 (when (eobp)
1957 (forward-line -1))
1958 (beginning-of-line)
1959 (let ((curformat (mapcar #'ibuffer-expand-format-entry
1960 (ibuffer-current-format t))))
1961 (ibuffer-clear-summary-columns curformat)
1962 (let ((buf (ibuffer-current-buffer)))
1963 (when buf
1964 (let ((mark (ibuffer-current-mark)))
1965 (save-excursion
1966 (delete-region (point) (1+ (line-end-position)))
1967 (ibuffer-insert-buffer-line
1968 buf mark
1969 (ibuffer-current-format)))
1970 (when ibuffer-shrink-to-minimum-size
1971 (ibuffer-shrink-to-fit)))))))
1973 (defun ibuffer-map-on-mark (mark func)
1974 (ibuffer-map-lines
1975 (lambda (buf mk)
1976 (if (eq mark mk)
1977 (funcall func buf mark)
1978 nil))))
1980 (defun ibuffer-map-lines (function &optional nomodify group)
1981 "Call FUNCTION for each buffer.
1982 Set the ibuffer modification flag unless NOMODIFY is non-nil.
1984 If optional argument GROUP is non-nil, then only call FUNCTION on
1985 buffers in filtering group GROUP.
1987 FUNCTION is called with two arguments:
1988 the buffer object itself and the current mark symbol."
1989 (ibuffer-assert-ibuffer-mode)
1990 (ibuffer-forward-line 0)
1991 (let* ((orig-target-line (1+ (count-lines (save-excursion
1992 (goto-char (point-min))
1993 (ibuffer-forward-line 0)
1994 (point))
1995 (point))))
1996 (target-line-offset orig-target-line)
1997 (ibuffer-map-lines-total 0)
1998 (ibuffer-map-lines-count 0))
1999 (unwind-protect
2000 (progn
2001 (setq buffer-read-only nil)
2002 (goto-char (point-min))
2003 (ibuffer-forward-line 0 t)
2004 (while (and (not (eobp))
2005 (not (get-text-property (point) 'ibuffer-summary))
2006 (progn
2007 (ibuffer-forward-line 0 t)
2008 (and (not (eobp))
2009 (not (get-text-property (point) 'ibuffer-summary)))))
2010 (let ((result
2011 (if (buffer-live-p (ibuffer-current-buffer))
2012 (when (or (null group)
2013 (ibuffer-aif (get-text-property (point) 'ibuffer-filter-group)
2014 (equal group it)))
2015 (save-excursion
2016 (funcall function
2017 (ibuffer-current-buffer)
2018 (ibuffer-current-mark))))
2019 ;; Kill the line if the buffer is dead
2020 'kill)))
2021 ;; A given mapping function should return:
2022 ;; nil if it chose not to affect the buffer
2023 ;; `kill' means the remove line from the buffer list
2024 ;; t otherwise
2025 (cl-incf ibuffer-map-lines-total)
2026 (cond ((null result)
2027 (forward-line 1))
2028 ((eq result 'kill)
2029 (delete-region (line-beginning-position)
2030 (1+ (line-end-position)))
2031 (cl-incf ibuffer-map-lines-count)
2032 (when (< ibuffer-map-lines-total
2033 orig-target-line)
2034 (cl-decf target-line-offset)))
2036 (cl-incf ibuffer-map-lines-count)
2037 (forward-line 1)))))
2038 ibuffer-map-lines-count)
2039 (progn
2040 (setq buffer-read-only t)
2041 (unless nomodify
2042 (set-buffer-modified-p nil))
2043 (goto-char (point-min))
2044 (ibuffer-forward-line 0)
2045 (ibuffer-forward-line (1- target-line-offset))))))
2047 ;; Return buffers around current line.
2048 (defun ibuffer--near-buffers (n)
2049 (delq nil
2050 (mapcar
2051 (lambda (x)
2052 (car (get-text-property
2053 (line-beginning-position (if (natnump n) x (- (1- x))))
2054 'ibuffer-properties)))
2055 (number-sequence 1 (abs n)))))
2057 (defun ibuffer-get-marked-buffers ()
2058 "Return a list of buffer objects currently marked."
2059 (delq nil
2060 (mapcar (lambda (e)
2061 (when (eq (cdr e) ibuffer-marked-char)
2062 (car e)))
2063 (ibuffer-current-state-list))))
2065 (defun ibuffer-current-state-list (&optional pos)
2066 "Return a list like (BUF . MARK) of all buffers in an ibuffer.
2067 If POS is non-nil, return a list like (BUF MARK POINT), where POINT is
2068 the value of point at the beginning of the line for that buffer."
2069 (let ((ibuffer-current-state-list-tmp '()))
2070 ;; ah, if only we had closures. I bet this will mysteriously
2071 ;; break later. Don't blame me.
2072 (if pos
2073 (ibuffer-map-lines-nomodify
2074 (lambda (buf mark)
2075 (when (buffer-live-p buf)
2076 (push (list buf mark (point)) ibuffer-current-state-list-tmp))))
2077 (ibuffer-map-lines-nomodify
2078 (lambda (buf mark)
2079 (when (buffer-live-p buf)
2080 (push (cons buf mark) ibuffer-current-state-list-tmp)))))
2081 (nreverse ibuffer-current-state-list-tmp)))
2083 (defun ibuffer-current-buffers-with-marks (curbufs)
2084 "Return a list like (BUF . MARK) of all open buffers."
2085 (let ((bufs (ibuffer-current-state-list)))
2086 (mapcar (lambda (buf) (let ((e (assq buf bufs)))
2087 (if e
2089 (cons buf ?\s))))
2090 curbufs)))
2092 (defun ibuffer-buf-matches-predicates (buf predicates)
2093 (let ((hit nil)
2094 (name (buffer-name buf)))
2095 (dolist (pred predicates)
2096 (when (if (stringp pred)
2097 (string-match pred name)
2098 (funcall pred buf))
2099 (setq hit t)))
2100 hit))
2102 (defun ibuffer-filter-buffers (ibuffer-buf last bmarklist all)
2103 (let ((ext-loaded (featurep 'ibuf-ext)))
2104 (delq nil
2105 (mapcar
2106 ;; element should be like (BUFFER . MARK)
2107 (lambda (e)
2108 (let* ((buf (car e)))
2109 (when
2110 ;; This takes precedence over anything else
2111 (or (and ibuffer-always-show-last-buffer
2112 (eq last buf))
2113 (funcall (if ext-loaded
2114 #'ibuffer-ext-visible-p
2115 #'ibuffer-visible-p)
2116 buf all ibuffer-buf))
2117 e)))
2118 bmarklist))))
2120 (defun ibuffer-visible-p (buf all &optional ibuffer-buf)
2121 (and (or all
2122 (not
2123 (ibuffer-buf-matches-predicates buf ibuffer-maybe-show-predicates)))
2124 (or ibuffer-view-ibuffer
2125 (and ibuffer-buf
2126 (not (eq ibuffer-buf buf))))))
2128 ;; This function is a special case; it's not defined by
2129 ;; `define-ibuffer-sorter'.
2130 (defun ibuffer-do-sort-by-recency ()
2131 "Sort the buffers by last view time."
2132 (interactive)
2133 (setq ibuffer-sorting-mode 'recency)
2134 (when (eq ibuffer-last-sorting-mode 'recency)
2135 (setq ibuffer-sorting-reversep (not ibuffer-sorting-reversep)))
2136 (ibuffer-update nil t)
2137 (setq ibuffer-last-sorting-mode 'recency))
2139 (defun ibuffer-update-format ()
2140 (when (null ibuffer-current-format)
2141 (setq ibuffer-current-format 0))
2142 (when (null ibuffer-formats)
2143 (error "Ibuffer error: no formats!")))
2145 (defun ibuffer-switch-format ()
2146 "Switch the current display format."
2147 (interactive)
2148 (ibuffer-assert-ibuffer-mode)
2149 (unless (consp ibuffer-formats)
2150 (error "Ibuffer error: No formats!"))
2151 (setq ibuffer-current-format
2152 (if (>= ibuffer-current-format (1- (length (ibuffer-current-formats nil))))
2154 (1+ ibuffer-current-format)))
2155 (ibuffer-update-format)
2156 (ibuffer-redisplay t))
2158 (defun ibuffer-update-title-and-summary (format)
2159 (ibuffer-assert-ibuffer-mode)
2160 ;; Don't do funky font-lock stuff here
2161 (let ((inhibit-modification-hooks t))
2162 (if (get-text-property (point-min) 'ibuffer-title)
2163 (delete-region (point-min)
2164 (next-single-property-change
2165 (point-min) 'ibuffer-title)))
2166 (goto-char (point-min))
2167 (add-text-properties
2168 (point)
2169 (progn
2170 (let ((opos (point)))
2171 ;; Insert the title names.
2172 (dolist (element format)
2173 (insert
2174 (if (stringp element)
2175 element
2176 (pcase-let ((`(,sym ,min ,_max ,align) element))
2177 ;; Ignore a negative min when we're inserting the title
2178 (when (cl-minusp min)
2179 (setq min (- min)))
2180 (let* ((name (or (get sym 'ibuffer-column-name)
2181 (error "Unknown column %s in ibuffer-formats" sym)))
2182 (len (length name))
2183 (hmap (get sym 'header-mouse-map))
2184 (strname (if (< len min)
2185 (ibuffer-format-column name
2186 (- min len)
2187 align)
2188 name)))
2189 (when hmap
2190 (setq
2191 strname
2192 (propertize strname 'mouse-face 'highlight 'keymap hmap)))
2193 strname)))))
2194 (add-text-properties opos (point) `(ibuffer-title-header t))
2195 (insert "\n")
2196 ;; Add the underlines
2197 (let ((str (save-excursion
2198 (forward-line -1)
2199 (beginning-of-line)
2200 (buffer-substring (point) (line-end-position)))))
2201 (apply #'insert (mapcar
2202 (lambda (c)
2203 (if (not (or (eq c ?\s)
2204 (eq c ?\n)))
2206 ?\s))
2207 str)))
2208 (insert "\n"))
2209 (point))
2210 `(ibuffer-title t font-lock-face ,ibuffer-title-face))
2211 ;; Now, insert the summary columns.
2212 (goto-char (point-max))
2213 (if (get-text-property (1- (point-max)) 'ibuffer-summary)
2214 (delete-region (previous-single-property-change
2215 (point-max) 'ibuffer-summary)
2216 (point-max)))
2217 (if ibuffer-display-summary
2218 (add-text-properties
2219 (point)
2220 (progn
2221 (insert "\n")
2222 (dolist (element format)
2223 (insert
2224 (if (stringp element)
2225 (make-string (length element) ?\s)
2226 (pcase-let ((`(,sym ,min ,_max ,align) element))
2227 ;; Ignore a negative min when we're inserting the title.
2228 (when (cl-minusp min)
2229 (setq min (- min)))
2230 (let* ((summary
2231 (if (get sym 'ibuffer-column-summarizer)
2232 (funcall (get sym 'ibuffer-column-summarizer)
2233 (get sym 'ibuffer-column-summary))
2234 (make-string
2235 (length (get sym 'ibuffer-column-name))
2236 ?\s)))
2237 (len (length summary)))
2238 (if (< len min)
2239 (ibuffer-format-column summary
2240 (- min len)
2241 align)
2242 summary))))))
2243 (point))
2244 `(ibuffer-summary t)))))
2247 (defun ibuffer-redisplay (&optional silent)
2248 "Redisplay the current list of buffers.
2249 This does not show new buffers; use `ibuffer-update' for that.
2251 If optional arg SILENT is non-nil, do not display progress messages."
2252 (interactive)
2253 (ibuffer-forward-line 0)
2254 (unless silent
2255 (message "Redisplaying current buffer list..."))
2256 (let ((blist (ibuffer-current-state-list)))
2257 (when (and (null blist)
2258 (featurep 'ibuf-ext)
2259 (or ibuffer-filtering-qualifiers ibuffer-hidden-filter-groups))
2260 (message "No buffers! (note: filtering in effect)"))
2261 (ibuffer-redisplay-engine blist t)
2262 (unless silent
2263 (message "Redisplaying current buffer list...done"))
2264 (ibuffer-forward-line 0)))
2266 (defun ibuffer-update (arg &optional silent)
2267 "Regenerate the list of all buffers.
2269 Prefix arg non-nil means to toggle whether buffers that match
2270 `ibuffer-maybe-show-predicates' should be displayed.
2272 If optional arg SILENT is non-nil, do not display progress messages."
2273 (interactive "P")
2274 (if arg
2275 (setq ibuffer-display-maybe-show-predicates
2276 (not ibuffer-display-maybe-show-predicates)))
2277 (ibuffer-forward-line 0)
2278 (let* ((bufs (buffer-list))
2279 (blist (ibuffer-filter-buffers
2280 (current-buffer)
2281 (if (and
2282 (cadr bufs)
2283 (eq ibuffer-always-show-last-buffer
2284 :nomini)
2285 (minibufferp (cadr bufs)))
2286 (nth 2 bufs)
2287 (cadr bufs))
2288 (ibuffer-current-buffers-with-marks bufs)
2289 ibuffer-display-maybe-show-predicates)))
2290 (and (null blist)
2291 (featurep 'ibuf-ext)
2292 ibuffer-filtering-qualifiers
2293 (message "No buffers! (note: filtering in effect)"))
2294 (unless silent
2295 (message "Updating buffer list..."))
2296 (ibuffer-redisplay-engine blist arg)
2297 (unless silent
2298 (message "Updating buffer list...done")))
2299 (if (eq ibuffer-shrink-to-minimum-size 'onewindow)
2300 (ibuffer-shrink-to-fit t)
2301 (when ibuffer-shrink-to-minimum-size
2302 (ibuffer-shrink-to-fit)))
2303 (ibuffer-forward-line 0)
2304 ;; I tried to update this automatically from the mode-line-process format,
2305 ;; but changing nil-ness of header-line-format while computing
2306 ;; mode-line-format is asking a bit too much it seems. --Stef
2307 (setq header-line-format
2308 (and ibuffer-use-header-line
2309 ibuffer-filtering-qualifiers
2310 ibuffer-header-line-format)))
2312 (defun ibuffer-sort-bufferlist (bmarklist)
2313 (unless ibuffer-sorting-functions-alist
2314 ;; make sure the sorting functions are loaded
2315 (require 'ibuf-ext))
2316 (let* ((sortdat (assq ibuffer-sorting-mode
2317 ibuffer-sorting-functions-alist))
2318 (func (nth 2 sortdat)))
2319 (let ((result
2320 ;; actually sort the buffers
2321 (if (and sortdat func)
2322 (sort bmarklist func)
2323 bmarklist)))
2324 ;; perhaps reverse the sorted buffer list
2325 (if ibuffer-sorting-reversep
2326 (nreverse result)
2327 result))))
2329 (defun ibuffer-insert-filter-group (name display-name filter-string format bmarklist)
2330 (add-text-properties
2331 (point)
2332 (progn
2333 (insert "[ " display-name " ]")
2334 (point))
2335 `(ibuffer-filter-group-name
2336 ,name
2337 font-lock-face ,ibuffer-filter-group-name-face
2338 keymap ,ibuffer-mode-filter-group-map
2339 mouse-face highlight
2340 help-echo ,(let ((echo '(if tooltip-mode
2341 "mouse-1: toggle marks in this group\nmouse-2: hide/show this filtering group"
2342 "mouse-1: toggle marks mouse-2: hide/show")))
2343 (if (> (length filter-string) 0)
2344 `(concat ,filter-string
2345 (if tooltip-mode "\n" " ")
2346 ,echo)
2347 echo))))
2348 (insert "\n")
2349 (when bmarklist
2350 (put-text-property
2351 (point)
2352 (progn
2353 (dolist (entry bmarklist)
2354 (ibuffer-insert-buffer-line (car entry) (cdr entry) format))
2355 (point))
2356 'ibuffer-filter-group
2357 name)))
2359 (defun ibuffer-redisplay-engine (bmarklist &optional _ignore)
2360 (ibuffer-assert-ibuffer-mode)
2361 (let* ((--ibuffer-insert-buffers-and-marks-format
2362 (ibuffer-current-format))
2363 (--ibuffer-expanded-format (mapcar #'ibuffer-expand-format-entry
2364 (ibuffer-current-format t)))
2365 (orig (count-lines (point-min) (point)))
2366 ;; Inhibit font-lock caching tricks, since we're modifying the
2367 ;; entire buffer at once
2368 (inhibit-modification-hooks t)
2369 (ext-loaded (featurep 'ibuf-ext))
2370 (bgroups (if ext-loaded
2371 (ibuffer-generate-filter-groups bmarklist)
2372 (list (cons "Default" bmarklist)))))
2373 (ibuffer-clear-summary-columns --ibuffer-expanded-format)
2374 (unwind-protect
2375 (progn
2376 (setq buffer-read-only nil)
2377 (erase-buffer)
2378 (ibuffer-update-format)
2379 (dolist (group (nreverse bgroups))
2380 (let* ((name (car group))
2381 (disabled (and ext-loaded
2382 (member name ibuffer-hidden-filter-groups)))
2383 (bmarklist (cdr group)))
2384 (unless (and (null bmarklist)
2385 (not disabled)
2386 ext-loaded
2387 (null ibuffer-show-empty-filter-groups))
2388 (ibuffer-insert-filter-group
2389 name
2390 (if disabled (concat name " ...") name)
2391 (if ext-loaded
2392 (ibuffer-format-filter-group-data name)
2394 --ibuffer-insert-buffers-and-marks-format
2395 (if disabled
2397 (ibuffer-sort-bufferlist bmarklist))))))
2398 (ibuffer-update-title-and-summary --ibuffer-expanded-format))
2399 (setq buffer-read-only t)
2400 (set-buffer-modified-p ibuffer-did-modification)
2401 (setq ibuffer-did-modification nil)
2402 (goto-char (point-min))
2403 (forward-line orig))))
2405 ;;;###autoload
2406 (defun ibuffer-list-buffers (&optional files-only)
2407 "Display a list of buffers, in another window.
2408 If optional argument FILES-ONLY is non-nil, then add a filter for
2409 buffers which are visiting a file."
2410 (interactive "P")
2411 (ibuffer t nil (when files-only
2412 '((filename . ".*"))) t))
2414 ;;;###autoload
2415 (defun ibuffer-other-window (&optional files-only)
2416 "Like `ibuffer', but displayed in another window by default.
2417 If optional argument FILES-ONLY is non-nil, then add a filter for
2418 buffers which are visiting a file."
2419 (interactive "P")
2420 (ibuffer t nil (when files-only
2421 '((filename . ".*")))))
2423 ;;;###autoload
2424 (defun ibuffer (&optional other-window-p name qualifiers noselect
2425 shrink filter-groups formats)
2426 "Begin using Ibuffer to edit a list of buffers.
2427 Type `h' after entering ibuffer for more information.
2429 All arguments are optional.
2430 OTHER-WINDOW-P says to use another window.
2431 NAME specifies the name of the buffer (defaults to \"*Ibuffer*\").
2432 QUALIFIERS is an initial set of filtering qualifiers to use;
2433 see `ibuffer-filtering-qualifiers'.
2434 NOSELECT means don't select the Ibuffer buffer.
2435 SHRINK means shrink the buffer to minimal size. The special
2436 value `onewindow' means always use another window.
2437 FILTER-GROUPS is an initial set of filtering groups to use;
2438 see `ibuffer-filter-groups'.
2439 FORMATS is the value to use for `ibuffer-formats'.
2440 If specified, then the variable `ibuffer-formats' will have
2441 that value locally in this buffer."
2442 (interactive "P")
2443 (when ibuffer-use-other-window
2444 (setq other-window-p t))
2445 (let ((buf (get-buffer-create (or name "*Ibuffer*"))))
2446 (if other-window-p
2447 (or (and noselect (display-buffer buf t))
2448 (pop-to-buffer buf t))
2449 (funcall (if noselect #'display-buffer #'switch-to-buffer) buf))
2450 (with-current-buffer buf
2451 (save-selected-window
2452 ;; We switch to the buffer's window in order to be able
2453 ;; to modify the value of point
2454 (select-window (get-buffer-window buf 0))
2455 (or (derived-mode-p 'ibuffer-mode)
2456 (ibuffer-mode))
2457 (when shrink
2458 (setq ibuffer-shrink-to-minimum-size shrink))
2459 (when qualifiers
2460 (require 'ibuf-ext)
2461 (setq ibuffer-filtering-qualifiers qualifiers))
2462 (when filter-groups
2463 (require 'ibuf-ext)
2464 (setq ibuffer-filter-groups filter-groups))
2465 (when formats
2466 (set (make-local-variable 'ibuffer-formats) formats))
2467 (ibuffer-update nil)
2468 ;; Skip the group name by default.
2469 (ibuffer-forward-line 0 t)
2470 (unwind-protect
2471 (progn
2472 (setq buffer-read-only nil)
2473 (run-hooks 'ibuffer-hook))
2474 (setq buffer-read-only t))
2475 (unless ibuffer-expert
2476 (message "Commands: m, u, t, RET, g, k, S, D, Q; q to quit; h for help"))))))
2478 ;;;###autoload
2479 (defun ibuffer-jump (&optional other-window)
2480 "Call Ibuffer and set point at the line listing the current buffer.
2481 If optional arg OTHER-WINDOW is non-nil, then use another window."
2482 (interactive "P")
2483 (let ((name (buffer-name)))
2484 (ibuffer other-window)
2485 (ignore-errors (ibuffer-jump-to-buffer name))))
2487 (put 'ibuffer-mode 'mode-class 'special)
2488 (define-derived-mode ibuffer-mode special-mode "IBuffer"
2489 "A major mode for viewing a list of buffers.
2490 In Ibuffer, you can conveniently perform many operations on the
2491 currently open buffers, in addition to filtering your view to a
2492 particular subset of them, and sorting by various criteria.
2494 Operations on marked buffers:
2495 \\<ibuffer-mode-map>
2496 `\\[ibuffer-do-save]' - Save the marked buffers
2497 `\\[ibuffer-do-view]' - View the marked buffers in this frame.
2498 `\\[ibuffer-do-view-other-frame]' - View the marked buffers in another frame.
2499 `\\[ibuffer-do-revert]' - Revert the marked buffers.
2500 `\\[ibuffer-do-toggle-read-only]' - Toggle read-only state of marked buffers.
2501 `\\[ibuffer-do-delete]' - Kill the marked buffers.
2502 `\\[ibuffer-do-isearch]' - Do incremental search in the marked buffers.
2503 `\\[ibuffer-do-isearch-regexp]' - Isearch for regexp in the marked buffers.
2504 `\\[ibuffer-do-replace-regexp]' - Replace by regexp in each of the marked
2505 buffers.
2506 `\\[ibuffer-do-query-replace]' - Query replace in each of the marked buffers.
2507 `\\[ibuffer-do-query-replace-regexp]' - As above, with a regular expression.
2508 `\\[ibuffer-do-print]' - Print the marked buffers.
2509 `\\[ibuffer-do-occur]' - List lines in all marked buffers which match
2510 a given regexp (like the function `occur').
2511 `\\[ibuffer-do-shell-command-pipe]' - Pipe the contents of the marked
2512 buffers to a shell command.
2513 `\\[ibuffer-do-shell-command-pipe-replace]' - Replace the contents of the marked
2514 buffers with the output of a shell command.
2515 `\\[ibuffer-do-shell-command-file]' - Run a shell command with the
2516 buffer's file as an argument.
2517 `\\[ibuffer-do-eval]' - Evaluate a form in each of the marked buffers. This
2518 is a very flexible command. For example, if you want to make all
2519 of the marked buffers read only, try using (read-only-mode 1) as
2520 the input form.
2521 `\\[ibuffer-do-view-and-eval]' - As above, but view each buffer while the form
2522 is evaluated.
2523 `\\[ibuffer-do-kill-lines]' - Remove the marked lines from the *Ibuffer* buffer,
2524 but don't kill the associated buffer.
2525 `\\[ibuffer-do-kill-on-deletion-marks]' - Kill all buffers marked for deletion.
2527 Marking commands:
2529 `\\[ibuffer-mark-forward]' - Mark the buffer at point.
2530 `\\[ibuffer-toggle-marks]' - Unmark all currently marked buffers, and mark
2531 all unmarked buffers.
2532 `\\[ibuffer-change-marks]' - Change the mark used on marked buffers.
2533 `\\[ibuffer-unmark-forward]' - Unmark the buffer at point.
2534 `\\[ibuffer-unmark-backward]' - Unmark the buffer at point, and move to the
2535 previous line.
2536 `\\[ibuffer-unmark-all]' - Unmark buffers marked with MARK.
2537 `\\[ibuffer-unmark-all-marks]' - Unmark all marked buffers.
2538 `\\[ibuffer-mark-by-mode]' - Mark buffers by major mode.
2539 `\\[ibuffer-mark-unsaved-buffers]' - Mark all \"unsaved\" buffers.
2540 This means that the buffer is modified, and has an associated file.
2541 `\\[ibuffer-mark-modified-buffers]' - Mark all modified buffers,
2542 regardless of whether or not they have an associated file.
2543 `\\[ibuffer-mark-special-buffers]' - Mark all buffers whose name begins and
2544 ends with `*'.
2545 `\\[ibuffer-mark-dissociated-buffers]' - Mark all buffers which have
2546 an associated file, but that file doesn't currently exist.
2547 `\\[ibuffer-mark-read-only-buffers]' - Mark all read-only buffers.
2548 `\\[ibuffer-mark-dired-buffers]' - Mark buffers in `dired' mode.
2549 `\\[ibuffer-mark-help-buffers]' - Mark buffers in `help-mode', `apropos-mode', etc.
2550 `\\[ibuffer-mark-old-buffers]' - Mark buffers older than `ibuffer-old-time'.
2551 `\\[ibuffer-mark-for-delete]' - Mark the buffer at point for deletion.
2552 `\\[ibuffer-mark-by-name-regexp]' - Mark buffers by their name, using a regexp.
2553 `\\[ibuffer-mark-by-mode-regexp]' - Mark buffers by their major mode, using a regexp.
2554 `\\[ibuffer-mark-by-file-name-regexp]' - Mark buffers by their filename, using a regexp.
2555 `\\[ibuffer-mark-by-content-regexp]' - Mark buffers by their content, using a regexp.
2556 `\\[ibuffer-mark-by-locked]' - Mark all locked buffers.
2558 Filtering commands:
2560 `\\[ibuffer-filter-chosen-by-completion]' - Select and apply filter chosen by completion.
2561 `\\[ibuffer-filter-by-mode]' - Add a filter by any major mode.
2562 `\\[ibuffer-filter-by-used-mode]' - Add a filter by a major mode now in use.
2563 `\\[ibuffer-filter-by-derived-mode]' - Add a filter by derived mode.
2564 `\\[ibuffer-filter-by-name]' - Add a filter by buffer name.
2565 `\\[ibuffer-filter-by-content]' - Add a filter by buffer content.
2566 `\\[ibuffer-filter-by-basename]' - Add a filter by basename.
2567 `\\[ibuffer-filter-by-directory]' - Add a filter by directory name.
2568 `\\[ibuffer-filter-by-filename]' - Add a filter by filename.
2569 `\\[ibuffer-filter-by-file-extension]' - Add a filter by file extension.
2570 `\\[ibuffer-filter-by-modified]' - Add a filter by modified buffers.
2571 `\\[ibuffer-filter-by-predicate]' - Add a filter by an arbitrary Lisp predicate.
2572 `\\[ibuffer-filter-by-size-gt]' - Add a filter by buffer size.
2573 `\\[ibuffer-filter-by-size-lt]' - Add a filter by buffer size.
2574 `\\[ibuffer-filter-by-starred-name]' - Add a filter by special buffers.
2575 `\\[ibuffer-filter-by-visiting-file]' - Add a filter by buffers visiting files.
2576 `\\[ibuffer-save-filters]' - Save the current filters with a name.
2577 `\\[ibuffer-switch-to-saved-filters]' - Switch to previously saved filters.
2578 `\\[ibuffer-add-saved-filters]' - Add saved filters to current filters.
2579 `\\[ibuffer-and-filter]' - Replace the top two filters with their logical AND.
2580 `\\[ibuffer-or-filter]' - Replace the top two filters with their logical OR.
2581 `\\[ibuffer-pop-filter]' - Remove the top filter.
2582 `\\[ibuffer-negate-filter]' - Invert the logical sense of the top filter.
2583 `\\[ibuffer-decompose-filter]' - Break down the topmost filter.
2584 `\\[ibuffer-filter-disable]' - Remove all filtering currently in effect.
2586 Filter group commands:
2588 `\\[ibuffer-filters-to-filter-group]' - Create filter group from filters.
2589 `\\[ibuffer-pop-filter-group]' - Remove top filter group.
2590 `\\[ibuffer-forward-filter-group]' - Move to the next filter group.
2591 `\\[ibuffer-backward-filter-group]' - Move to the previous filter group.
2592 `\\[ibuffer-clear-filter-groups]' - Remove all active filter groups.
2593 `\\[ibuffer-save-filter-groups]' - Save the current groups with a name.
2594 `\\[ibuffer-switch-to-saved-filter-groups]' - Restore previously saved groups.
2595 `\\[ibuffer-delete-saved-filter-groups]' - Delete previously saved groups.
2597 Sorting commands:
2599 `\\[ibuffer-toggle-sorting-mode]' - Rotate between the various sorting modes.
2600 `\\[ibuffer-invert-sorting]' - Reverse the current sorting order.
2601 `\\[ibuffer-do-sort-by-alphabetic]' - Sort the buffers lexicographically.
2602 `\\[ibuffer-do-sort-by-filename/process]' - Sort the buffers by the file name.
2603 `\\[ibuffer-do-sort-by-recency]' - Sort the buffers by last viewing time.
2604 `\\[ibuffer-do-sort-by-size]' - Sort the buffers by size.
2605 `\\[ibuffer-do-sort-by-major-mode]' - Sort the buffers by major mode.
2607 Other commands:
2609 `\\[ibuffer-update]' - Regenerate the list of all buffers.
2610 Prefix arg means to toggle whether buffers that match
2611 `ibuffer-maybe-show-predicates' should be displayed.
2613 `\\[ibuffer-switch-format]' - Change the current display format.
2614 `\\[forward-line]' - Move point to the next line.
2615 `\\[previous-line]' - Move point to the previous line.
2616 `\\[describe-mode]' - This help.
2617 `\\[ibuffer-diff-with-file]' - View the differences between this buffer
2618 and its associated file.
2619 `\\[ibuffer-visit-buffer]' - View the buffer on this line.
2620 `\\[ibuffer-visit-buffer-other-window]' - As above, but in another window.
2621 `\\[ibuffer-visit-buffer-other-window-noselect]' - As both above, but don't select
2622 the new window.
2623 `\\[ibuffer-bury-buffer]' - Bury (not kill!) the buffer on this line.
2625 ** Information on Filtering:
2627 You can filter your ibuffer view via different criteria. Each Ibuffer
2628 buffer has its own stack of active filters. For example, suppose you
2629 are working on an Emacs Lisp project. You can create an Ibuffer
2630 buffer displays buffers in just `emacs-lisp' modes via
2631 `\\[ibuffer-filter-by-mode] emacs-lisp-mode RET'. In this case, there
2632 is just one entry on the filtering stack.
2634 You can also combine filters. The various filtering commands push a
2635 new filter onto the stack, and the filters combine to show just
2636 buffers which satisfy ALL criteria on the stack. For example, suppose
2637 you only want to see buffers in `emacs-lisp' mode, whose names begin
2638 with \"gnus\". You can accomplish this via:
2640 \\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2641 \\[ibuffer-filter-by-name] ^gnus RET
2643 Additionally, you can OR the top two filters together with
2644 `\\[ibuffer-or-filters]'. To see all buffers in either
2645 `emacs-lisp-mode' or `lisp-interaction-mode', type:
2647 \\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2648 \\[ibuffer-filter-by-mode] lisp-interaction-mode RET
2649 \\[ibuffer-or-filters]
2651 Filters can also be saved and restored using mnemonic names: see the
2652 functions `ibuffer-save-filters' and `ibuffer-switch-to-saved-filters'.
2654 To remove the top filter on the stack, use `\\[ibuffer-pop-filter]', and
2655 to disable all filtering currently in effect, use
2656 `\\[ibuffer-filter-disable]'.
2658 ** Filter Groups:
2660 Once one has mastered filters, the next logical step up is \"filter
2661 groups\". A filter group is basically a named group of buffers which
2662 match a filter, which are displayed together in an Ibuffer buffer. To
2663 create a filter group, simply use the regular functions to create a
2664 filter, and then type `\\[ibuffer-filters-to-filter-group]'.
2666 A quick example will make things clearer. Suppose that one wants to
2667 group all of one's Emacs Lisp buffers together. To do this, type:
2669 \\[ibuffer-filter-by-mode] emacs-lisp-mode RET
2670 \\[ibuffer-filters-to-filter-group] emacs lisp buffers RET
2672 You may, of course, name the group whatever you want; it doesn't have
2673 to be \"emacs lisp buffers\". Filter groups may be composed of any
2674 arbitrary combination of filters.
2676 Just like filters themselves, filter groups act as a stack. Buffers
2677 will not be displayed multiple times if they would be included in
2678 multiple filter groups; instead, the first filter group is used. The
2679 filter groups are displayed in this order of precedence.
2681 You may rearrange filter groups by using the regular
2682 `\\[ibuffer-kill-line]' and `\\[ibuffer-yank]' pair. Yanked groups
2683 will be inserted before the group at point."
2684 ;; Include state info next to the mode name.
2685 (set (make-local-variable 'mode-line-process)
2686 '(" by "
2687 (ibuffer-sorting-mode (:eval (symbol-name ibuffer-sorting-mode))
2688 "view time")
2689 (ibuffer-sorting-reversep " [rev]")
2690 (ibuffer-auto-mode " (Auto)")
2691 ;; Only list the filters if they're not already in the header-line.
2692 (header-line-format
2694 (:eval (if (functionp 'ibuffer-format-qualifier)
2695 (mapconcat 'ibuffer-format-qualifier
2696 ibuffer-filtering-qualifiers ""))))))
2697 ;; `ibuffer-update' puts this on header-line-format when needed.
2698 (setq ibuffer-header-line-format
2699 ;; Display the part that won't be in the mode-line.
2700 `("" ,mode-name
2701 ,@(mapcar (lambda (elem)
2702 (if (eq (car-safe elem) 'header-line-format)
2703 (nth 2 elem) elem))
2704 mode-line-process)))
2706 (setq buffer-read-only t)
2707 (buffer-disable-undo)
2708 (setq truncate-lines ibuffer-truncate-lines)
2709 ;; This makes things less ugly for Emacs 21 users with a non-nil
2710 ;; `show-trailing-whitespace'.
2711 (setq show-trailing-whitespace nil)
2712 ;; disable `show-paren-mode' buffer-locally
2713 (if (bound-and-true-p show-paren-mode)
2714 (set (make-local-variable 'show-paren-mode) nil))
2715 (set (make-local-variable 'revert-buffer-function)
2716 #'ibuffer-update)
2717 (set (make-local-variable 'ibuffer-sorting-mode)
2718 ibuffer-default-sorting-mode)
2719 (set (make-local-variable 'ibuffer-sorting-reversep)
2720 ibuffer-default-sorting-reversep)
2721 (set (make-local-variable 'ibuffer-shrink-to-minimum-size)
2722 ibuffer-default-shrink-to-minimum-size)
2723 (set (make-local-variable 'ibuffer-display-maybe-show-predicates)
2724 ibuffer-default-display-maybe-show-predicates)
2725 (set (make-local-variable 'ibuffer-filtering-qualifiers) nil)
2726 (set (make-local-variable 'ibuffer-filter-groups) nil)
2727 (set (make-local-variable 'ibuffer-filter-group-kill-ring) nil)
2728 (set (make-local-variable 'ibuffer-hidden-filter-groups) nil)
2729 (set (make-local-variable 'ibuffer-compiled-formats) nil)
2730 (set (make-local-variable 'ibuffer-cached-formats) nil)
2731 (set (make-local-variable 'ibuffer-cached-eliding-string) nil)
2732 (set (make-local-variable 'ibuffer-current-format) nil)
2733 (set (make-local-variable 'ibuffer-did-modification) nil)
2734 (set (make-local-variable 'ibuffer-tmp-hide-regexps) nil)
2735 (set (make-local-variable 'ibuffer-tmp-show-regexps) nil)
2736 (define-key ibuffer-mode-map [menu-bar edit] 'undefined)
2737 (define-key ibuffer-mode-map [menu-bar operate] (cons "Operate" ibuffer-mode-operate-map))
2738 (ibuffer-update-format)
2739 (when ibuffer-default-directory
2740 (setq default-directory ibuffer-default-directory))
2741 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t))
2743 (provide 'ibuffer)
2745 (run-hooks 'ibuffer-load-hook)
2747 ;;; ibuffer.el ends here