mirrored from git://git.sv.gnu.org/emacs.git
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathibuffer.el
2665 lines (2423 loc) · 98.6 KB
/
ibuffer.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; ibuffer.el --- operate on buffers like dired -*- lexical-binding:t -*-
;; Copyright (C) 2000-2025 Free Software Foundation, Inc.
;; Author: Colin Walters <walters@verbum.org>
;; Maintainer: John Paul Wallington <jpw@gnu.org>
;; Created: 8 Sep 2000
;; Keywords: buffer, convenience
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; Ibuffer is an advanced replacement for the `buffer-menu' which is
;; distributed with Emacs. It lets you operate on buffers in a
;; Dired-like way, with the ability to sort, mark by regular
;; expression, and filter displayed buffers by various criteria. Its
;; interface is intended to be analogous to that of Dired.
;;
;; To start using it, type `M-x ibuffer'. If you use it regularly,
;; you might be interested in replacing the default `list-buffers' key
;; binding by adding the following to your init file:
;;
;; (keymap-global-set "C-x C-b" 'ibuffer)
;;
;; See also the various customization options, not least the
;; documentation for `ibuffer-formats'.
;;
;; For more help, type `?' in the "*Ibuffer*" buffer.
;;; Code:
(eval-when-compile
(require 'cl-lib)
(require 'ibuf-macs)
(require 'dired))
(require 'seq)
(require 'ibuffer-loaddefs)
;; These come from ibuf-ext.el, which can not be require'd at compile time
;; because it has a recursive dependency on ibuffer.el
(defvar ibuffer-auto-mode)
(defvar ibuffer-cached-filter-formats)
(defvar ibuffer-compiled-filter-formats)
(defvar ibuffer-filter-format-alist)
(defvar ibuffer-filter-group-kill-ring)
(defvar ibuffer-filter-groups)
(defvar ibuffer-filtering-qualifiers)
(defvar ibuffer-header-line-format)
(defvar ibuffer-hidden-filter-groups)
(defvar ibuffer-inline-columns)
(defvar ibuffer-show-empty-filter-groups)
(defvar ibuffer-tmp-hide-regexps)
(defvar ibuffer-tmp-show-regexps)
(declare-function ibuffer-ext-visible-p "ibuf-ext"
(buf all &optional ibuffer-buf))
(declare-function ibuffer-mark-on-buffer "ibuf-ext"
(func &optional ibuffer-mark-on-buffer-mark group))
(declare-function ibuffer-generate-filter-groups "ibuf-ext"
(bmarklist &optional noempty nodefault))
(declare-function ibuffer-format-filter-group-data "ibuf-ext" (filter))
(defgroup ibuffer nil
"Advanced replacement for `buffer-menu'.
Ibuffer lets you operate on buffers in a Dired-like way,
with the ability to sort, mark by regular expression,
and filter displayed buffers by various criteria."
:version "22.1"
:group 'convenience)
(defcustom ibuffer-formats '((mark modified read-only locked
" " (name 18 18 :left :elide)
" " (size 9 -1 :right)
" " (mode 16 16 :left :elide) " " filename-and-process)
(mark " " (name 16 -1) " " filename))
"A list of ways to display buffer lines.
With Ibuffer, you are not limited to displaying just certain
attributes of a buffer such as size, name, and mode in a particular
order. Through this variable, you can completely customize and
control the appearance of an Ibuffer buffer. See also
`define-ibuffer-column', which allows you to define your own columns
for display.
This variable has the form
((COLUMN COLUMN ...) (COLUMN COLUMN ...) ...)
Each element in `ibuffer-formats' should be a list containing COLUMN
specifiers. A COLUMN can be any of the following:
SYMBOL - A symbol naming the column. Predefined columns are:
mark modified read-only locked name size mode process filename
When you define your own columns using `define-ibuffer-column', just
use their name like the predefined columns here. This entry can
also be a function of two arguments, which should return a string.
The first argument is the buffer object, and the second is the mark
on that buffer.
or
\"STRING\" - A literal string to display.
or
(SYMBOL MIN-SIZE MAX-SIZE &optional ALIGN ELIDE) - SYMBOL is a
symbol naming the column, and MIN-SIZE and MAX-SIZE are integers (or
functions of no arguments returning an integer) which constrict the
size of a column. If MAX-SIZE is -1, there is no upper bound. The
default values are 0 and -1, respectively. If MIN-SIZE is negative,
use the end of the string. The optional element ALIGN describes the
alignment of the column; it can be :left, :center or :right. The
optional element ELIDE describes whether or not to elide the column
if it is too long; valid values are :elide and nil. The default is
nil (don't elide).
Some example of valid entries in `ibuffer-formats', with
description (also, feel free to try them out, and experiment with your
own!):
(mark \" \" name)
This format just displays the current mark (if any) and the name of
the buffer, separated by a space.
(mark modified read-only \" \" (name 16 16 :left) \" \" (size 6 -1 :right))
This format displays the current mark (if any), its modification and
read-only status, as well as the name of the buffer and its size. In
this format, the name is restricted to 16 characters (longer names
will be truncated, and shorter names will be padded with spaces), and
the name is also aligned to the left. The size of the buffer will
be padded with spaces up to a minimum of six characters, but there is
no upper limit on its size. The size will also be aligned to the
right.
Thus, if you wanted to use these two formats, the appropriate
value for this variable would be
\\='((mark \" \" name)
(mark modified read-only
(name 16 16 :left)
(size 6 -1 :right)))
Using \\[ibuffer-switch-format], you can rotate the display between
the specified formats in the list."
:version "26.1"
:type '(repeat sexp))
(defcustom ibuffer-always-compile-formats (featurep 'bytecomp)
"If non-nil, then use the byte-compiler to optimize `ibuffer-formats'.
This will increase the redisplay speed, at the cost of loading the
elisp byte-compiler."
:type 'boolean)
(defcustom ibuffer-fontification-alist
'((10 buffer-read-only font-lock-constant-face)
(15 (and buffer-file-name
(string-match ibuffer-compressed-file-name-regexp
buffer-file-name))
font-lock-doc-face)
(20 (string-match "^\\*" (buffer-name)) font-lock-keyword-face)
(25 (and (string-match "^ " (buffer-name))
(null buffer-file-name))
italic)
(30 (memq major-mode ibuffer-help-buffer-modes) font-lock-comment-face)
(35 (derived-mode-p 'dired-mode) font-lock-function-name-face)
(40 (and (boundp 'emacs-lock-mode) emacs-lock-mode) ibuffer-locked-buffer))
"An alist describing how to fontify buffers.
Each element should be of the form (PRIORITY FORM FACE), where
PRIORITY is an integer, FORM is an arbitrary form to evaluate in the
buffer, and FACE is the face to use for fontification. If the FORM
evaluates to non-nil, then FACE will be put on the buffer name. The
element with the highest PRIORITY takes precedence.
If you change this variable, you must kill the Ibuffer buffer and
recreate it for the change to take effect."
:type '(repeat
(list (integer :tag "Priority")
(sexp :tag "Test Form")
face)))
(defcustom ibuffer-human-readable-size nil
"Show buffer sizes in human-readable format.
Use the function `file-size-human-readable' for formatting."
:type 'boolean
:version "31.1")
(defcustom ibuffer-use-other-window nil
"If non-nil, display Ibuffer in another window by default."
:type 'boolean)
(defcustom ibuffer-default-shrink-to-minimum-size nil
"If non-nil, minimize the size of the Ibuffer window by default."
:type 'boolean)
(defvar ibuffer-shrink-to-minimum-size nil)
(defcustom ibuffer-display-summary t
"If non-nil, summarize Ibuffer columns."
:type 'boolean)
(defcustom ibuffer-truncate-lines t
"If non-nil, do not display continuation lines."
:type 'boolean)
(defcustom ibuffer-case-fold-search case-fold-search
"If non-nil, ignore case when searching."
:type 'boolean)
(defcustom ibuffer-default-sorting-mode 'recency
"The criteria by which to sort the buffers.
Note that this variable is local to each Ibuffer buffer. Thus, you
can have multiple Ibuffer buffers open, each with a different sorted
view of the buffers."
:type '(choice (const :tag "Last view time" :value recency)
(const :tag "Lexicographic" :value alphabetic)
(const :tag "Buffer size" :value size)
(const :tag "File name" :value filename/process)
(const :tag "Major mode" :value major-mode)))
(defvar ibuffer-sorting-mode nil)
(defvar ibuffer-last-sorting-mode nil)
(defcustom ibuffer-default-sorting-reversep nil
"If non-nil, reverse the default sorting order."
:type 'boolean)
(defvar ibuffer-sorting-reversep nil)
(defcustom ibuffer-eliding-string "..."
"The string to use for eliding long columns."
:type 'string)
(defcustom ibuffer-maybe-show-predicates `(,(lambda (buf)
(and (string-match "^ " (buffer-name buf))
(null buffer-file-name))))
"A list of predicates for buffers to display conditionally.
A predicate can be a regexp or a function.
If a regexp, then it will be matched against the buffer's name.
If a function, it will be called with the buffer as an argument, and
should return non-nil if this buffer should be shown.
Viewing of buffers hidden because of these predicates may be customized
via `ibuffer-default-display-maybe-show-predicates' and is toggled by
giving a non-nil prefix argument to `ibuffer-update'.
Note that this specialized filtering occurs before real filtering."
:type '(repeat (choice regexp function)))
(defcustom ibuffer-default-display-maybe-show-predicates nil
"Non-nil means show buffers that match `ibuffer-maybe-show-predicates'."
:type 'boolean)
(defvar ibuffer-display-maybe-show-predicates nil)
(defvar ibuffer-current-format nil)
(defcustom ibuffer-movement-cycle t
"If non-nil, then forward and backwards movement commands cycle."
:type 'boolean)
(defcustom ibuffer-modified-char ?*
"The character to display for modified buffers."
:type 'character)
(defcustom ibuffer-read-only-char ?%
"The character to display for read-only buffers."
:type 'character)
(defcustom ibuffer-marked-char ?>
"The character to display for marked buffers."
:type 'character)
(defcustom ibuffer-locked-char ?L
"The character to display for locked buffers."
:version "26.1"
:type 'character)
(defcustom ibuffer-deletion-char ?D
"The character to display for buffers marked for deletion."
:type 'character)
(defcustom ibuffer-expert nil
"If non-nil, don't ask for confirmation of \"dangerous\" operations."
:type 'boolean)
(defcustom ibuffer-view-ibuffer nil
"If non-nil, display the current Ibuffer buffer itself.
Note that this has a drawback - the data about the current Ibuffer
buffer will most likely be inaccurate. This includes modification
state, size, etc."
:type 'boolean)
(defcustom ibuffer-always-show-last-buffer nil
"If non-nil, always display the previous buffer.
This variable takes precedence over filtering, and even
`ibuffer-never-show-predicates'."
:type '(choice (const :tag "Always" :value t)
(const :tag "Never" :value nil)
(const :tag "Always except minibuffer" :value :nomini)))
(defcustom ibuffer-jump-offer-only-visible-buffers nil
"If non-nil, only offer buffers visible in the Ibuffer buffer
in completion lists of the `ibuffer-jump-to-buffer' command."
:type 'boolean)
(defcustom ibuffer-use-header-line t
"If non-nil, display a header line.
If the variable's value is t, the header line displays the current
filters. For the value `title', display the column titles."
:type '(choice boolean (const :tag "Column titles" :value title)))
(defcustom ibuffer-default-directory nil
"The default directory to use for a new Ibuffer buffer.
If nil, inherit the directory of the buffer in which `ibuffer' was
called. Otherwise, this variable should be a string naming a
directory, like `default-directory'."
:type '(choice (const :tag "Inherit" :value nil)
string))
(defcustom ibuffer-help-buffer-modes
'(help-mode apropos-mode Info-mode)
"List of \"Help\" major modes."
:type '(repeat function))
(defcustom ibuffer-compressed-file-name-regexp
"\\.\\(arj\\|bgz\\|bz2\\|gz\\|lzh\\|taz\\|tgz\\|xz\\|zip\\|z\\)$"
"Regexp to match compressed file names."
:version "24.1" ; added xz
:type 'regexp)
(defcustom ibuffer-hook nil
"Hook run when `ibuffer' is called."
:type 'hook)
(defcustom ibuffer-mode-hook nil
"Hook run upon entry into `ibuffer-mode'."
:type 'hook
:options '(ibuffer-auto-mode))
(defcustom ibuffer-load-hook nil
"Hook run when Ibuffer is loaded."
:type 'hook)
(make-obsolete-variable 'ibuffer-load-hook
"use `with-eval-after-load' instead." "28.1")
(defcustom ibuffer-marked-face 'warning
"Face used for displaying marked buffers."
:type 'face)
(defcustom ibuffer-deletion-face 'error
"Face used for displaying buffers marked for deletion."
:type 'face)
(defcustom ibuffer-title-face 'font-lock-type-face
"Face used for the title string."
:type 'face)
(defcustom ibuffer-filter-group-name-face 'bold
"Face used for displaying filtering group names."
:type 'face)
(defcustom ibuffer-directory-abbrev-alist nil
"An alist of file name abbreviations like `directory-abbrev-alist'."
:type '(repeat (cons :format "%v"
:value ("" . "")
(regexp :tag "From")
(regexp :tag "To"))))
(defvar-keymap ibuffer--filter-map
"RET" #'ibuffer-filter-by-mode
"SPC" #'ibuffer-filter-chosen-by-completion
"m" #'ibuffer-filter-by-used-mode
"M" #'ibuffer-filter-by-derived-mode
"n" #'ibuffer-filter-by-name
"E" #'ibuffer-filter-by-process
"*" #'ibuffer-filter-by-starred-name
"f" #'ibuffer-filter-by-filename
"F" #'ibuffer-filter-by-directory
"b" #'ibuffer-filter-by-basename
"." #'ibuffer-filter-by-file-extension
"<" #'ibuffer-filter-by-size-lt
">" #'ibuffer-filter-by-size-gt
"i" #'ibuffer-filter-by-modified
"v" #'ibuffer-filter-by-visiting-file
"c" #'ibuffer-filter-by-content
"e" #'ibuffer-filter-by-predicate
"r" #'ibuffer-switch-to-saved-filters
"a" #'ibuffer-add-saved-filters
"x" #'ibuffer-delete-saved-filters
"d" #'ibuffer-decompose-filter
"s" #'ibuffer-save-filters
"p" #'ibuffer-pop-filter
"<up>" #'ibuffer-pop-filter
"!" #'ibuffer-negate-filter
"t" #'ibuffer-exchange-filters
"TAB" #'ibuffer-exchange-filters
"o" #'ibuffer-or-filter
"|" #'ibuffer-or-filter
"&" #'ibuffer-and-filter
"g" #'ibuffer-filters-to-filter-group
"P" #'ibuffer-pop-filter-group
"S-<up>" #'ibuffer-pop-filter-group
"D" #'ibuffer-decompose-filter-group
"/" #'ibuffer-filter-disable
"S" #'ibuffer-save-filter-groups
"R" #'ibuffer-switch-to-saved-filter-groups
"X" #'ibuffer-delete-saved-filter-groups
"\\" #'ibuffer-clear-filter-groups)
(defvar-keymap ibuffer-mode-map
:full t
"0" #'digit-argument
"1" #'digit-argument
"2" #'digit-argument
"3" #'digit-argument
"4" #'digit-argument
"5" #'digit-argument
"6" #'digit-argument
"7" #'digit-argument
"8" #'digit-argument
"9" #'digit-argument
"m" #'ibuffer-mark-forward
"t" #'ibuffer-toggle-marks
"u" #'ibuffer-unmark-forward
"=" #'ibuffer-diff-with-file
"j" #'ibuffer-jump-to-buffer
"M-g" #'ibuffer-jump-to-buffer
"M-s a C-s" #'ibuffer-do-isearch
"M-s a C-M-s" #'ibuffer-do-isearch-regexp
"M-s a C-o" #'ibuffer-do-occur
"DEL" #'ibuffer-unmark-backward
"M-DEL" #'ibuffer-unmark-all
"* *" #'ibuffer-unmark-all
"* c" #'ibuffer-change-marks
"U" #'ibuffer-unmark-all-marks
"* M" #'ibuffer-mark-by-mode
"* m" #'ibuffer-mark-modified-buffers
"* u" #'ibuffer-mark-unsaved-buffers
"* s" #'ibuffer-mark-special-buffers
"* r" #'ibuffer-mark-read-only-buffers
"* /" #'ibuffer-mark-dired-buffers
"* e" #'ibuffer-mark-dissociated-buffers
"* h" #'ibuffer-mark-help-buffers
"* z" #'ibuffer-mark-compressed-file-buffers
"." #'ibuffer-mark-old-buffers
"d" #'ibuffer-mark-for-delete
"C-d" #'ibuffer-mark-for-delete-backwards
"x" #'ibuffer-do-kill-on-deletion-marks
;; immediate operations
"n" #'ibuffer-forward-line
"SPC" #'forward-line
"p" #'ibuffer-backward-line
"M-}" #'ibuffer-forward-next-marked
"M-{" #'ibuffer-backwards-next-marked
"l" #'ibuffer-redisplay
"g" #'ibuffer-update
"`" #'ibuffer-switch-format
"-" #'ibuffer-add-to-tmp-hide
"+" #'ibuffer-add-to-tmp-show
"b" #'ibuffer-bury-buffer
"," #'ibuffer-toggle-sorting-mode
"s i" #'ibuffer-invert-sorting
"s a" #'ibuffer-do-sort-by-alphabetic
"s v" #'ibuffer-do-sort-by-recency
"s s" #'ibuffer-do-sort-by-size
"s f" #'ibuffer-do-sort-by-filename/process
"s m" #'ibuffer-do-sort-by-major-mode
"M-n" #'ibuffer-forward-filter-group
"TAB" #'ibuffer-forward-filter-group
"M-p" #'ibuffer-backward-filter-group
"<backtab>" #'ibuffer-backward-filter-group
"M-j" #'ibuffer-jump-to-filter-group
"C-k" #'ibuffer-kill-line
"C-y" #'ibuffer-yank
"% n" #'ibuffer-mark-by-name-regexp
"% m" #'ibuffer-mark-by-mode-regexp
"% f" #'ibuffer-mark-by-file-name-regexp
"% g" #'ibuffer-mark-by-content-regexp
"% L" #'ibuffer-mark-by-locked
"C-t" #'ibuffer-visit-tags-table
"|" #'ibuffer-do-shell-command-pipe
"!" #'ibuffer-do-shell-command-file
"~" #'ibuffer-do-toggle-modified
;; marked operations
"A" #'ibuffer-do-view
"D" #'ibuffer-do-delete
"E" #'ibuffer-do-eval
"F" #'ibuffer-do-shell-command-file
"I" #'ibuffer-do-query-replace-regexp
"H" #'ibuffer-do-view-other-frame
"N" #'ibuffer-do-shell-command-pipe-replace
"M" #'ibuffer-do-toggle-modified
"O" #'ibuffer-do-occur
"P" #'ibuffer-do-print
"Q" #'ibuffer-do-query-replace
"R" #'ibuffer-do-rename-uniquely
"S" #'ibuffer-do-save
"T" #'ibuffer-do-toggle-read-only
"L" #'ibuffer-do-toggle-lock
"r" #'ibuffer-do-replace-regexp
"V" #'ibuffer-do-revert
"W" #'ibuffer-do-view-and-eval
"X" #'ibuffer-do-shell-command-pipe
"k" #'ibuffer-do-kill-lines
"w" #'ibuffer-copy-filename-as-kill
"B" #'ibuffer-copy-buffername-as-kill
"RET" #'ibuffer-visit-buffer
"e" #'ibuffer-visit-buffer
"f" #'ibuffer-visit-buffer
"C-x C-f" #'ibuffer-find-file
"o" #'ibuffer-visit-buffer-other-window
"C-o" #'ibuffer-visit-buffer-other-window-noselect
"M-o" #'ibuffer-visit-buffer-1-window
"v" #'ibuffer-do-view
"C-x v" #'ibuffer-do-view-horizontally
"C-c C-a" #'ibuffer-auto-mode
"C-x 4 RET" #'ibuffer-visit-buffer-other-window
"C-x 5 RET" #'ibuffer-visit-buffer-other-frame
"/" ibuffer--filter-map)
(defun ibuffer-mode--groups-menu-definition (&optional is-popup)
"Build the `ibuffer' \"Filter\" menu. Internal."
`("Filter Groups"
["Create filter group from current filters..."
ibuffer-filters-to-filter-group
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)]
["Move point to the next filter group"
ibuffer-forward-filter-group]
["Move point to the previous filter group"
ibuffer-backward-filter-group]
["Move point to a specific filter group..."
ibuffer-jump-to-filter-group]
,@(if is-popup
'(["Kill filter group"
ibuffer-kill-line
:enable (and (featurep 'ibuf-ext)
ibuffer-filter-groups)]
["Yank last killed filter group"
ibuffer-yank
:enable (and (featurep 'ibuf-ext)
ibuffer-filter-group-kill-ring)])
'(["Kill filter group named..."
ibuffer-kill-filter-group
:enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)]
["Yank last killed filter group before..."
ibuffer-yank-filter-group
:enable (and (featurep 'ibuf-ext) ibuffer-filter-group-kill-ring)]))
["Remove top filter group"
ibuffer-pop-filter-group
:enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)]
["Remove all filter groups"
ibuffer-clear-filter-groups
:enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)]
["Decompose filter group..."
ibuffer-pop-filter-group
:help "\"Unmake\" a filter group"
:enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)]
["Save current filter groups permanently..."
ibuffer-save-filter-groups
:enable (and (featurep 'ibuf-ext) ibuffer-filter-groups)
:help "Use a mnemonic name to store current filter groups"]
["Restore permanently saved filters..."
ibuffer-switch-to-saved-filter-groups
:enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)
:help "Replace current filters with a saved stack"]
["Delete permanently saved filter groups..."
ibuffer-delete-saved-filter-groups
:enable (and (featurep 'ibuf-ext) ibuffer-saved-filter-groups)]
["Set current filter groups to filter by mode"
ibuffer-set-filter-groups-by-mode]))
(easy-menu-define ibuffer-mode-groups-popup nil
"Menu for `ibuffer'."
(ibuffer-mode--groups-menu-definition 'is-popup))
(easy-menu-define ibuffer-mode-mark-menu ibuffer-mode-map
"Mark menu for `ibuffer'."
'("Mark"
["Toggle marks" ibuffer-toggle-marks
:help "Unmark marked buffers, and mark unmarked buffers"]
["Change marks" ibuffer-change-marks
:help "Change OLD mark for marked buffers with NEW"]
["Mark" ibuffer-mark-forward
:help "Mark the buffer at point"]
["Unmark" ibuffer-unmark-forward
:help "Unmark the buffer at point"]
["Mark by mode..." ibuffer-mark-by-mode
:help "Mark all buffers in a particular major mode"]
["Mark modified buffers" ibuffer-mark-modified-buffers
:help "Mark all buffers which have been modified"]
["Mark unsaved buffers" ibuffer-mark-unsaved-buffers
:help "Mark all buffers which have a file and are modified"]
["Mark read-only buffers" ibuffer-mark-read-only-buffers
:help "Mark all buffers which are read-only"]
["Mark special buffers" ibuffer-mark-special-buffers
:help "Mark all buffers whose name begins with a *"]
["Mark dired buffers" ibuffer-mark-dired-buffers
:help "Mark buffers in dired-mode"]
["Mark dissociated buffers" ibuffer-mark-dissociated-buffers
:help "Mark buffers with a non-existent associated file"]
["Mark help buffers" ibuffer-mark-help-buffers
:help "Mark buffers in help-mode"]
["Mark compressed file buffers" ibuffer-mark-compressed-file-buffers
:help "Mark buffers which have a file that is compressed"]
["Mark old buffers" ibuffer-mark-old-buffers
:help "Mark buffers which have not been viewed recently"]
["Unmark All" ibuffer-unmark-all]
["Unmark All buffers" ibuffer-unmark-all-marks]
"---"
["Mark by buffer name (regexp)..." ibuffer-mark-by-name-regexp
:help "Mark buffers whose name matches a regexp"]
["Mark by major mode (regexp)..." ibuffer-mark-by-mode-regexp
:help "Mark buffers whose major mode name matches a regexp"]
["Mark by file name (regexp)..." ibuffer-mark-by-file-name-regexp
:help "Mark buffers whose file name matches a regexp"]
["Mark by content (regexp)..." ibuffer-mark-by-content-regexp
:help "Mark buffers whose content matches a regexp"]
["Mark by locked buffers..." ibuffer-mark-by-locked
:help "Mark all locked buffers"]))
(easy-menu-define ibuffer-mode-view-menu ibuffer-mode-map
"View menu for `ibuffer'."
`("View"
["View this buffer" ibuffer-visit-buffer]
["View (other window)" ibuffer-visit-buffer-other-window]
["View (other frame)" ibuffer-visit-buffer-other-frame]
["Update" ibuffer-update
:help "Regenerate the list of buffers"]
["Switch display format" ibuffer-switch-format
:help "Toggle between available values of `ibuffer-formats'"]
"---"
("Sort"
["Sort by major mode" ibuffer-do-sort-by-major-mode]
["Sort by buffer size" ibuffer-do-sort-by-size]
["Sort lexicographically" ibuffer-do-sort-by-alphabetic
:help "Sort by the alphabetic order of buffer name"]
["Sort by view time" ibuffer-do-sort-by-recency
:help "Sort by the last time the buffer was displayed"]
"---"
["Reverse sorting order" ibuffer-invert-sorting]
["Switch sorting mode" ibuffer-toggle-sorting-mode
:help "Switch between the various sorting criteria"])
("Filter"
["Disable all filtering" ibuffer-filter-disable
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)]
["Add filter by any major mode..." ibuffer-filter-by-mode]
["Add filter by a major mode in use..." ibuffer-filter-by-used-mode]
["Add filter by derived mode..." ibuffer-filter-by-derived-mode]
["Add filter by buffer name..." ibuffer-filter-by-name]
["Add filter by starred buffer name..." ibuffer-filter-by-starred-name
:help "List buffers whose names begin with a star"]
["Add filter by full filename..." ibuffer-filter-by-filename
:help (concat "For a buffer associated with file `/a/b/c.d', "
"list buffer if a given pattern matches `/a/b/c.d'")]
["Add filter by file basename..." ibuffer-filter-by-basename
:help (concat "For a buffer associated with file `/a/b/c.d', "
"list buffer if a given pattern matches `c.d'")]
["Add filter by file name extension..." ibuffer-filter-by-file-extension
:help (concat "For a buffer associated with file `/a/b/c.d', "
"list buffer if a given pattern matches `d'")]
["Add filter by filename's directory..." ibuffer-filter-by-directory
:help (concat "For a buffer associated with file `/a/b/c.d', "
"list buffer if a given pattern matches `/a/b'")]
["Add filter by size less than..." ibuffer-filter-by-size-lt]
["Add filter by size greater than..." ibuffer-filter-by-size-gt]
["Add filter by modified buffer" ibuffer-filter-by-modified
:help "List buffers that are marked as modified"]
["Add filter by buffer visiting a file" ibuffer-filter-by-visiting-file
:help "List buffers that are visiting files"]
["Add filter by content (regexp)..." ibuffer-filter-by-content]
["Add filter by Lisp predicate..." ibuffer-filter-by-predicate]
["Remove top filter" ibuffer-pop-filter
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)]
["AND top two filters" ibuffer-and-filter
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
(cdr ibuffer-filtering-qualifiers))
:help "Create a new filter which is the logical AND of the top two filters"]
["OR top two filters" ibuffer-or-filter
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
(cdr ibuffer-filtering-qualifiers))
:help "Create a new filter which is the logical OR of the top two filters"]
["Negate top filter" ibuffer-negate-filter
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)]
["Decompose top filter" ibuffer-decompose-filter
:enable (and (featurep 'ibuf-ext)
(memq (car ibuffer-filtering-qualifiers) '(or saved not)))
:help "Break down a complex filter like OR or NOT"]
["Swap top two filters" ibuffer-exchange-filters
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers
(cdr ibuffer-filtering-qualifiers))]
["Save current filters permanently..." ibuffer-save-filters
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
:help "Use a mnemonic name to store current filter stack"]
["Restore permanently saved filters..." ibuffer-switch-to-saved-filters
:enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)
:help "Replace current filters with a saved stack"]
["Add to permanently saved filters..." ibuffer-add-saved-filters
:enable (and (featurep 'ibuf-ext) ibuffer-filtering-qualifiers)
:help "Include already saved stack with current filters"]
["Delete permanently saved filters..." ibuffer-delete-saved-filters
:enable (and (featurep 'ibuf-ext) ibuffer-saved-filters)])
;; The "Filter Groups" menu:
,(ibuffer-mode--groups-menu-definition)
"---"
["Auto Mode" ibuffer-auto-mode
:style toggle
:selected ibuffer-auto-mode
:help "Attempt to automatically update the Ibuffer buffer"]))
(define-obsolete-variable-alias 'ibuffer-mode-operate-map 'ibuffer-mode-operate-menu "28.1")
(easy-menu-define ibuffer-mode-operate-menu ibuffer-mode-map
"Operate menu for `ibuffer'."
'("Operate"
["View" ibuffer-do-view]
["View (separate frame)" ibuffer-do-view-other-frame]
["Save" ibuffer-do-save]
["Replace (regexp)..." ibuffer-do-replace-regexp
:help "Replace text inside marked buffers"]
["Query Replace..." ibuffer-do-query-replace
:help "Replace text in marked buffers, asking each time"]
["Query Replace (regexp)..." ibuffer-do-query-replace-regexp
:help "Replace text in marked buffers by regexp, asking each time"]
["Print" ibuffer-do-print]
["Toggle modification flag" ibuffer-do-toggle-modified]
["Toggle read-only flag" ibuffer-do-toggle-read-only]
["Toggle lock flag" ibuffer-do-toggle-lock]
["Revert" ibuffer-do-revert
:help "Revert marked buffers to their associated file"]
["Rename Uniquely" ibuffer-do-rename-uniquely
:help "Rename marked buffers to a new, unique name"]
["Kill" ibuffer-do-delete]
["List lines matching..." ibuffer-do-occur
:help "View all lines in marked buffers matching a regexp"]
["Pipe to shell command..." ibuffer-do-shell-command-pipe
:help "For each marked buffer, send its contents to a shell command"]
["Pipe to shell command (replace)..." ibuffer-do-shell-command-pipe-replace
:help "For each marked buffer, replace its contents with output of shell command"]
["Shell command on buffer's file..." ibuffer-do-shell-command-file
:help "For each marked buffer, run a shell command with its file as argument"]
["Eval..." ibuffer-do-eval
:help "Evaluate a Lisp form in each marked buffer"]
["Eval (viewing buffer)..." ibuffer-do-view-and-eval
:help "Evaluate a Lisp form in each marked buffer while viewing it"]
["Diff with file" ibuffer-diff-with-file
:help "View the differences between this buffer and its file"]))
(defvar-keymap ibuffer-name-map
"<mouse-1>" #'ibuffer-mouse-toggle-mark
"<mouse-2>" #'ibuffer-mouse-visit-buffer
"<down-mouse-3>" #'ibuffer-mouse-popup-menu)
(defvar-keymap ibuffer-filename/process-header-map
"<mouse-1>" #'ibuffer-do-sort-by-filename/process)
(defvar-keymap ibuffer-mode-name-map
"<mouse-2>" #'ibuffer-mouse-filter-by-mode
"RET" #'ibuffer-interactive-filter-by-mode)
(defvar-keymap ibuffer-name-header-map
"<mouse-1>" #'ibuffer-do-sort-by-alphabetic)
(defvar-keymap ibuffer-size-header-map
"<mouse-1>" #'ibuffer-do-sort-by-size)
(defvar-keymap ibuffer-mode-header-map
"<mouse-1>" #'ibuffer-do-sort-by-major-mode)
(defvar-keymap ibuffer-recency-header-map
"<mouse-1>" #'ibuffer-do-sort-by-recency)
(defvar-keymap ibuffer-mode-filter-group-map
"<mouse-1>" #'ibuffer-mouse-toggle-mark
"<mouse-2>" #'ibuffer-mouse-toggle-filter-group
"RET" #'ibuffer-toggle-filter-group
"<down-mouse-3>" #'ibuffer-mouse-popup-menu)
(defvar ibuffer-did-modification nil)
(defvar ibuffer-compiled-formats nil)
(defvar ibuffer-cached-formats nil)
(defvar ibuffer-cached-eliding-string nil)
(defvar ibuffer-sorting-functions-alist nil
"An alist of functions which describe how to sort buffers.
Note: You most likely do not want to modify this variable directly;
use `define-ibuffer-sorter' instead.
The alist elements are constructed like (NAME DESCRIPTION FUNCTION)
Where NAME is a symbol describing the sorting method, DESCRIPTION is a
short string which will be displayed in the minibuffer and menu, and
FUNCTION is a function of two arguments, which will be the buffers to
compare.")
;;; Utility functions
(defun ibuffer-columnize-and-insert-list (list &optional pad-width)
"Insert LIST into the current buffer in as many columns as possible.
The maximum number of columns is determined by the current window
width and the longest string in LIST."
(unless pad-width
(setq pad-width 3))
(let ((width (window-width))
(max (+ (apply #'max (mapcar #'length list))
pad-width)))
(let ((columns (/ width max)))
(when (zerop columns)
(setq columns 1))
(while list
(dotimes (_ (1- columns))
(insert (concat (car list) (make-string (- max (length (car list)))
?\s)))
(setq list (cdr list)))
(when (not (null list))
(insert (pop list)))
(insert "\n")))))
(defsubst ibuffer-current-mark ()
(cadr (get-text-property (line-beginning-position)
'ibuffer-properties)))
(defun ibuffer-mouse-toggle-mark (event)
"Toggle the marked status of the buffer chosen with the mouse."
(interactive "e")
(unwind-protect
(let ((pt (save-excursion
(mouse-set-point event)
(point))))
(if-let* ((it (get-text-property (point) 'ibuffer-filter-group-name)))
(ibuffer-toggle-marks it)
(goto-char pt)
(let ((mark (ibuffer-current-mark)))
(setq buffer-read-only nil)
(if (eq mark ibuffer-marked-char)
(ibuffer-set-mark ?\s)
(ibuffer-set-mark ibuffer-marked-char)))))
(setq buffer-read-only t)))
(defun ibuffer-find-file (file &optional wildcards)
"Like `find-file', but default to the directory of the buffer at point."
(interactive
(let ((default-directory (let ((buf (ibuffer-current-buffer)))
(if (buffer-live-p buf)
(with-current-buffer buf
default-directory)
default-directory))))
(list (read-file-name "Find file: " default-directory)
t)))
(find-file file wildcards))
(defun ibuffer-mouse-visit-buffer (event)
"Visit the buffer chosen with the mouse."
(interactive "e")
(switch-to-buffer
(save-excursion
(mouse-set-point event)
(ibuffer-current-buffer t))))
(defun ibuffer-mouse-popup-menu (event)
"Display a menu of operations."
(interactive "e")
(let ((eventpt (posn-point (event-end event)))
(origpt (point)))
(unwind-protect
(if (get-text-property eventpt 'ibuffer-filter-group-name)
(progn
(goto-char eventpt)
(popup-menu ibuffer-mode-groups-popup))
(let ((inhibit-read-only t))
(ibuffer-save-marks
(ibuffer-unmark-all-marks)
(save-excursion
(goto-char eventpt)
(ibuffer-set-mark ibuffer-marked-char))
(save-excursion
(popup-menu ibuffer-mode-operate-menu)))))
(setq buffer-read-only t)
(if (= eventpt (point))
(goto-char origpt)))))
(defun ibuffer-skip-properties (props direction)
(while (and (not (eobp))
(let ((hit nil))
(dolist (prop props hit)
(when (get-text-property (point) prop)
(setq hit t)))))
(forward-line direction)
(beginning-of-line)))
(defun ibuffer-customize ()
"Begin customizing Ibuffer interactively."
(interactive)
(customize-group 'ibuffer))
(defun ibuffer-backward-line (&optional arg skip-group-names)
"Move backwards ARG lines, wrapping around the list if necessary."
(interactive "P")
(or arg (setq arg 1))
(beginning-of-line)
(while (> arg 0)
(forward-line -1)
(when (and ibuffer-movement-cycle
(or (get-text-property (point) 'ibuffer-title)
(and skip-group-names
(get-text-property (point)
'ibuffer-filter-group-name))))
(goto-char (point-max))
(beginning-of-line))
(ibuffer-skip-properties (append '(ibuffer-summary)
(when skip-group-names
'(ibuffer-filter-group-name)))
-1)
;; Handle the special case of no buffers.
(when (get-text-property (point) 'ibuffer-title)
(forward-line 1)
(setq arg 1))
(decf arg)))
(defun ibuffer-forward-line (&optional arg skip-group-names)
"Move forward ARG lines, wrapping around the list if necessary."
(interactive "P")
(or arg (setq arg 1))
(beginning-of-line)
(when (and ibuffer-movement-cycle
(or (eobp)
(get-text-property (point) 'ibuffer-summary)))
(goto-char (point-min)))
(when (or (get-text-property (point) 'ibuffer-title)
(and skip-group-names
(get-text-property (point) 'ibuffer-filter-group-name)))
(when (> arg 0)
(decf arg))
(ibuffer-skip-properties (append '(ibuffer-title)
(when skip-group-names
'(ibuffer-filter-group-name)))
1))
(if (< arg 0)
(ibuffer-backward-line (- arg))
(while (> arg 0)
(forward-line 1)
(when (and ibuffer-movement-cycle
(or (eobp)
(get-text-property (point) 'ibuffer-summary)))
(goto-char (point-min)))
(decf arg)
(ibuffer-skip-properties (append '(ibuffer-title)
(when skip-group-names
'(ibuffer-filter-group-name)))
1))))
(defun ibuffer-visit-buffer (&optional single)
"Visit the buffer on this line.
If optional argument SINGLE is non-nil, then also ensure there is only
one window."
(interactive "P")
(let ((buf (ibuffer-current-buffer t)))
(switch-to-buffer buf)
(when single
(delete-other-windows))))
(defun ibuffer-visit-buffer-other-window (&optional noselect)
"Visit the buffer on this line in another window."
(interactive)
(let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
(if noselect
(display-buffer buf)
(switch-to-buffer-other-window buf))))
(defun ibuffer-visit-buffer-other-window-noselect ()
"Visit the buffer on this line in another window, but don't select it."
(interactive)
(ibuffer-visit-buffer-other-window t))
(defun ibuffer-visit-buffer-other-frame ()
"Visit the buffer on this line in another frame."
(interactive)
(let ((buf (ibuffer-current-buffer t)))
(bury-buffer (current-buffer))
(switch-to-buffer-other-frame buf)))
(defun ibuffer-visit-buffer-1-window ()
"Visit the buffer on this line, and delete other windows."