From 2f10a264ab96bf53342c9e0042b7d9fedb60ce7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sat, 27 Aug 2022 02:01:43 +0200 Subject: eb.el: Add eb-quit-or-bury. --- eb.el | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/eb.el b/eb.el index 4d9b430..7477372 100644 --- a/eb.el +++ b/eb.el @@ -46,17 +46,19 @@ "List project buffers." (interactive "P") (require 'projectile) - (let ((buffer - (list-buffers-noselect (not arg) - (if arg - (projectile-project-buffers) - (mapcan - (lambda (b) (and (buffer-file-name b) (list b))) - (projectile-project-buffers)))))) - (display-buffer-in-direction buffer '((direction . up))) - (select-window (get-buffer-window buffer)) - (with-current-buffer buffer - (setq-local eb--list-buffers t)))) + (if eb--list-buffers + (quit-window) + (let ((buffer + (list-buffers-noselect (not arg) + (if arg + (projectile-project-buffers) + (mapcan + (lambda (b) (and (buffer-file-name b) (list b))) + (projectile-project-buffers)))))) + (display-buffer-in-direction buffer '((direction . up))) + (select-window (get-buffer-window buffer)) + (with-current-buffer buffer + (setq-local eb--list-buffers t))))) (define-advice Buffer-menu-mouse-select (:around (f event) eb-list-buffers) (if eb--list-buffers @@ -71,7 +73,18 @@ (defun eb-dired () "Open the root of the current project with `dired'." (interactive) - (dired (project-root (project-current)))) + (let ((project-root (project-root (project-current)))) + (if (and (eq major-mode 'dired-mode) (equal default-directory project-root)) + (bury-buffer) + (dired project-root)))) + +;;;###autoload +(defun eb-quit-or-bury () + "Quit window or bury buffer." + (interactive) + (if (window-parameter (selected-window) 'quit-restore) + (quit-window) + (bury-buffer))) (defvar-local eb-tool-bar-mode--old-map nil) (defvar-local eb-tool-bar-mode--old-back-button-mode nil) @@ -90,8 +103,8 @@ (back-button-mode 1) (setq-local back-button-show-toolbar-buttons nil) (let ((map (make-sparse-keymap))) - (tool-bar-local-item "close" #'bury-buffer 'bury-buffer map - :label "Bury" :help "Bury buffer") + (tool-bar-local-item "close" #'eb-quit-or-bury 'quit-or-bury map + :label "Bury" :help "Bury buffer or window") (tool-bar-local-item "index" #'eb-list-buffers 'list-buffers map :label "Buffers" :help "Show project buffers") (tool-bar-local-item "diropen" #'eb-dired 'dired map -- cgit v1.2.3