IPython support on Emacs 24.x

2019-04-25 17:04发布

问题:

I am confused about the integration of IPython with Emacs. Starting with Emacs 24, Emacs ships with it's own python.el. Does this file have support for IPython or just for Python?

Also, the Emacswiki talks about a file called IPython.el (although the link it provides: http://ipython.scipy.org/dist/ipython.el returns a 404 Error). Is this file compatible with Emacs 24' python.el or does it only work with python-model.el?

回答1:

The new python.el (shipped with Emacs version 24.3) does support IPython. You need to add the following lines to your init.el file (instructions copied from python.el):

(require 'python)
(setq
  python-shell-interpreter "ipython"
  python-shell-interpreter-args "--pylab"
  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")

This works on Linux (I'm running Ubuntu 12.04), some additional modifications might be needed on Windows (for details, check the init.el source).

However, you should not use ipython.el (which is distributed with the IPython package), as it explicitly depends on python-mode.el (at least this is the case with IPython 0.12.1 which is installed on my system).



回答2:

Not certain about the stock python.el as I'm running python-mode.el, which has ipython support in it. But I just took a peek at the python.el sources which got installed with my Emacs 24 and it's got a few references to ipython inside it so it appears that it does support ipython.



回答3:

Emacs ships with python.el since as early as emacs 22. That one is what I am using and relying on to build the rest of the python editing features I need.

Unfortunately someone wrote a new python.el and the maintainers (neither of them uses python mode heavily) OK its replacing of the existing and working python.el in the upcoming 24.3. They were going to do it in a backward-compatible way which sadly, fell on the opposite side.

python.el from before 24.3 supports running ipython.