Skip to content

Commit

Permalink
Merge pull request #177 from wyuenho/fix-dangling-popup
Browse files Browse the repository at this point in the history
Fix #153 delete popup window where there aren't any prev buffers
  • Loading branch information
wyuenho committed Mar 2, 2021
2 parents cb61b93 + eb98688 commit c85dd3c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions window-purpose-x.el
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,16 @@ the popup window doesn't need to close."
(purpose-x-popwin-close-windows)
(purpose-x-popwin-remove-hooks))))

(defun purpose-x-popwin-quit-restore-window-advice (fn &optional window bury-or-kill)
"Close pop up window when there aren't previous buffers can be shown in it."
(when-let* ((window (ignore-errors (window-normalize-window window t))))
(funcall fn window bury-or-kill)
(when (and (window-live-p window)
;; quit-restore-window did not kill window
(null (window-parameter window 'quit-restore))
(not (window-prev-buffers window)))
(ignore-errors (delete-window window)))))

;;;###autoload
(defun purpose-x-popwin-setup ()
"Activate `popwin' emulation.
Expand All @@ -521,14 +531,16 @@ Look at `purpose-x-popwin-*' variables and functions to learn more."
(purpose-x-popwin-update-conf)
(setq purpose-special-action-sequences
(cl-delete 'popup purpose-special-action-sequences :key #'car))
(purpose-x-popupify-purpose 'popup #'purpose-x-popwin-display-buffer))
(purpose-x-popupify-purpose 'popup #'purpose-x-popwin-display-buffer)
(advice-add 'quit-restore-window :around 'purpose-x-popwin-quit-restore-window-advice))

(defun purpose-x-popwin-unset ()
"Deactivate `popwin' emulation."
(interactive)
(purpose-del-extension-configuration :popwin)
(purpose-x-unpopupify-purpose 'popup)
(purpose-x-popwin-remove-hooks))
(purpose-x-popwin-remove-hooks)
(advice-remove 'quit-restore-window 'purpose-x-popwin-quit-restore-window-advice))

;;; --- purpose-x-popup ends here ---

Expand Down

0 comments on commit c85dd3c

Please sign in to comment.