core-popups: attach popup hacks to window-setup-hook (fix #29)
This commit is contained in:
parent
ccabb9f6ee
commit
2a9a1ef186
1 changed files with 156 additions and 155 deletions
|
@ -212,188 +212,189 @@ properties."
|
||||||
;; Hacks
|
;; Hacks
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(after! evil
|
(add-hook! 'window-setup-hook
|
||||||
(let ((map doom-popup-mode-map))
|
(after! evil
|
||||||
(define-key map [remap evil-window-delete] 'doom/popup-close)
|
(let ((map doom-popup-mode-map))
|
||||||
(define-key map [remap evil-window-move-very-bottom] 'ignore)
|
(define-key map [remap evil-window-delete] 'doom/popup-close)
|
||||||
(define-key map [remap evil-window-move-very-top] 'ignore)
|
(define-key map [remap evil-window-move-very-bottom] 'ignore)
|
||||||
(define-key map [remap evil-window-move-far-left] 'ignore)
|
(define-key map [remap evil-window-move-very-top] 'ignore)
|
||||||
(define-key map [remap evil-window-move-far-right] 'ignore)
|
(define-key map [remap evil-window-move-far-left] 'ignore)
|
||||||
(define-key map [remap evil-window-split] 'ignore)
|
(define-key map [remap evil-window-move-far-right] 'ignore)
|
||||||
(define-key map [remap evil-window-vsplit] 'ignore)
|
(define-key map [remap evil-window-split] 'ignore)
|
||||||
(define-key map [remap evil-force-normal-state] 'doom/popup-close-maybe))
|
(define-key map [remap evil-window-vsplit] 'ignore)
|
||||||
|
(define-key map [remap evil-force-normal-state] 'doom/popup-close-maybe))
|
||||||
|
|
||||||
;; Make evil-mode cooperate with popups
|
;; Make evil-mode cooperate with popups
|
||||||
(advice-add 'evil-command-window :override 'doom*popup-evil-command-window)
|
(advice-add 'evil-command-window :override 'doom*popup-evil-command-window)
|
||||||
(advice-add 'evil-command-window-execute :override 'doom*popup-evil-command-window-execute)
|
(advice-add 'evil-command-window-execute :override 'doom*popup-evil-command-window-execute)
|
||||||
|
|
||||||
(defun doom*popup-evil-command-window (hist cmd-key execute-fn)
|
(defun doom*popup-evil-command-window (hist cmd-key execute-fn)
|
||||||
"The evil command window has a mind of its own (uses `switch-to-buffer'). We
|
"The evil command window has a mind of its own (uses `switch-to-buffer'). We
|
||||||
monkey patch it to use pop-to-buffer, and to remember the previous window."
|
monkey patch it to use pop-to-buffer, and to remember the previous window."
|
||||||
(when (eq major-mode 'evil-command-window-mode)
|
(when (eq major-mode 'evil-command-window-mode)
|
||||||
(user-error "Cannot recursively open command line window"))
|
(user-error "Cannot recursively open command line window"))
|
||||||
(dolist (win (window-list))
|
(dolist (win (window-list))
|
||||||
(when (equal (buffer-name (window-buffer win))
|
(when (equal (buffer-name (window-buffer win))
|
||||||
"*Command Line*")
|
"*Command Line*")
|
||||||
(kill-buffer (window-buffer win))
|
(kill-buffer (window-buffer win))
|
||||||
(delete-window win)))
|
(delete-window win)))
|
||||||
(setq evil-command-window-current-buffer (current-buffer))
|
(setq evil-command-window-current-buffer (current-buffer))
|
||||||
(ignore-errors (kill-buffer "*Command Line*"))
|
(ignore-errors (kill-buffer "*Command Line*"))
|
||||||
(with-current-buffer (pop-to-buffer "*Command Line*")
|
(with-current-buffer (pop-to-buffer "*Command Line*")
|
||||||
(setq-local evil-command-window-execute-fn execute-fn)
|
(setq-local evil-command-window-execute-fn execute-fn)
|
||||||
(setq-local evil-command-window-cmd-key cmd-key)
|
(setq-local evil-command-window-cmd-key cmd-key)
|
||||||
(evil-command-window-mode)
|
(evil-command-window-mode)
|
||||||
(evil-command-window-insert-commands hist)))
|
(evil-command-window-insert-commands hist)))
|
||||||
|
|
||||||
(defun doom*popup-evil-command-window-execute ()
|
(defun doom*popup-evil-command-window-execute ()
|
||||||
"Execute the command under the cursor in the appropriate buffer, rather than
|
"Execute the command under the cursor in the appropriate buffer, rather than
|
||||||
the command buffer."
|
the command buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((result (buffer-substring (line-beginning-position)
|
(let ((result (buffer-substring (line-beginning-position)
|
||||||
(line-end-position)))
|
(line-end-position)))
|
||||||
(execute-fn evil-command-window-execute-fn)
|
(execute-fn evil-command-window-execute-fn)
|
||||||
(popup (selected-window)))
|
(popup (selected-window)))
|
||||||
(select-window doom-popup-other-window)
|
(select-window doom-popup-other-window)
|
||||||
(unless (equal evil-command-window-current-buffer (current-buffer))
|
(unless (equal evil-command-window-current-buffer (current-buffer))
|
||||||
(user-error "Originating buffer is no longer active"))
|
(user-error "Originating buffer is no longer active"))
|
||||||
;; (kill-buffer "*Command Line*")
|
;; (kill-buffer "*Command Line*")
|
||||||
(doom/popup-close popup)
|
(doom/popup-close popup)
|
||||||
(funcall execute-fn result)
|
(funcall execute-fn result)
|
||||||
(setq evil-command-window-current-buffer nil)))
|
(setq evil-command-window-current-buffer nil)))
|
||||||
|
|
||||||
;; Don't mess with popups
|
;; Don't mess with popups
|
||||||
(advice-add 'doom-evil-window-move :around 'doom*popups-save)
|
(advice-add 'doom-evil-window-move :around 'doom*popups-save)
|
||||||
(advice-add 'evil-window-move-very-bottom :around 'doom*popups-save)
|
(advice-add 'evil-window-move-very-bottom :around 'doom*popups-save)
|
||||||
(advice-add 'evil-window-move-very-top :around 'doom*popups-save)
|
(advice-add 'evil-window-move-very-top :around 'doom*popups-save)
|
||||||
(advice-add 'evil-window-move-far-left :around 'doom*popups-save)
|
(advice-add 'evil-window-move-far-left :around 'doom*popups-save)
|
||||||
(advice-add 'evil-window-move-far-right :around 'doom*popups-save)
|
(advice-add 'evil-window-move-far-right :around 'doom*popups-save)
|
||||||
|
|
||||||
;; Don't block moving to/from popup windows
|
;; Don't block moving to/from popup windows
|
||||||
(defun doom*ignore-window-parameters-in-popups (dir &optional arg window)
|
(defun doom*ignore-window-parameters-in-popups (dir &optional arg window)
|
||||||
(window-in-direction (cond ((eq dir 'up) 'above)
|
(window-in-direction (cond ((eq dir 'up) 'above)
|
||||||
((eq dir 'down) 'below)
|
((eq dir 'down) 'below)
|
||||||
(t dir))
|
(t dir))
|
||||||
window t arg windmove-wrap-around t))
|
window t arg windmove-wrap-around t))
|
||||||
(advice-add 'windmove-find-other-window :override 'doom*ignore-window-parameters-in-popups))
|
(advice-add 'windmove-find-other-window :override 'doom*ignore-window-parameters-in-popups))
|
||||||
|
|
||||||
|
|
||||||
(after! help-mode
|
(after! help-mode
|
||||||
;; Help buffers use `other-window' to decide where to open followed links,
|
;; Help buffers use `other-window' to decide where to open followed links,
|
||||||
;; which can be unpredictable. It should *only* replace the original buffer we
|
;; 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
|
;; opened the popup from. To fix this these three button types need to be
|
||||||
;; redefined to set aside the popup before following a link.
|
;; redefined to set aside the popup before following a link.
|
||||||
(defsubst doom--switch-from-popup (location)
|
(defsubst doom--switch-from-popup (location)
|
||||||
(doom/popup-close)
|
(doom/popup-close)
|
||||||
(switch-to-buffer (car location) nil t)
|
(switch-to-buffer (car location) nil t)
|
||||||
(if (not (cdr location))
|
(if (not (cdr location))
|
||||||
(message "Unable to find location in file")
|
(message "Unable to find location in file")
|
||||||
(goto-char (cdr location))
|
(goto-char (cdr location))
|
||||||
(recenter)))
|
(recenter)))
|
||||||
|
|
||||||
(define-button-type 'help-function-def
|
(define-button-type 'help-function-def
|
||||||
:supertype 'help-xref
|
:supertype 'help-xref
|
||||||
'help-function
|
'help-function
|
||||||
(lambda (fun file)
|
(lambda (fun file)
|
||||||
(require 'find-func)
|
(require 'find-func)
|
||||||
(when (eq file 'C-source)
|
(when (eq file 'C-source)
|
||||||
(setq file (help-C-file-name (indirect-function fun) 'fun)))
|
(setq file (help-C-file-name (indirect-function fun) 'fun)))
|
||||||
(doom--switch-from-popup (find-function-search-for-symbol fun nil file))))
|
(doom--switch-from-popup (find-function-search-for-symbol fun nil file))))
|
||||||
|
|
||||||
(define-button-type 'help-variable-def
|
(define-button-type 'help-variable-def
|
||||||
:supertype 'help-xref
|
:supertype 'help-xref
|
||||||
'help-function
|
'help-function
|
||||||
(lambda (var &optional file)
|
(lambda (var &optional file)
|
||||||
(when (eq file 'C-source)
|
(when (eq file 'C-source)
|
||||||
(setq file (help-C-file-name var 'var)))
|
(setq file (help-C-file-name var 'var)))
|
||||||
(doom--switch-from-popup (find-variable-noselect var file))))
|
(doom--switch-from-popup (find-variable-noselect var file))))
|
||||||
|
|
||||||
(define-button-type 'help-face-def
|
(define-button-type 'help-face-def
|
||||||
:supertype 'help-xref
|
:supertype 'help-xref
|
||||||
'help-function
|
'help-function
|
||||||
(lambda (fun file)
|
(lambda (fun file)
|
||||||
(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)))))
|
||||||
|
|
||||||
|
|
||||||
;; (after! magit
|
;; (after! magit
|
||||||
;; ;; Don't open files (from magit) within the magit popup
|
;; ;; Don't open files (from magit) within the magit popup
|
||||||
;; (advice-add 'magit-display-file-buffer-traditional :around 'doom*popups-save))
|
;; (advice-add 'magit-display-file-buffer-traditional :around 'doom*popups-save))
|
||||||
|
|
||||||
|
|
||||||
(after! neotree
|
(after! neotree
|
||||||
(defun doom*popups-save-neotree (orig-fn &rest args)
|
(defun doom*popups-save-neotree (orig-fn &rest args)
|
||||||
"Prevents messing up the neotree buffer on window changes."
|
"Prevents messing up the neotree buffer on window changes."
|
||||||
(let ((neo-p (and (featurep 'neotree)
|
(let ((neo-p (and (featurep 'neotree)
|
||||||
(neo-global--window-exists-p))))
|
(neo-global--window-exists-p))))
|
||||||
(when neo-p
|
|
||||||
(neotree-hide))
|
|
||||||
(unwind-protect (apply orig-fn args)
|
|
||||||
(when neo-p
|
(when neo-p
|
||||||
(save-selected-window
|
(neotree-hide))
|
||||||
(neotree-show))))))
|
(unwind-protect (apply orig-fn args)
|
||||||
|
(when neo-p
|
||||||
|
(save-selected-window
|
||||||
|
(neotree-show))))))
|
||||||
|
|
||||||
;; Prevents messing up the neotree buffer on window changes
|
;; Prevents messing up the neotree buffer on window changes
|
||||||
(advice-add '+evil-window-move :around 'doom*popups-save-neotree)
|
(advice-add '+evil-window-move :around 'doom*popups-save-neotree)
|
||||||
;; Don't let neotree interfere with moving, splitting or rebalancing windows
|
;; Don't let neotree interfere with moving, splitting or rebalancing windows
|
||||||
(advice-add 'evil-window-move-very-bottom :around 'doom*popups-save-neotree)
|
(advice-add 'evil-window-move-very-bottom :around 'doom*popups-save-neotree)
|
||||||
(advice-add 'evil-window-move-very-top :around 'doom*popups-save-neotree)
|
(advice-add 'evil-window-move-very-top :around 'doom*popups-save-neotree)
|
||||||
(advice-add 'evil-window-move-far-left :around 'doom*popups-save-neotree)
|
(advice-add 'evil-window-move-far-left :around 'doom*popups-save-neotree)
|
||||||
(advice-add 'evil-window-move-far-right :around 'doom*popups-save-neotree))
|
(advice-add 'evil-window-move-far-right :around 'doom*popups-save-neotree))
|
||||||
|
|
||||||
|
|
||||||
(add-hook! org-load
|
(add-hook! 'org-load-hook
|
||||||
(set! :popup
|
(set! :popup
|
||||||
'("*Calendar*" :size 0.4 :noselect t)
|
'("*Calendar*" :size 0.4 :noselect t)
|
||||||
'(" *Org todo*" :size 5 :noselect t)
|
'(" *Org todo*" :size 5 :noselect t)
|
||||||
'("*Org Note*" :size 10)
|
'("*Org Note*" :size 10)
|
||||||
'("*Org Select*" :size 20 :noselect t)
|
'("*Org Select*" :size 20 :noselect t)
|
||||||
'("*Org Links*" :size 5 :noselect t)
|
'("*Org Links*" :size 5 :noselect t)
|
||||||
'(" *Agenda Commands*" :noselect t)
|
'(" *Agenda Commands*" :noselect t)
|
||||||
'("^\\*Org Agenda" :regexp t :size 30)
|
'("^\\*Org Agenda" :regexp t :size 30)
|
||||||
'("*Org Clock*" :noselect t)
|
'("*Org Clock*" :noselect t)
|
||||||
'("*Edit Formulas*" :size 10)
|
'("*Edit Formulas*" :size 10)
|
||||||
'("\\*Org Src" :regexp t :size 15 :autokill t)
|
'("\\*Org Src" :regexp t :size 15 :autokill t)
|
||||||
'("^\\*Org-Babel" :regexp t :size 0.4)
|
'("^\\*Org-Babel" :regexp t :size 0.4)
|
||||||
'("^CAPTURE.*\\.org$" :regexp t :size 20))
|
'("^CAPTURE.*\\.org$" :regexp t :size 20))
|
||||||
|
|
||||||
;; Org tries to do its own popup management, causing buffer/window config
|
;; Org tries to do its own popup management, causing buffer/window config
|
||||||
;; armageddon when paired with shackle. To fix this, first we suppress
|
;; armageddon when paired with shackle. To fix this, first we suppress
|
||||||
;; delete-other-windows in org functions:
|
;; delete-other-windows in org functions:
|
||||||
(defun doom*suppress-delete-other-windows (orig-fn &rest args)
|
(defun doom*suppress-delete-other-windows (orig-fn &rest args)
|
||||||
(cl-flet ((silence (&rest args) (ignore)))
|
(cl-flet ((silence (&rest args) (ignore)))
|
||||||
(advice-add 'delete-other-windows :around #'silence)
|
(advice-add 'delete-other-windows :around #'silence)
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
(apply orig-fn args)
|
(apply orig-fn args)
|
||||||
(advice-remove 'delete-other-windows #'silence))))
|
(advice-remove 'delete-other-windows #'silence))))
|
||||||
(advice-add 'org-capture-place-template :around #'doom*suppress-delete-other-windows)
|
(advice-add 'org-capture-place-template :around #'doom*suppress-delete-other-windows)
|
||||||
(advice-add 'org-agenda :around #'doom*suppress-delete-other-windows)
|
(advice-add 'org-agenda :around #'doom*suppress-delete-other-windows)
|
||||||
(advice-add 'org-add-log-note :around #'doom*suppress-delete-other-windows)
|
(advice-add 'org-add-log-note :around #'doom*suppress-delete-other-windows)
|
||||||
|
|
||||||
;; Tell org-src-edit to open another window, which shackle can intercept.
|
;; Tell org-src-edit to open another window, which shackle can intercept.
|
||||||
(setq org-src-window-setup 'other-window)
|
(setq org-src-window-setup 'other-window)
|
||||||
|
|
||||||
;; Then, we tell org functions to use pop-to-buffer instead of
|
;; Then, we tell org functions to use pop-to-buffer instead of
|
||||||
;; switch-to-buffer-*. Buffers get handed off to shackle properly this way.
|
;; switch-to-buffer-*. Buffers get handed off to shackle properly this way.
|
||||||
(defun doom*org-switch-to-buffer-other-window (&rest args)
|
(defun doom*org-switch-to-buffer-other-window (&rest args)
|
||||||
(pop-to-buffer (car args)))
|
(pop-to-buffer (car args)))
|
||||||
(advice-add 'org-switch-to-buffer-other-window :override 'doom*org-switch-to-buffer-other-window)
|
(advice-add 'org-switch-to-buffer-other-window :override 'doom*org-switch-to-buffer-other-window)
|
||||||
|
|
||||||
;; Hide modeline in org-agenda
|
;; Hide modeline in org-agenda
|
||||||
(add-hook 'org-agenda-finalize-hook 'doom-hide-modeline-mode)
|
(add-hook 'org-agenda-finalize-hook 'doom-hide-modeline-mode)
|
||||||
|
|
||||||
(after! org-agenda
|
(after! org-agenda
|
||||||
(after! evil
|
(after! evil
|
||||||
(map! :map* org-agenda-mode-map
|
(map! :map* org-agenda-mode-map
|
||||||
:m [escape] 'org-agenda-Quit
|
:m [escape] 'org-agenda-Quit
|
||||||
:m "ESC" 'org-agenda-Quit))
|
:m "ESC" 'org-agenda-Quit))
|
||||||
(let ((map org-agenda-mode-map))
|
(let ((map org-agenda-mode-map))
|
||||||
(define-key map "q" 'org-agenda-Quit)
|
(define-key map "q" 'org-agenda-Quit)
|
||||||
(define-key map "Q" 'org-agenda-Quit))))
|
(define-key map "Q" 'org-agenda-Quit))))
|
||||||
|
|
||||||
|
|
||||||
(after! repl-toggle
|
(after! repl-toggle
|
||||||
(add-hook! doom-popup-close
|
(add-hook! doom-popup-close
|
||||||
(setq rtog/--last-buffer nil)))
|
(setq rtog/--last-buffer nil))))
|
||||||
|
|
||||||
(provide 'core-popups)
|
(provide 'core-popups)
|
||||||
;;; core-popups.el ends here
|
;;; core-popups.el ends here
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue