我有兴趣创建一个基于用户定义标准运行的仅限交互式的准后命令挂钩,例如:
Up(interactive);
向下(互动);
左(互动);
正确(互动);
将文本插入缓冲区的任何(交互式)密钥 - 例如aA-zZ; 0-9;空间; !@#$%^& *() - + =。;,返回/输入,删除/退格等。
鼠标滚轮(上/下)(交互式)。
我相信post-command-hook包含更多,我想限制/控制何时激活钩子。
任何关于如何创建这种钩子的指导都将受到赞赏。
2013年5月3日:根据以下@phils的答案草拟示例。
(add-hook 'post-command-hook 'quasi-post-command-hook)
(defvar quasi-this-command-functions '(next-line previous-line left-char right-char
self-insert-command newline delete-backward-char delete-forward-char
indent-for-tab-command mwheel-scroll lawlist-mwheel-scroll end-of-visual-line
beginning-of-visual-line end-of-buffer beginning-of-buffer lawlist-forward-entity
lawlist-backward-entity left-word right-word forward-word backward-word)
"Variable list of functions that trigger the `quasi-post-command-hook`.")
(defvar quasi-major-mode-inclusions '(text-mode emacs-lisp-mode)
"Variable list of major modes where the `quasi-post-command-hook` operates.")
(defun quasi-post-command-hook ()
(unless (minibufferp)
(when
(and
(memq major-mode quasi-major-mode-inclusions)
(memq this-command quasi-this-command-functions))
(message "this-command: %s" this-command))))
答案 0 :(得分:3)
您可能想要测试this-command
变量。
e.g。 C-u M-x apropos-variable RET this RET
:
real-this-command
This is like `this-command', except that commands should never
modify it.
this-command
The command now being executed.
this-command-keys-shift-translated
Non-nil if the key sequence activating this command was
shift-translated.
this-original-command
The command bound to the current key sequence before remapping.
答案 1 :(得分:1)
枚举你知道的命令应该触发这个钩子(使用this-command
)当然是一个选项,但“它不能扩展”。如果你试图描述这些命令彼此之间的共同点以及其他命令没有的那些,你可能会做得更好。