更改Emacs“发送代码到解释器”C-c C-r命令在IPython模式 [英] Change the Emacs “send code to interpreter” C-c C-r command in IPython-mode
问题描述
这里的问题是相关的(但不完全相同),并且与将发送代码更改为解释器 (C-c |)命令在python模式。我在Mac上工作10.9.5,Emacs 24.4,Python 2.7.8和IPython 2.2.0。
我的想法是更改 Cc Cr
emacs命令以IPython模式发送一个区域/行代码因为我通常使用R,但从现在开始,我将使用R和Python(特别是IPython,我真正喜欢的),和 C-RET
- 已经在R中的发送代码命令似乎比我更舒服。
在这个问题开头引用的链接中,他们建议将以下行添加到 .emacs
文件中以更改 Cc |
命令进入 Cc Cr
:
(eval-after-loadpython
'(progn
(define-key python-mode-map(kbdCc Cr)'python-shell-send-region))
目前,我的python / IPython配置在我的 .emacs
文件如下所示:
;;启用Python
/ pre>
(add-to-list'load-path/sw/lib/python-mode-1.0)
(加载python-mode)
(setq自动模式-alist
(cons'(\\.py $。python-mode)auto-mode-alist))
(setq interpreter-mode-alist
(cons' python)python-modepython-modePython编辑模式)
;; IPython的。这个python模式采用Key-map和菜单
(when(executable-findipython)
(setq
python-shell-interpreteripython
python- shell-interpreter-args
python-shell-prompt-regexpin \\ [[0-9] + \\]:
python-shell-prompt-output- regexpOut \\ [[0-9] + \\]:
python-shell-completion-setup-code
来自IPython.core.completerlib import module_completion
python-shell-completion-module-string-code
';'。join(module_completion('''%s'''))\\\
python-shell-completion- string-code
';'。join(get_ipython()。Completer.all_completions('''%s'''))\\\
))
哪些是并行运行的两个python模式,第二个(IPython,我一直使用的)采用键映射和菜单(由方式,任何建议更好的配置是欢迎的。IPython部分是基于:如何在emacs中打开IPython解释器?)。
我试图添加
(eval-after-loadpython'(progn ...
命令在我的python配置结束之前描述(当然,将Cc Cr
更改为C-RET
或C-ret
甚至C-< return>
)。
我还在
中尝试了(可执行 - 查找ipython)...
不同形式的块(例如简单的(define-key python-mode-map(kbdCc Cr)'python-shell-send-region)
)但是似乎没有什么可行的。
因此,我的问题是:给定我的Python / IPython配置,我必须包含在我的
.emacs
文件中以更改Cc Cr
命令进入(C-RET)
非常感谢您提前!
解决方案使用(kbdRET)
使用python.el
$ b(eval-after-loadpython
'(define-key python-mode-map [(控制c)(kbdRET)]'python-shell-send-region))
WRT python-mode.el:
(eval-after-loadpython-mode
' -key python-mode-map [(control c)(kbdRET)]'py-execute-region))
BTW除非需要IPython独占功能,建议通过普通的Python执行Emacs的代码。 IPython实现了一堆很酷的东西,这可能与Emacs正交,这也实现了一堆很酷的东西。
The question here is related (but NOT identical) and complementary to Change the "send code to interpreter" (C-c |) command in python-mode .
I work on a Mac 10.9.5, Emacs 24.4, Python 2.7.8 and IPython 2.2.0.
My idea is to change the
C-c C-r
emacs command to send a region/line of code in IPython mode toC-RET
, as when using R. This is because I usually work with R, but from now on, I am going to be using R and Python (IPython in particular, which I really like), andC-RET
--already the send code command in R-- seems more comfortable to me.In the link cited at the beginning of this question they suggest to add the following lines to the
.emacs
file to change theC-c |
command intoC-c C-r
:(eval-after-load "python" '(progn (define-key python-mode-map (kbd "C-c C-r") 'python-shell-send-region)))
At the moment, my python/IPython configuration in my
.emacs
file looks like this:;; Enable Python (add-to-list 'load-path "/sw/lib/python-mode-1.0") (load "python-mode") (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t) ;; Ipython. This python-mode takes the Key-map and the menu (when (executable-find "ipython") (setq python-shell-interpreter "ipython" python-shell-interpreter-args "" python-shell-prompt-regexp "In \\[[0-9]+\\]: " python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: " python-shell-completion-setup-code "from IPython.core.completerlib import module_completion" python-shell-completion-module-string-code "';'.join(module_completion('''%s'''))\n" python-shell-completion-string-code "';'.join(get_ipython().Completer.all_completions('''%s'''))\n"))
Which are two python modes running in parallel and the second one (IPython, the one I use all the time) takes the key-map and the menu (by the way, any suggestion for a better configuration is welcome. The IPython section is based on: How to open IPython interpreter in emacs?).
I have tried to add the
(eval-after-load "python" '(progn ...
command described before at the end of my python configuration (of course, changingC-c C-r
toC-RET
orC-ret
or evenC-<return>
).I have also tried within the
when (executable-find "ipython") ...
chunk in different forms (such as simply(define-key python-mode-map (kbd "C-c C-r") 'python-shell-send-region)
). But nothing seems to work.Therefore, my question would be: Given my Python/IPython configuration, what do I have to include in my
.emacs
file to change theC-c C-r
command into (C-RET)Many thanks in advance!
解决方案Use (kbd "RET")
Try this with python.el
(eval-after-load "python" '(define-key python-mode-map [(control c)(kbd "RET")] 'python-shell-send-region))
WRT python-mode.el:
(eval-after-load "python-mode" '(define-key python-mode-map [(control c) (kbd "RET")] 'py-execute-region))
BTW unless IPython-exclusiv features are needed, recommend to execute code from Emacs through a common Python. IPython implements a bunch of cool things, which might appear orthogonal to Emacs, which also implements a bunch of cool things.
这篇关于更改Emacs“发送代码到解释器”C-c C-r命令在IPython模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!