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