我一直在查看the available hooks,但是当你切换窗户时,它们似乎都没有被触发。
我正在尝试做的是激活所选窗口的次要模式:
(defvar active-window (frame-selected-window))
(defun active-window-switch (&rest _)
(when active-window
(with-selected-window active-window
(active-window-mode nil)))
(setq active-window (frame-selected-window))
(active-window-mode t))
(define-minor-mode active-window-mode
"Minor mode to distinguish the selected window."
:global nil :group 'active-window :init-value nil :lighter " Active")
(add-hook 'window-configuration-change-hook #'active-window-switch)
(provide 'active-window)
我可以使用什么钩子或函数来代替window-configuration-change-hook
(只有在我创建或退出窗口时才会触发)?
答案 0 :(得分:2)
select-window
是在许多情况下内部使用的操作,在单个命令中可能数千次。您并不是一直关心所选窗口,而只是在不运行命令时。所以更好的地方就是post-command-hook
。
答案 1 :(得分:1)
您可以尝试建议选择窗口:
(defadvice select-window (after select-window-and-do-stuff activate)
(do-stuff))
或者,如果您想在首先离开的窗口中取消设置:
(defadvice select-window (around select-window-and-do-stuff activate)
(undo-stuff)
ad-do-it
(do-stuff))