【发布时间】:2014-05-03 07:22:32
【问题描述】:
我有兴趣创建一个基于用户定义标准运行的仅交互式准命令后挂钩,例如:
向上(交互式);
向下(交互式);
左(交互式);
右(交互式);
将文本插入缓冲区的任何(交互式)键——例如,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))))
【问题讨论】: