feature/popup: add hacks for wgrep, org, persp-mode & balance-windows

Plus +popup*close and +popup*save advice functions.
This commit is contained in:
Henrik Lissner 2018-01-06 04:56:39 -05:00
parent a9a731c1eb
commit eedd86135e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 68 additions and 1 deletions

View file

@ -324,3 +324,18 @@ prevent the popup(s) from messing up the UI (or vice versa)."
(unless in-popup-p (unless in-popup-p
(select-window origin))))))) (select-window origin)))))))
;;
;; Advice
;;
;;;###autoload
(defun +popup*close (&rest _)
"TODO"
(+popup/close))
;;;###autoload
(defun +popup*save (orig-fn &rest args)
"Sets aside all popups before executing the original function, usually to
prevent the popup(s) from messing up the UI (or vice versa)."
(save-popups! (apply orig-fn args)))

View file

@ -141,6 +141,8 @@ ALIST supports one custom parameter: `size', which will resolve to
;; Hacks ;; Hacks
;; ;;
(advice-add #'balance-windows :around #'+popup*save)
(defun doom*ignore-window-parameters (orig-fn &rest args) (defun doom*ignore-window-parameters (orig-fn &rest args)
"Allow *interactive* window moving commands to traverse popups." "Allow *interactive* window moving commands to traverse popups."
(cl-letf (((symbol-function #'windmove-find-other-window) (cl-letf (((symbol-function #'windmove-find-other-window)
@ -154,7 +156,7 @@ ALIST supports one custom parameter: `size', which will resolve to
(advice-add #'windmove-left :around #'doom*ignore-window-parameters) (advice-add #'windmove-left :around #'doom*ignore-window-parameters)
(advice-add #'windmove-right :around #'doom*ignore-window-parameters) (advice-add #'windmove-right :around #'doom*ignore-window-parameters)
;; `help-mode'
(after! help-mode (after! help-mode
(defun doom--switch-from-popup (location) (defun doom--switch-from-popup (location)
(let (origin) (let (origin)
@ -196,5 +198,55 @@ ALIST supports one custom parameter: `size', which will resolve to
(require 'find-func) (require 'find-func)
(doom--switch-from-popup (find-function-search-for-symbol fun 'defface file))))) (doom--switch-from-popup (find-function-search-for-symbol fun 'defface file)))))
;; `wgrep'
(after! wgrep
;; close the popup after you're done with a wgrep buffer
(advice-add #'wgrep-abort-changes :after #'+popup*close)
(advice-add #'wgrep-finish-edit :after #'+popup*close))
;; `org'
(after! org
(set! :popup "^ \\*Org todo" '((size . 5)) '((transient . 0)))
(set! :popup "^\\*Org Agenda" '((size . 20)))
;; Org has a scorched-earth window management system I'm not fond of. i.e.
;; it kills all windows and monopolizes the frame. No thanks. We can do
;; better with shackle's help.
(defun +popup*suppress-delete-other-windows (orig-fn &rest args)
(cl-letf (((symbol-function 'delete-other-windows)
(symbol-function 'ignore)))
(apply orig-fn args)))
(advice-add #'org-add-log-note :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-capture-place-template :around #'+popup*suppress-delete-other-windows)
(advice-add #'org-export--dispatch-ui :around #'+popup*suppress-delete-other-windows)
(defun +popup*org-pop-to-buffer (&rest args)
"Use `pop-to-buffer' instead of `switch-to-buffer' to open buffer.'"
(let ((buf (car args)))
(pop-to-buffer
(cond ((stringp buf) (get-buffer-create buf))
((bufferp buf) buf)
(t (error "Invalid buffer %s" buf))))))
(advice-add #'org-switch-to-buffer-other-window :override #'+popup*org-pop-to-buffer)
;; `org-agenda'
(setq org-agenda-window-setup 'other-window
org-agenda-restore-windows-after-quit nil)
;; Hide modeline in org-agenda
(add-hook 'org-agenda-finalize-hook #'doom-hide-modeline-mode)
(add-hook 'org-agenda-finalize-hook #'org-fit-window-to-buffer)
;; Don't monopolize frame!
(advice-add #'org-agenda :around #'+popup*suppress-delete-other-windows))
;; `persp-mode'
(after! persp-mode
(defun +popup*persp-mode-restore-popups (&rest _)
"Restore popup windows when loading a perspective from file."
(dolist (window (window-list))
(when (+popup-parameter 'popup window)
(with-selected-window window
(+popup-buffer-mode +1)))))
(advice-add #'persp-load-state-from-file :after #'+popup*persp-mode-restore-popups))
(provide 'config) (provide 'config)
;;; config.el ends here ;;; config.el ends here