From eef71477ce8484a1faeacb28de1a71ee4365eda7 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Tue, 1 Jun 2021 18:07:30 +0800 Subject: Add a key-binding to clear buffers in ibuffer. * ibuffer.el (durand-ibuffer-clear): This is my frequent operation. (ibuffer-mode-map): Bind to a key. --- ibuffer.el | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/ibuffer.el b/ibuffer.el index 8d77296..a6910d0 100644 --- a/ibuffer.el +++ b/ibuffer.el @@ -73,6 +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 +(defun durand-ibuffer-clear (&optional arg) + "Kill every buffer except for the dashboard. +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."))) + (cond + ((null arg) + (mapc (function + (lambda (buffer) + (cond + ((string= (buffer-name buffer) + dashboard-buffer-name)) + ((kill-buffer buffer))))) + (cons + (current-buffer) + (mapcar #'car (ibuffer-current-state-list))))) + (t + (mapc (function + (lambda (buffer-and-mark) + (cond + ((or (/= (cdr buffer-and-mark) + ibuffer-marked-char) + (string= (buffer-name (car buffer-and-mark)) + dashboard-buffer-name))) + ((kill-buffer (car buffer-and-mark)))))) + (cons + (cons (current-buffer) 32) + (ibuffer-current-state-list))) + (ibuffer-update nil)))) + (define-key global-map (vector 24 2) #'ibuffer) (define-key global-map (vector ?\s-h) #'ibuffer) (define-key global-map (vector ?\M-\s-b) #'switch-to-buffer-same-mode) @@ -83,6 +118,7 @@ If the optional ARG is non-nil, then produce an IBUFFER buffer (define-key ibuffer-mode-map (vector ?d) #'ibuffer-do-delete) (define-key ibuffer-mode-map (vector ?D) #'ibuffer-mark-for-delete) +(define-key ibuffer-mode-map (vector ?c) #'durand-ibuffer-clear) ;;; filter for bongo -- cgit v1.2.3-18-g5258