2014-05-03 14 views
1

我有兴趣创建一个基于用户定义标准运行的交互式准后命令钩,如:Emacs - 创建一个交互式的只准后命令钩

  • 向上(交互式);

  • Down(interactive);

  • Left(interactive);

  • Right(interactive);

  • 将文本插入缓冲区的任何(交互式)键 - 例如aA-zZ; 0-9;空间; (上/下)(交互式)。

  • 鼠标滚轮(上/下)(交互式)。

相信后命令钩包括更多,我想要当钩被激活以限制/控制。

任何有关如何创建这样一个钩子的指导,将不胜感激。


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)))) 

回答

3

您可能想要测试this-command变量。

例如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. 
+0

真棒!非常感谢你 - 非常感谢! :) – lawlist

1

历数你知道应该触发这个钩子(使用this-command)的命令当然是一种选择,但“它不适合”。如果你试图描述这些命令与其他命令有什么共同之处,而其他命令没有这些命令,那么你可以做得更好。

+0

这两个组基本上是:由于用户按下交互键,'point'已经手动移动;或者,手动向上或向下滚动缓冲区。 – lawlist

+0

所以,也许你可以记住'lawlist-last-point'中的前一点,然后将它与当前点进行比较,以查看最后一个命令是否移动了点。 – Stefan

+0

谢谢你的建议 - 随着时间的推移,我会在接下来的几天继续处理这个问题,然后我会报告回来。 – lawlist