diff options
author | JSDurand <mmemmew@gmail.com> | 2021-08-08 16:49:34 +0800 |
---|---|---|
committer | JSDurand <mmemmew@gmail.com> | 2021-08-08 16:49:34 +0800 |
commit | ddd919fc18f2588ca0dcf842daf9c75760cdc4fe (patch) | |
tree | 61966369ff03c747fbaf1dd2de4aa1aa8aa1e708 | |
parent | 4316b60be16909097316b7dc3904c9497b58d04a (diff) |
change: add a pass list and some filters
* ibuffer.el (dashboard-buffer-name): to be added to the pass list.
(durand-clear-passlist): Buffer names listed in this variable will not
be deleted automatically.
(durand-ibuffer-clear): Do not delete those buffers whose names are a
member of `durand-clear-passlist'.
(durand-directory): a filter for matching files whose associated files
are in a subdirectory of the qualifier. This needs more testing,
though.
(durand-bongo-set-filter): Add groups for C, ELisp, EWW, and Roman.
-rw-r--r-- | ibuffer.el | 58 |
1 files changed, 50 insertions, 8 deletions
@@ -3,8 +3,8 @@ (require 'ibuffer) (require 'ibuf-ext) -(setq ibuffer-expert t - ibuffer-display-summary nil) +(setq ibuffer-expert t) +(setq ibuffer-display-summary nil) (setq ibuffer-show-empty-filter-groups nil) @@ -74,22 +74,40 @@ If the optional ARG is non-nil, then produce an IBUFFER buffer (buffer-local-value 'major-mode (current-buffer)))))))) ;;;###autoload +(defvar durand-clear-passlist nil + "The list of buffers that should not be deleted \ +automatically.") + +;; from dashboard.el +(defvar dashboard-buffer-name) + +(cond + ((null dashboard-buffer-name) + (setq dashboard-buffer-name ""))) + +(setq durand-clear-passlist + (list dashboard-buffer-name + "*Group*" + ".newsrc-dribble")) + +;;;###autoload (defun durand-ibuffer-clear (&optional arg) - "Kill every buffer except for the dashboard. + "Kill every buffer except for those in `durand-clear-passlist'. If the optional ARG is non-nil, then kill every buffer except for those that are marked." (interactive "P") (cond ((derived-mode-p 'ibuffer-mode)) ((user-error "durand-ibuffer-clear should only be used in \ -derived modes of ibuffer-mode."))) +derived modes of `ibuffer-mode'."))) (cond ((null arg) (mapc (function (lambda (buffer) (cond - ((string= (buffer-name buffer) - dashboard-buffer-name)) + ((durand-member (buffer-name buffer) + durand-clear-passlist + #'string=)) ((kill-buffer buffer))))) (cons (current-buffer) @@ -144,12 +162,36 @@ derived modes of ibuffer-mode."))) ((derived-mode-p 'bongo-playlist-mode 'bongo-library-mode))))) ;;;###autoload +(define-ibuffer-filter durand-directory + "Limit current view to buffers with directory a subdirectory of \ +QUALIFIER. + +For a buffer not associated with a file, this matches against the +value of `default-directory' in that buffer." + (:description "directory name" + :reader (read-from-minibuffer "Filter by directory name (regex): ")) + (ibuffer-aif (with-current-buffer buf (ibuffer-buffer-file-name)) + (let ((dirname (expand-file-name (file-name-directory it)))) + (when dirname + (string-match-p + (expand-file-name qualifier) + dirname))) + (when (with-current-buffer buf default-directory) + (string-match-p (expand-file-name qualifier) + (expand-file-name + (with-current-buffer buf + default-directory)))))) + +;;;###autoload (defun durand-bongo-set-filter () "Set my custom filters." (interactive) (setq ibuffer-filter-groups - (cons (cons "Bongo" '((durand-bongo))) - ibuffer-filter-groups)) + (list (cons "Bongo" '((durand-bongo))) + (cons "C" '((mode . c-mode))) + (cons "ELisp" '((mode . emacs-lisp-mode))) + (cons "EWW" '((mode . eww-mode))) + (cons "Roman" '((mode . novel-read-mode))))) (let ((ibuf (get-buffer "*Ibuffer*"))) (when ibuf (with-current-buffer ibuf |