【问题标题】:Emacs map <compile "python current-buffer-name"> to a hotkeyEmacs 将 <compile "python current-buffer-name"> 映射到热键
【发布时间】:2015-12-17 19:51:48
【问题描述】:

如果我执行M-x &lt;RET&gt; compile &lt;RET&gt;,则会提示我要编译什么。我要编译的是python中的当前缓冲区,所以我输入python test.py &lt;RET&gt;。现在有时有人问我是否要创建一个单独的进程,我总是想说y(是的)。

(define-key python-mode-map "\C-b" 'compile) 给出以下错误:

(define-key global-map "\C-b" 'compile) 有效,但这远不是我需要的。

那么,我如何将compile python current-buffer-name 映射到"\C-b"

【问题讨论】:

标签: emacs elisp


【解决方案1】:

Emacs 确实有模式的概念。我猜您不想将 python 编译为全局键。

您是否检查过: http://www.emacswiki.org/emacs?action=browse;oldid=PythonMode;id=PythonProgrammingInEmacs

您所做的是调用外部程序。我确信在 python 模式下有更合适的方法来做到这一点。

如果你想将多个命令打包到一个键中,你必须编写某种包装器,这个函数包含你要调用的所有东西。

【讨论】:

    【解决方案2】:

    在您加载 python-mode 之前,不会定义变量 python-mode-map。蛮力方法是从您的 .emacs(require 'python-mode),但您可以通过仅在调用 python-mode 时进行定义来更优雅地避免这种情况。

    (add-hook 'python-mode-hook
              (lambda ()
                (define-key python-mode-map "\C-b" #'compile)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-12
      • 2019-01-06
      相关资源
      最近更新 更多