From 2c9fa6ec14966321ab04da35d587eb99612f0cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 31 Aug 2022 16:03:00 +0200 Subject: eb.el: Run fleeting window close code consistently. --- eb.el | 64 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/eb.el b/eb.el index 5233c9c..ec9557e 100644 --- a/eb.el +++ b/eb.el @@ -41,10 +41,21 @@ ;; Fleeting minor mode. +(defvar eb--fleeting--buffer nil) +(defvar eb--fleeting--window nil) +(defvar-local eb--fleeting--close nil) +(defvar-local eb--fleeting--direction nil) + ;;;###autoload (define-minor-mode eb--fleeting-minor-mode "Minor mode for transient buffer selection pop-up windows." - :lighter "") + :lighter "" + (if eb--fleeting-minor-mode + (let ((refit (lambda (window) (let ((fit-window-to-buffer-horizontally t)) + (fit-window-to-buffer window))))) + (funcall refit (get-buffer-window)) + (run-with-idle-timer 0 nil refit (get-buffer-window))) + (eval eb--fleeting--close))) (defmacro eb--fleeting-window (dir buffer &optional open close) (declare (indent 2)) @@ -53,12 +64,10 @@ (cwd default-directory)) (if (equal buffer (window-buffer)) (progn - ,close (eb--fleeting-minor-mode -1) (quit-window) nil) (when eb--fleeting-minor-mode - ,close (eb--fleeting-minor-mode -1) (quit-window)) (display-buffer-in-direction buffer '((direction . ,dir))) @@ -66,19 +75,13 @@ (select-window window) (with-current-buffer buffer (setq default-directory cwd) + (setq eb--fleeting--close ',close) ,open - (eb--fleeting-minor-mode) + (eb--fleeting-minor-mode 1) + (message "%s" eb--fleeting-minor-mode) (setq eb--fleeting--direction ',dir)) - (run-with-idle-timer 0 nil (lambda (window) - (let ((fit-window-to-buffer-horizontally t)) - (fit-window-to-buffer window))) - window) window))))) -(defvar eb--fleeting--buffer nil) -(defvar eb--fleeting--window nil) -(defvar-local eb--fleeting--direction nil) - (defun eb--fleeting--main-window (&optional fleeting-buffer fleeting-window) (setq fleeting-buffer (or fleeting-buffer (current-buffer))) (setq fleeting-window (or fleeting-window (selected-window))) @@ -105,24 +108,25 @@ (when (and fleeting-buffer fleeting-window (not (equal window (minibuffer-window)))) - (if (and (equal fleeting-window window) - (equal fleeting-buffer buffer)) - (with-current-buffer fleeting-buffer - (eb--fleeting-minor-mode -1)) - (if (and (equal fleeting-window window) - (not (equal fleeting-buffer buffer))) - (progn - (with-current-buffer fleeting-buffer - (eb--fleeting-minor-mode -1)) - (bury-buffer fleeting-buffer) - (setq eb--fleeting--window nil) - (select-window (eb--fleeting--main-window fleeting-buffer fleeting-window)) - (switch-to-buffer buffer) - (delete-window fleeting-window)) - (if (get-buffer-window fleeting-buffer) - (delete-window fleeting-window) - (with-current-buffer fleeting-buffer - (eb--fleeting-minor-mode -1)))))))) + (cond + ((and (equal fleeting-window window) + (equal fleeting-buffer buffer)) + (with-current-buffer fleeting-buffer + (eb--fleeting-minor-mode -1))) + ((and (equal fleeting-window window) + (not (equal fleeting-buffer buffer))) + (with-current-buffer fleeting-buffer + (eb--fleeting-minor-mode -1)) + (bury-buffer fleeting-buffer) + (setq eb--fleeting--window nil) + (select-window (eb--fleeting--main-window fleeting-buffer fleeting-window)) + (switch-to-buffer buffer) + (delete-window fleeting-window)) + (t + (with-current-buffer fleeting-buffer + (eb--fleeting-minor-mode -1)) + (when (get-buffer-window fleeting-buffer) + (delete-window fleeting-window))))))) (add-hook 'window-configuration-change-hook #'eb--fleeting--window-hook) (add-hook 'window-selection-change-functions #'eb--fleeting--window-hook) -- cgit v1.2.3