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