在IPython模式下更改Emacs"将代码发送到解释器"Cc Cr命令

Jav*_*ier 4 python macos emacs ipython

这里的问题与python-mode中的"发送代码到解释器"(Cc |)命令有关(但不完全相同)和互补.

我在Mac 10.9.5,Emacs 24.4,Python 2.7.8和IPython 2.2.0上工作.

我的想法是更改C-c C-remacs命令以在IPython模式下发送一个区域/代码行C-RET,就像使用R一样.这是因为我通常使用R,但从现在开始,我将使用R和Python(特别是IPython,我非常喜欢),并且 - C-RET在R--中已经发送代码命令似乎对我来说更舒服.

在本问题开头引用的链接中,他们建议在.emacs文件中添加以下行以将C-c |命令更改 为C-c C-r:

(eval-after-load "python"
  '(progn
     (define-key python-mode-map (kbd "C-c C-r") 'python-shell-send-region)))
Run Code Online (Sandbox Code Playgroud)

目前,我的.emacs文件中的python/IPython配置如下所示:

;; 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"))
Run Code Online (Sandbox Code Playgroud)

这是两个并行运行的python模式和第二个(IPython,我一直使用的模式)采用键映射和菜单(顺便说一句,任何更好配置的建议都是受欢迎的.IPython部分基于on:如何在emacs中打开IPython解释器?).

我试图添加(eval-after-load "python" '(progn ...在我的蟒配置结束之前描述的命令(当然,改变C-c C-rC-RETC-ret甚至C-<return>).

我也尝试过when (executable-find "ipython") ...不同形式的块(例如简单(define-key python-mode-map (kbd "C-c C-r") 'python-shell-send-region)).但似乎没有任何效果.

因此,我的问题是:鉴于我的Python/IPython配置,我必须在我的.emacs文件中包含什么才能将C-c C-r命令更改为(C-RET)

提前谢谢了!

And*_*ler 5

使用 (kbd "RET")

尝试使用python.el

(eval-after-load "python"
  '(define-key python-mode-map [(control c)(kbd "RET")] 'python-shell-send-region))
Run Code Online (Sandbox Code Playgroud)

WRT python-mode.el:

(eval-after-load "python-mode"
  '(define-key python-mode-map [(control c) (kbd "RET")] 'py-execute-region))
Run Code Online (Sandbox Code Playgroud)

除非需要IPython-exclusiv功能,否则建议通过常见的Python从Emacs执行代码.IPython实现了很多很酷的东西,它们可能与Emacs正交,它也实现了很多很酷的东西.