本文介绍了如何执行键盘宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多情况下,emacs不会像应该执行的那样执行kbd宏。例如

 (execute-kbd-macro(read-kbd-macroCx Cf))

而不是结束执行这个宏与开放的minibuffer 查找文件:... emacs只打开第一个可用的文件或dired缓冲区(视情况而定)。如何执行这种类型的kbd宏,没有这种误解?



更新2.这只是一个类似于原始行为的键盘宏的例子, kbd> Cx Cf )。以下是 grep 的另一个例子。



更新。所提到的@lawlist我可以使用

 (key-binding(kbdCx Cf))

用于转换键序列到命令名。但它只有在有命令时才起作用。在更复杂的情况下,例如

 (execute-kbd-macro(read-kbd-macroCu Mx grep RET) )

这个暴力方法不起作用(我想继续编辑模式为 grep ,但emacs强制完成交互)。

解决方案

函数 kbd-macro-query 可以帮助这种情况

 (execute-kbd-宏(read-kbd-macroCx Cf Cu Cx q))

但是有一个问题:命令循环级别增加(您可以在modeline中看到
外观的方括号)。如果 find-file
示例没关系,但

 (execute-kbd-macro(read-kbd-macroMx helm-do-grep RET Cu Cx q))

给出错误的行为。我设计有趣的解决方法

 (defun eab / kbd-macro-query()
(interactive)
(let((execution-kbd-macro definitions-kbd-macro))
(run-with-timer 0.1 nil'abort-recursive-edit)
(递归编辑)))

(全局设置密钥(kbdCx Q)'eab / kbd-macro-query)

(let((minibuffer-message-timeout 0))
(execute-kbd-macro(read-kbd-macroMx helm-do-grep RET Cx Q)))

,它的工作正常。

 (let((minibuffer-message-timeout 0))
(execute-kbd-macro(read-kbd-macroread-kbd-macroCu Mx grep RET Cx Q))



ido-find-file ( in ido-mode

 code>(let((minibuffer-message-timeout 0))
(execute-kbd-macro(read-kbd-macroCx Cf Cx Q))

有一些事情g错误 ido-text 和[无匹配]。



总和。这种方法的主要思想是截取使用递归编辑的kbd宏
执行。 ($ code> kbd-macro-query
with
non-nil arg使用它)。 ido-mode 有一些问题,但是在
中,一般来说,即使使用复杂的kbd序列,如

 (let((minibuffer-message-timeout 0))
(execute-kbd-macro(read-kbd-macroCu Mx helm-do-grep RET Cx Q )))


In many cases emacs doesn't execute kbd macros exactly as it should be. For example

(execute-kbd-macro (read-kbd-macro "C-x C-f"))

Rather than to end execution of this macros with open minibuffer Find file: ... emacs just opens the first available file or dired buffer (depending on the situation). How to execute such kinds of kbd macroses without such misunderstandings?

Upd 2. It is just example of such kind of keyboard macroses that behaves differently from the original behavior (i.e. pressed). Below is another example with grep.

Upd. As @lawlist mentioned I can use

(key-binding (kbd "C-x C-f"))

for transformation key sequence to command name. But it only works when there is the command. In a more complex case, e.g.

(execute-kbd-macro (read-kbd-macro "C-u M-x grep RET"))

this "brute-force" method doesn't work (I want to continue editing pattern for grep but emacs forcedly finishes the interaction).

解决方案

The function kbd-macro-query can help in this situation

(execute-kbd-macro (read-kbd-macro "C-x C-f C-u C-x q"))

But there is a problem: command loop level increases (you can seeappearance of the square brackets in modeline). In case of find-fileexample it doesn't matter, but

(execute-kbd-macro (read-kbd-macro "M-x helm-do-grep RET C-u C-x q"))

gives wrong behavior. I devise interesting workaround

(defun eab/kbd-macro-query ()
  (interactive)
  (let ((executing-kbd-macro defining-kbd-macro))
    (run-with-timer 0.1 nil 'abort-recursive-edit)
    (recursive-edit)))

(global-set-key (kbd "C-x Q") 'eab/kbd-macro-query)

(let ((minibuffer-message-timeout 0))
  (execute-kbd-macro (read-kbd-macro "M-x helm-do-grep RET C-x Q")))

and it works fine.

(let ((minibuffer-message-timeout 0))
  (execute-kbd-macro (read-kbd-macro "C-u M-x grep RET C-x Q")))

also works as it should be.

But now there is another problem withido-find-file ( in ido-mode)

(let ((minibuffer-message-timeout 0))
  (execute-kbd-macro (read-kbd-macro "C-x C-f C-x Q")))

There is something wrong with ido-text and [No match].

Sum. The main idea of this method is the interception of kbd macroexecution with the use of recursive-edit. (kbd-macro-query withnon-nil arg uses it). There is some problem with ido-mode but ingeneral it works well even with complicated kbd sequences like

(let ((minibuffer-message-timeout 0))
  (execute-kbd-macro (read-kbd-macro "C-u M-x helm-do-grep RET C-x Q")))

这篇关于如何执行键盘宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:58