Comparison of Python modes for Emacs

Question:

So I have Emacs 24.3 and with it comes a quite recent python.el file providing a Python mode for editing.

But I keep reading that there is a python-mode.el on Launchpad, and comparing the two files it jumps out to me that the former is under 4000 lines, while the latter is almost 20000. This suggests that the latter is much more feature-rich.

And I can’t find any online feature comparison about them, documentation, or at least a list about the features for each of them. Yep, there is syntax highlighting and embedded interpreter, but what about completion in shell buffer, completion in source file buffer, autoindent, reindent etc.

So what are the important features of these modes? (Or any other Python mode for Emacs which you recommend.) Please provide detailed answers.

Asked By: marczellm

||

Answers:

I was python-mode.el user once but quit using it a year ago because I felt the way it was developed was not well organized. Here is a list from the note I took at that time. But I need to warn you that almost a year is passed since then so the situation may be changed.

  1. Many copy & paste functions.
  2. Many accidentally working code. For example, not passing around variables but using implicit binding. This produces many compile errors (and will not work if you change it to lexical scope).
  3. Rough granularity of commit. I send a patch, and it was committed with unrelated changes.

One thing I like about python-mode.el is it comes with automated test set (although I’ve never run it). python.el does not have a test set yet. But I know the author of python.el is writing it now.

While python.el is compact, it does not mean you get poor functionality. It is more like keeping core small and let others to extend it by providing concise API. Same author of python.el wrote python-django.el to extend python.el for django projects. I wrote auto-completion plugin for Python called Jedi.el and advanced IPython plugin called EIN. Both of them have better support for python.el than python-mode.el (well, that’s because I don’t use python-mode.el, though).

I had a few thing I missed from python-mode.el first, but they are quickly fixed in python.el (Of course, this probably means that I was not using so much functionality in python-mode.el).

what about completion in shell buffer, completion in source file buffer, autoindent, reindent etc.

  • completion in shell buffer:
    It sort of works in both python.el and python-mode.el. But sometimes it does not work if you have bad combination of Emacs version and python(-mode).el version. So probably python.el is safer in this manner.
    But if you want better solution, use EIN 🙂

  • completion in source file buffer:
    Just use Jedi.el 🙂

  • autoindent/reindent:
    I don’t know which one is better in performance-wise. However, keybind for return differs one to the other. In python-mode.el, if you type RET you get autoindent. In python.el, RET does not give you indentation and you should use C-j instead. Actually C-j for newline+indentation is universal behavior in Emacs. So python.el is better if you do programming in other languages.

Answered By: tkf

Being heavily involved in developing python-mode.el last years, my comment probably is biased: Recommend to stay with python.el for Emacs beginners. Also its author deserves credit for some useful approaches.

python-mode.el is designed to boost edits productivity. It makes it easy to run or execute via python2 and python3 or IPython shells in parallel.

It reduces number of needed keystrokes providing tailored commands. It makes edits faster, assists programming by speech, macro-driven input etc.

Supports Python language features not known from python.el currently:

py-up, py-down – travelling nested blocks

Avoid typos fetching forms at point, a clause for example:

py-backward-clause
py-copy-clause
py-down-clause

No need to customize when testing different versions:

py-execute-clause-python2
py-execute-clause-python3
py-execute-clause-ipython

  • notion of finer grained parts – py-expression, py-minor-expression
  • commands running versioned and paralleled (I)Python-executables, no need to re-define the default Python
  • largely removing the need of an active region marked before, see py-execute-line and a whole bunch more

To get an overview, have a look at the menu. Directory “doc” lists commands.

As the quality of code is raised: a way to compare both modes probably is checking for the bugs listed in http://debbugs.gnu.org/. See for example bug #15510, #16875; or http://lists.gnu.org/archive/html/help-gnu-emacs/2014-04/msg00250.html

Commented at “rough granularity of commit” already: While tkf basically is right looking for smaller pieces, sometimes conditions make me leave the rule. Considerable parts are not written by hand, but by programs residing in directory “devel”. They create files used in development branch frist – i.e. components-python-mode. When starting a new feature it’s often not obvious if the path chosen is fruitful.
After a hundred would-be-commits or so it still might turn out impossible or not so recommendable. Instead of posting all the meanders, used to keep that experimental branch for several days in these cases and check in when tests passed.

BTW assume tkf refers not to compile-errors –which would be looked for instantly– but compiler warnings. Unfortunately Emacs mixes warning about backed style preferences with real errors.

Answered By: Andreas Röhler
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.