feature/popup: move hacks to +hacks.el
This commit is contained in:
parent
4bd74d9653
commit
d675ade45d
2 changed files with 164 additions and 118 deletions
|
@ -158,121 +158,4 @@ ALIST supports one custom parameter: `size', which will resolve to
|
|||
;; Hacks
|
||||
;;
|
||||
|
||||
(advice-add #'balance-windows :around #'+popup*save)
|
||||
|
||||
(defun doom*ignore-window-parameters (orig-fn &rest args)
|
||||
"Allow *interactive* window moving commands to traverse popups."
|
||||
(cl-letf (((symbol-function #'windmove-find-other-window)
|
||||
(lambda (dir &optional arg window)
|
||||
(window-in-direction
|
||||
(pcase dir (`up 'above) (`down 'below) (_ dir))
|
||||
window (bound-and-true-p +popup-mode) arg windmove-wrap-around t))))
|
||||
(apply orig-fn args)))
|
||||
(advice-add #'windmove-up :around #'doom*ignore-window-parameters)
|
||||
(advice-add #'windmove-down :around #'doom*ignore-window-parameters)
|
||||
(advice-add #'windmove-left :around #'doom*ignore-window-parameters)
|
||||
(advice-add #'windmove-right :around #'doom*ignore-window-parameters)
|
||||
|
||||
;; `help-mode'
|
||||
(after! help-mode
|
||||
(defun doom--switch-from-popup (location)
|
||||
(let (origin)
|
||||
(save-popups!
|
||||
(switch-to-buffer (car location) nil t)
|
||||
(if (not (cdr location))
|
||||
(message "Unable to find location in file")
|
||||
(goto-char (cdr location))
|
||||
(recenter)
|
||||
(setq origin (selected-window))))
|
||||
(+popup/close)
|
||||
(select-window origin)))
|
||||
|
||||
;; Help buffers use `pop-to-window' to decide where to open followed links,
|
||||
;; which can be unpredictable. It should *only* replace the original buffer we
|
||||
;; opened the popup from. To fix this these three button types need to be
|
||||
;; redefined to set aside the popup before following a link.
|
||||
(define-button-type 'help-function-def
|
||||
:supertype 'help-xref
|
||||
'help-function
|
||||
(lambda (fun file)
|
||||
(require 'find-func)
|
||||
(when (eq file 'C-source)
|
||||
(setq file (help-C-file-name (indirect-function fun) 'fun)))
|
||||
(doom--switch-from-popup (find-function-search-for-symbol fun nil file))))
|
||||
|
||||
(define-button-type 'help-variable-def
|
||||
:supertype 'help-xref
|
||||
'help-function
|
||||
(lambda (var &optional file)
|
||||
(when (eq file 'C-source)
|
||||
(setq file (help-C-file-name var 'var)))
|
||||
(doom--switch-from-popup (find-variable-noselect var file))))
|
||||
|
||||
(define-button-type 'help-face-def
|
||||
:supertype 'help-xref
|
||||
'help-function
|
||||
(lambda (fun file)
|
||||
(require 'find-func)
|
||||
(doom--switch-from-popup (find-function-search-for-symbol fun 'defface file)))))
|
||||
|
||||
;; `neotree'
|
||||
(after! neotree
|
||||
(advice-remove #'balance-windows #'ad-Advice-balance-windows))
|
||||
|
||||
;; `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\\|Links\\)" '((slot . -1) (size . shrink-window-if-larger-than-buffer)))
|
||||
(set! :popup "^\\*Org Agenda" '((slot . -1) (size . 20)))
|
||||
(set! :popup "^\\*Org Src" '((size . 0.3)) '((quit) (select . t)))
|
||||
|
||||
;; 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
|
||||
;; ourselves.
|
||||
(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 doom*org-src-pop-to-buffer (buffer _context)
|
||||
"Hand off the src-block window to the popup system by using `display-buffer'
|
||||
instead of switch-to-buffer-*."
|
||||
(if (eq org-src-window-setup 'switch-invisibly) ; for internal calls
|
||||
(set-buffer buffer)
|
||||
(display-buffer buffer)))
|
||||
(advice-add #'org-src-switch-to-buffer :override #'doom*org-src-pop-to-buffer)
|
||||
(setq org-src-window-setup 'other-window)
|
||||
|
||||
;; Ensure todo, agenda, and other minor popups are delegated to the popup system.
|
||||
(defun +popup*org-pop-to-buffer (buf &optional _norecord)
|
||||
"Use `pop-to-buffer' instead of `switch-to-buffer' to open buffer.'"
|
||||
(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)
|
||||
(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)
|
||||
(+popup--init window))))
|
||||
(advice-add #'persp-load-state-from-file :after #'+popup*persp-mode-restore-popups))
|
||||
|
||||
(load! +hacks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue