选择窗口时请执行操作 [英] Do stuff when selecting a window
问题描述
我一直在查看可用的钩子,但是当您切换窗口时,似乎没有任何人触发。
I've been looking through the available hooks, but none of them seems to be firing when you switch windows.
我正在尝试的是为所选窗口激活一个次要模式:
What I'm trying to do, is activating a minor mode for the selected window:
(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
(仅当我创建或退出窗口时才会触发)?
What hook or function to advice can I use instead of window-configuration-change-hook
(which only fires when I create or quit windows)?
推荐答案
select-window
是一种内部使用的操作,在单一命令中潜在数千次。你一直都不关心所选的窗口,而只是在不运行命令的时候。所以钩住自己的好地方在 post-command-hook
。
select-window
is an operation used internally in many cases, potentially thousands of times in a single command. You don't really care about the selected window all the time, but only when not running a command. So the better place to hook yourself is in post-command-hook
.
这篇关于选择窗口时请执行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!