[英]Emacs map <compile “python current-buffer-name”> to a hotkey
If I do Mx <RET> compile <RET>
, I get prompted for what to compile. 如果我执行
Mx <RET> compile <RET>
, Mx <RET> compile <RET>
提示我要编译什么。 What I want to compile is the current buffer in python, so I type python test.py <RET>
. 我要编译的是python中的当前缓冲区,因此我键入
python test.py <RET>
。 Now sometimes I get asked if I want to create a separate process, and I always want to say y
(that is yes). 现在有时我会被问到是否要创建一个单独的过程,而我总是想说
y
(是)。
(define-key python-mode-map "\\Cb" 'compile)
gives the following error: (define-key python-mode-map "\\Cb" 'compile)
给出以下错误:
(define-key global-map "\\Cb" 'compile)
works, but that's far from what I need. (define-key global-map "\\Cb" 'compile)
可以工作,但是那远不是我需要的。
So, how can I map compile python current-buffer-name
to "\\Cb"
? 那么,如何将
compile python current-buffer-name
映射到"\\Cb"
?
Emacs does have the concept of modes. Emacs确实具有模式的概念。 I guess you do not want to have the compilation of python to a global key.
我猜您不想将python编译为全局键。
Have you checked: http://www.emacswiki.org/emacs?action=browse;oldid=PythonMode;id=PythonProgrammingInEmacs 您是否检查过: http ://www.emacswiki.org/emacs?action = browse; oldid= PythonMode; id=PythonProgrammingInEmacs
What you do is calling an external program. 您要做的是调用外部程序。 I'm sure there is a better suited way to do that in the python-mode.
我敢肯定,在python模式下有一种更合适的方法可以做到这一点。
If you want to pack more then one command to a key, you have to write some kind of wrapper this function contains all the things you are going to call. 如果要给一个键打包多个命令,则必须编写某种包装程序,该包装程序包含要调用的所有内容。
The variable python-mode-map
will not be defined until you load python-mode
. 在加载
python-mode
之前,不会定义变量python-mode-map
。 The brute-force approach would be to (require 'python-mode)
from your .emacs
but you can avoid that somewhat more elegantly by only doing the define when python-mode
is being invoked. 蛮力方法是从
.emacs
(require 'python-mode)
,但是您可以通过仅在调用python-mode
时进行定义来更好地避免这种情况。
(add-hook 'python-mode-hook
(lambda ()
(define-key python-mode-map "\C-b" #'compile)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.