配置.emacs以使用IPython解释器

时间:2015-07-07 09:24:36

标签: emacs ipython python-mode

我是lisp的新手,很难为ipython配置emacs。我的.emacs文件的一部分如下所示:

;; Python mode settings
(require 'python-mode)
(add-to-list 'load-path "~/.emacs.d/elpa/")
(let ((default-directory "~/.emacs.d/elpa/"))
  (normal-top-level-add-to-load-path '("."))
  (normal-top-level-add-subdirs-to-load-path))

(autoload 'python-mode "python-mode" "Python Mode." t)
(add-to-list 'auto-mode-alist '("\\.py$\\'" . python-mode))
(add-to-list 'interpreter-mode-alist '("python" . python-mode))

(require 'ipython)

我从命令行窗口运行emacs --debug -init,并在启动emacs时收到以下错误消息:

Debugger entered--Lisp error: (wrong-type-argument listp "-i")
  nconc("-i" ("-colors" "LightBG"))

  eval-buffer(#<buffer  *load*-610080> nil "c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" nil t)  ; Reading at buffer position 9523
  load-with-code-conversion("c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" "c:/Users/xxxx/AppData/Roaming/.emacs.d/elpa/python-mode-20150616.2346/ipython.el" nil t)
  require(ipython)

这可能是非常明显的事情,但不确定如何解决这个问题。如果你能指出我正确的方向,那将非常有帮助。谢谢。

3 个答案:

答案 0 :(得分:1)

似乎你在python-mode.el中使用python-mode:不需要为IPython设置特殊设置。不需要ipython.el,它已经过时了。

py-shell-name配置为“ipython”将使其成为默认shell。 M-x ipython RET 应该可以直接使用,也可以向ipython命令发送内容。

对于特殊情况,覆盖默认值可以查看README.org。

答案 1 :(得分:0)

我在init.el中有以下内容使ipython成为默认的python解释器:

(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-python

希望这有帮助!

答案 2 :(得分:0)

尝试更改ipython命令行,如下所示:

(add-hook 'python-mode-hook
            (lambda ()
              ;You can uncomment next lines
              ;(set (make-variable-buffer-local 'beginning-of-defun-function)
              ;     'py-beginning-of-def-or-class)
              ;(setq outline-regexp "def\\|class ")
              ;(setq tab-width 4)
              ;(define-key py-mode-map "\C-c4" 'uncomment-region )
              ;(outline-minor-mode 1)
              ;(linum-mode 1)
              ;Ipython settings sections
              (require 'ipython)
              (setq-default py-shell-name "ipython")
              (setq-default py-which-bufname "IPython")
              (setq py-python-command-args '("--colors=linux")) ;Command line for run iPython
              ))