【问题标题】:How do I bind <Print Screen> to a macro in emacs?如何将 <Print Screen> 绑定到 emacs 中的宏?
【发布时间】:2010-06-23 17:01:17
【问题描述】:

我希望能够在 emacs 中点击 &lt;Print Screen&gt; 并在 git 存储库中触发提交。我的口齿不清,知道这是坏的,但不知道在哪里:

( defun tip-local-write nil "Write to store" ( interactive )
     ( save-buffer )
     ( change-directory "~/tip" )
     ( shell-command "git commit -m checkpoint ." )
     ( shell-command "git submodule foreach git commit -m checkpoint . \\\|\\\| true" ) ) )
( global-set-key [?\M-1] 'tip-local-write )

目前它绑定到 ^1,因为我不知道如何表示 &lt;Print Screen&gt; 按钮。

【问题讨论】:

    标签: emacs elisp key-bindings


    【解决方案1】:

    一个适用于绑定你不知道 Emacs 名称的击键的通用技巧:

    • 点击M-x global-set-key RET &lt;your keystroke&gt; RET &lt;name of function&gt;

    然后,点击 C-x ESC ESC(即repeat-complex-command)。在 minibufer 中,您应该会看到一个 global-set-key 函数调用,您可以将其复制到您的 .emacs 文件中。

    【讨论】:

    • 我用C-h k,可能更简单一些
    • 你说得对,C-h k 和 C-h c 更简单,但我记得喜欢这个技巧是有原因的……我现在不记得了。可能它仅与选项卡自动完成功能有关,可帮助您减少键入内容。 :-)
    【解决方案2】:

    您可以通过

    获得打印屏幕键
    (kbd "<print>")
    

    至于实际提交,使用 emacs 提供的版本控制功能可能要容易得多:

    (vc-git-checkin "." nil "checkpoint")
    

    【讨论】:

      【解决方案3】:

      你需要先运行这个:

      (w32-register-hot-key [snapshot])
      

      之后,您可以这样做:

      (global-set-key [snapshot] 'tip-local-write ) 
      

      【讨论】:

      • 为了成为 Stack Overflow 的更好贡献者(我是新来的),这个贡献没有获得 mod 点数有什么问题?它可以工作(我使用本地安装的 Emacs 对其进行了测试),并回答了所提出的问题。 (我不太关心积分本身,而更关心为网站做出有用的贡献。我将积分作为代表。)
      • 关于成为更好的贡献者,你只要坚持下去,b/c 持久性是关键。而且,关于你的回答,直到我也完成了(w32-register-hot-key [print]),它才对我有用。不知道为什么,但你去了。
      猜你喜欢
      • 2014-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 2020-03-28
      • 1970-01-01
      • 2012-05-26
      • 1970-01-01
      相关资源
      最近更新 更多