diff --git a/config.el b/config.el index 14ad115..f96b3f6 100644 --- a/config.el +++ b/config.el @@ -1123,10 +1123,16 @@ Otherwise: runs interactive ement-connect, then opens rooms after sync." ;; Re-activate Evil normal state when switching to a pdf-view window. ;; Without this, j/k do not respond after SPC w w until the user clicks. -(add-hook 'window-selection-change-functions - (lambda (_frame) - (when (derived-mode-p 'pdf-view-mode) - (evil-normal-state)))) +;; Uses targeted advice on window-switch commands to avoid interfering +;; with org-agenda which triggers window-selection-change-functions internally. +(defun my/pdf-view-ensure-normal-state (&rest _) + "Activate evil-normal-state when landing on a pdf-view-mode buffer." + (when (derived-mode-p 'pdf-view-mode) + (evil-normal-state))) + +(advice-add 'evil-window-next :after #'my/pdf-view-ensure-normal-state) +(advice-add 'evil-window-prev :after #'my/pdf-view-ensure-normal-state) +(advice-add 'other-window :after #'my/pdf-view-ensure-normal-state) ;; Open PDFs from org export in Emacs (pdf-view-mode) instead of Preview (when (eq system-type 'darwin)