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
|
||||
;;
|
||||
|
||||
(after! evil
|
||||
(let ((map doom-popup-mode-map))
|
||||
(define-key map [remap evil-window-delete] 'doom/popup-close)
|
||||
(define-key map [remap evil-window-move-very-bottom] 'ignore)
|
||||
(define-key map [remap evil-window-move-very-top] 'ignore)
|
||||
(define-key map [remap evil-window-move-far-left] 'ignore)
|
||||
(define-key map [remap evil-window-move-far-right] 'ignore)
|
||||
(define-key map [remap evil-window-split] 'ignore)
|
||||
(define-key map [remap evil-window-vsplit] 'ignore)
|
||||
(define-key map [remap evil-force-normal-state] 'doom/popup-close-maybe))
|
||||
(add-hook! 'window-setup-hook
|
||||
(after! evil
|
||||
(let ((map doom-popup-mode-map))
|
||||
(define-key map [remap evil-window-delete] 'doom/popup-close)
|
||||
(define-key map [remap evil-window-move-very-bottom] 'ignore)
|
||||
(define-key map [remap evil-window-move-very-top] 'ignore)
|
||||
(define-key map [remap evil-window-move-far-left] 'ignore)
|
||||
(define-key map [remap evil-window-move-far-right] 'ignore)
|
||||
(define-key map [remap evil-window-split] 'ignore)
|
||||
(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
|
||||
(advice-add 'evil-command-window :override 'doom*popup-evil-command-window)
|
||||
(advice-add 'evil-command-window-execute :override 'doom*popup-evil-command-window-execute)
|
||||
;; Make evil-mode cooperate with popups
|
||||
(advice-add 'evil-command-window :override 'doom*popup-evil-command-window)
|
||||
(advice-add 'evil-command-window-execute :override 'doom*popup-evil-command-window-execute)
|
||||
|
||||
(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
|
||||
(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
|
||||
monkey patch it to use pop-to-buffer, and to remember the previous window."
|
||||
(when (eq major-mode 'evil-command-window-mode)
|
||||
(user-error "Cannot recursively open command line window"))
|
||||
(dolist (win (window-list))
|
||||
(when (equal (buffer-name (window-buffer win))
|
||||
"*Command Line*")
|
||||
(kill-buffer (window-buffer win))
|
||||
(delete-window win)))
|
||||
(setq evil-command-window-current-buffer (current-buffer))
|
||||
(ignore-errors (kill-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-cmd-key cmd-key)
|
||||
(evil-command-window-mode)
|
||||
(evil-command-window-insert-commands hist)))
|
||||
(when (eq major-mode 'evil-command-window-mode)
|
||||
(user-error "Cannot recursively open command line window"))
|
||||
(dolist (win (window-list))
|
||||
(when (equal (buffer-name (window-buffer win))
|
||||
"*Command Line*")
|
||||
(kill-buffer (window-buffer win))
|
||||
(delete-window win)))
|
||||
(setq evil-command-window-current-buffer (current-buffer))
|
||||
(ignore-errors (kill-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-cmd-key cmd-key)
|
||||
(evil-command-window-mode)
|
||||
(evil-command-window-insert-commands hist)))
|
||||
|
||||
(defun doom*popup-evil-command-window-execute ()
|
||||
"Execute the command under the cursor in the appropriate buffer, rather than
|
||||
(defun doom*popup-evil-command-window-execute ()
|
||||
"Execute the command under the cursor in the appropriate buffer, rather than
|
||||
the command buffer."
|
||||
(interactive)
|
||||
(let ((result (buffer-substring (line-beginning-position)
|
||||
(line-end-position)))
|
||||
(execute-fn evil-command-window-execute-fn)
|
||||
(popup (selected-window)))
|
||||
(select-window doom-popup-other-window)
|
||||
(unless (equal evil-command-window-current-buffer (current-buffer))
|
||||
(user-error "Originating buffer is no longer active"))
|
||||
;; (kill-buffer "*Command Line*")
|
||||
(doom/popup-close popup)
|
||||
(funcall execute-fn result)
|
||||
(setq evil-command-window-current-buffer nil)))
|
||||
(interactive)
|
||||
(let ((result (buffer-substring (line-beginning-position)
|
||||
(line-end-position)))
|
||||
(execute-fn evil-command-window-execute-fn)
|
||||
(popup (selected-window)))
|
||||
(select-window doom-popup-other-window)
|
||||
(unless (equal evil-command-window-current-buffer (current-buffer))
|
||||
(user-error "Originating buffer is no longer active"))
|
||||
;; (kill-buffer "*Command Line*")
|
||||
(doom/popup-close popup)
|
||||
(funcall execute-fn result)
|
||||
(setq evil-command-window-current-buffer nil)))
|
||||
|
||||
;; Don't mess with popups
|
||||
(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-top :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)
|
||||
;; Don't mess with popups
|
||||
(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-top :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)
|
||||
|
||||
;; Don't block moving to/from popup windows
|
||||
(defun doom*ignore-window-parameters-in-popups (dir &optional arg window)
|
||||
(window-in-direction (cond ((eq dir 'up) 'above)
|
||||
((eq dir 'down) 'below)
|
||||
(t dir))
|
||||
window t arg windmove-wrap-around t))
|
||||
(advice-add 'windmove-find-other-window :override 'doom*ignore-window-parameters-in-popups))
|
||||
;; Don't block moving to/from popup windows
|
||||
(defun doom*ignore-window-parameters-in-popups (dir &optional arg window)
|
||||
(window-in-direction (cond ((eq dir 'up) 'above)
|
||||
((eq dir 'down) 'below)
|
||||
(t dir))
|
||||
window t arg windmove-wrap-around t))
|
||||
(advice-add 'windmove-find-other-window :override 'doom*ignore-window-parameters-in-popups))
|
||||
|
||||
|
||||
(after! help-mode
|
||||
;; Help buffers use `other-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.
|
||||
(defsubst doom--switch-from-popup (location)
|
||||
(doom/popup-close)
|
||||
(switch-to-buffer (car location) nil t)
|
||||
(if (not (cdr location))
|
||||
(message "Unable to find location in file")
|
||||
(goto-char (cdr location))
|
||||
(recenter)))
|
||||
(after! help-mode
|
||||
;; Help buffers use `other-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.
|
||||
(defsubst doom--switch-from-popup (location)
|
||||
(doom/popup-close)
|
||||
(switch-to-buffer (car location) nil t)
|
||||
(if (not (cdr location))
|
||||
(message "Unable to find location in file")
|
||||
(goto-char (cdr location))
|
||||
(recenter)))
|
||||
|
||||
(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-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-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)))))
|
||||
(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)))))
|
||||
|
||||
|
||||
;; (after! magit
|
||||
;; ;; Don't open files (from magit) within the magit popup
|
||||
;; (advice-add 'magit-display-file-buffer-traditional :around 'doom*popups-save))
|
||||
;; (after! magit
|
||||
;; ;; Don't open files (from magit) within the magit popup
|
||||
;; (advice-add 'magit-display-file-buffer-traditional :around 'doom*popups-save))
|
||||
|
||||
|
||||
(after! neotree
|
||||
(defun doom*popups-save-neotree (orig-fn &rest args)
|
||||
"Prevents messing up the neotree buffer on window changes."
|
||||
(let ((neo-p (and (featurep 'neotree)
|
||||
(neo-global--window-exists-p))))
|
||||
(when neo-p
|
||||
(neotree-hide))
|
||||
(unwind-protect (apply orig-fn args)
|
||||
(after! neotree
|
||||
(defun doom*popups-save-neotree (orig-fn &rest args)
|
||||
"Prevents messing up the neotree buffer on window changes."
|
||||
(let ((neo-p (and (featurep 'neotree)
|
||||
(neo-global--window-exists-p))))
|
||||
(when neo-p
|
||||
(save-selected-window
|
||||
(neotree-show))))))
|
||||
(neotree-hide))
|
||||
(unwind-protect (apply orig-fn args)
|
||||
(when neo-p
|
||||
(save-selected-window
|
||||
(neotree-show))))))
|
||||
|
||||
;; Prevents messing up the neotree buffer on window changes
|
||||
(advice-add '+evil-window-move :around 'doom*popups-save-neotree)
|
||||
;; 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-top :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))
|
||||
;; Prevents messing up the neotree buffer on window changes
|
||||
(advice-add '+evil-window-move :around 'doom*popups-save-neotree)
|
||||
;; 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-top :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))
|
||||
|
||||
|
||||
(add-hook! org-load
|
||||
(set! :popup
|
||||
'("*Calendar*" :size 0.4 :noselect t)
|
||||
'(" *Org todo*" :size 5 :noselect t)
|
||||
'("*Org Note*" :size 10)
|
||||
'("*Org Select*" :size 20 :noselect t)
|
||||
'("*Org Links*" :size 5 :noselect t)
|
||||
'(" *Agenda Commands*" :noselect t)
|
||||
'("^\\*Org Agenda" :regexp t :size 30)
|
||||
'("*Org Clock*" :noselect t)
|
||||
'("*Edit Formulas*" :size 10)
|
||||
'("\\*Org Src" :regexp t :size 15 :autokill t)
|
||||
'("^\\*Org-Babel" :regexp t :size 0.4)
|
||||
'("^CAPTURE.*\\.org$" :regexp t :size 20))
|
||||
(add-hook! 'org-load-hook
|
||||
(set! :popup
|
||||
'("*Calendar*" :size 0.4 :noselect t)
|
||||
'(" *Org todo*" :size 5 :noselect t)
|
||||
'("*Org Note*" :size 10)
|
||||
'("*Org Select*" :size 20 :noselect t)
|
||||
'("*Org Links*" :size 5 :noselect t)
|
||||
'(" *Agenda Commands*" :noselect t)
|
||||
'("^\\*Org Agenda" :regexp t :size 30)
|
||||
'("*Org Clock*" :noselect t)
|
||||
'("*Edit Formulas*" :size 10)
|
||||
'("\\*Org Src" :regexp t :size 15 :autokill t)
|
||||
'("^\\*Org-Babel" :regexp t :size 0.4)
|
||||
'("^CAPTURE.*\\.org$" :regexp t :size 20))
|
||||
|
||||
;; Org tries to do its own popup management, causing buffer/window config
|
||||
;; armageddon when paired with shackle. To fix this, first we suppress
|
||||
;; delete-other-windows in org functions:
|
||||
(defun doom*suppress-delete-other-windows (orig-fn &rest args)
|
||||
(cl-flet ((silence (&rest args) (ignore)))
|
||||
(advice-add 'delete-other-windows :around #'silence)
|
||||
(unwind-protect
|
||||
(apply orig-fn args)
|
||||
(advice-remove 'delete-other-windows #'silence))))
|
||||
(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-add-log-note :around #'doom*suppress-delete-other-windows)
|
||||
;; Org tries to do its own popup management, causing buffer/window config
|
||||
;; armageddon when paired with shackle. To fix this, first we suppress
|
||||
;; delete-other-windows in org functions:
|
||||
(defun doom*suppress-delete-other-windows (orig-fn &rest args)
|
||||
(cl-flet ((silence (&rest args) (ignore)))
|
||||
(advice-add 'delete-other-windows :around #'silence)
|
||||
(unwind-protect
|
||||
(apply orig-fn args)
|
||||
(advice-remove 'delete-other-windows #'silence))))
|
||||
(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-add-log-note :around #'doom*suppress-delete-other-windows)
|
||||
|
||||
;; Tell org-src-edit to open another window, which shackle can intercept.
|
||||
(setq org-src-window-setup 'other-window)
|
||||
;; Tell org-src-edit to open another window, which shackle can intercept.
|
||||
(setq org-src-window-setup 'other-window)
|
||||
|
||||
;; Then, we tell org functions to use pop-to-buffer instead of
|
||||
;; switch-to-buffer-*. Buffers get handed off to shackle properly this way.
|
||||
(defun doom*org-switch-to-buffer-other-window (&rest args)
|
||||
(pop-to-buffer (car args)))
|
||||
(advice-add 'org-switch-to-buffer-other-window :override 'doom*org-switch-to-buffer-other-window)
|
||||
;; Then, we tell org functions to use pop-to-buffer instead of
|
||||
;; switch-to-buffer-*. Buffers get handed off to shackle properly this way.
|
||||
(defun doom*org-switch-to-buffer-other-window (&rest args)
|
||||
(pop-to-buffer (car args)))
|
||||
(advice-add 'org-switch-to-buffer-other-window :override 'doom*org-switch-to-buffer-other-window)
|
||||
|
||||
;; Hide modeline in org-agenda
|
||||
(add-hook 'org-agenda-finalize-hook 'doom-hide-modeline-mode)
|
||||
;; Hide modeline in org-agenda
|
||||
(add-hook 'org-agenda-finalize-hook 'doom-hide-modeline-mode)
|
||||
|
||||
(after! org-agenda
|
||||
(after! evil
|
||||
(map! :map* org-agenda-mode-map
|
||||
:m [escape] 'org-agenda-Quit
|
||||
:m "ESC" 'org-agenda-Quit))
|
||||
(let ((map org-agenda-mode-map))
|
||||
(define-key map "q" 'org-agenda-Quit)
|
||||
(define-key map "Q" 'org-agenda-Quit))))
|
||||
(after! org-agenda
|
||||
(after! evil
|
||||
(map! :map* org-agenda-mode-map
|
||||
:m [escape] 'org-agenda-Quit
|
||||
:m "ESC" 'org-agenda-Quit))
|
||||
(let ((map org-agenda-mode-map))
|
||||
(define-key map "q" 'org-agenda-Quit)
|
||||
(define-key map "Q" 'org-agenda-Quit))))
|
||||
|
||||
|
||||
(after! repl-toggle
|
||||
(add-hook! doom-popup-close
|
||||
(setq rtog/--last-buffer nil)))
|
||||
(after! repl-toggle
|
||||
(add-hook! doom-popup-close
|
||||
(setq rtog/--last-buffer nil))))
|
||||
|
||||
(provide 'core-popups)
|
||||
;;; core-popups.el ends here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue