* .config/jami.net/Jami.conf: Update.
[~bandali/configs] / .emacs.d / lisp / bandali-ibuffer.el
1 ;;; bandali-ibuffer.el --- bandali's Ibuffer setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: tools
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My Ibuffer setup.
24
25 ;;; Code:
26
27 (csetq
28 ibuffer-saved-filter-groups
29 '(("default"
30 ("dired" (mode . dired-mode))
31 ("org" (mode . org-mode))
32 ("gnus"
33 (or
34 (mode . gnus-group-mode)
35 (mode . gnus-summary-mode)
36 (mode . gnus-article-mode)
37 (mode . message-mode)))
38 ("web"
39 (or
40 (mode . mhtml-mode)
41 (mode . css-mode)
42 (mode . scss-mode)
43 (mode . js2-mode)))
44 ("shell"
45 (or
46 (mode . eshell-mode)
47 (mode . shell-mode)
48 (mode . term-mode)))
49 ("programming"
50 (or
51 (mode . python-mode)
52 (mode . c-mode)
53 (mode . c++-mode)
54 (mode . java-mode)
55 (mode . emacs-lisp-mode)
56 (mode . scheme-mode)
57 (mode . haskell-mode)
58 (mode . lean-mode)
59 ;; (mode . go-mode)
60 (mode . alloy-mode)))
61 ("tex"
62 (or
63 (mode . bibtex-mode)
64 (mode . latex-mode)))
65 ("emacs"
66 (or
67 (name . "^\\*scratch\\*$")
68 (name . "^\\*Messages\\*$")))
69 ("exwm" (mode . exwm-mode))
70 ("erc" (mode . erc-mode))))
71 ibuffer-formats
72 '((mark modified read-only locked " "
73 (name 72 72 :left :elide)
74 " "
75 (size-h 9 -1 :right)
76 " "
77 (mode 16 16 :left :elide)
78 " " filename-and-process)
79 (mark " "
80 (name 16 -1)
81 " " filename)))
82 (with-eval-after-load 'ibuffer
83 ;; Use human readable Size column instead of original one
84 (define-ibuffer-column size-h
85 (:name "Size" :inline t)
86 (cond
87 ((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
88 ((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
89 ((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
90 (t (format "%8d" (buffer-size)))))
91
92 ;; local key bindings
93 (define-key ibuffer-mode-map (kbd "P")
94 #'ibuffer-backward-filter-group)
95 (define-key ibuffer-mode-map (kbd "N")
96 #'ibuffer-forward-filter-group)
97 (define-key ibuffer-mode-map (kbd "M-p")
98 #'ibuffer-do-print)
99 (define-key ibuffer-mode-map (kbd "M-n")
100 #'ibuffer-do-shell-command-pipe-replace))
101 ;; global key bindings
102 (global-set-key (kbd "C-x C-b") #'ibuffer)
103 ;; hooks
104 (declare-function ibuffer-switch-to-saved-filter-groups "ibuf-ext"
105 (name))
106 (add-hook 'ibuffer-hook
107 (lambda () (ibuffer-switch-to-saved-filter-groups "default")))
108
109 (provide 'bandali-ibuffer)
110 ;;; bandali-ibuffer.el ends here