aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-27 02:01:43 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-27 02:01:43 +0200
commit2f10a264ab96bf53342c9e0042b7d9fedb60ce7f (patch)
tree84768201fa7bd27c231f6f43f32ce621108e5019
parent271a8bfa2ed3c5ea864cfb9183b568508f8177e0 (diff)
downloadEpisodeBrowser-2f10a264ab96bf53342c9e0042b7d9fedb60ce7f.tar.gz
eb.el: Add eb-quit-or-bury.
-rw-r--r--eb.el41
1 files 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