From ddd919fc18f2588ca0dcf842daf9c75760cdc4fe Mon Sep 17 00:00:00 2001 From: JSDurand Date: Sun, 8 Aug 2021 16:49:34 +0800 Subject: 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. --- ibuffer.el | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 50 insertions(+), 8 deletions(-) (limited to 'ibuffer.el') diff --git a/ibuffer.el b/ibuffer.el index 93f6ccd..e1cf4ec 100644 --- a/ibuffer.el +++ b/ibuffer.el @@ -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) @@ -73,23 +73,41 @@ If the optional ARG is non-nil, then produce an IBUFFER buffer (list (cons 'used-mode (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) @@ -143,13 +161,37 @@ derived modes of ibuffer-mode."))) found)) ((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 -- cgit v1.2.3-18-g5258