Search code examples
pythonemacs

How does one get Emacs Python interpreter to work properly


I find the standard Ubuntu Emacs Python interpreter not particularly good to work with. Consider this small program in Emacs:

print ['hello'] * 10000

with C-c C-p and C-c C-r with the code block marked I get a slow output in the Python interpreter window.

If I try to stop the output with C-x o C-c C-c I get a very slow response with Emacs running with close to 100% load. After some time I get KeyboardInterrupt, but then any input at the Python prompt is terrible slow. This makes Emacs Python close to useless for me to work with.

I wonder if there is any kind of setup I am missing?


Solution

  • I can confirm that Emacs in general slows down when you look at very long lines, lines >= 10,000 characters. There is no easy fix. Emacs was designed as a text editor, where source code rarely goes above 200 lines.

    The "solution" is to turn a blind eye to long lines. For example, when running print ["hello"] * 10000, you can "look away" by going to the top of the buffer (M-<). The command will run much faster, in my experience it went about 10x faster by doing this.

    After it's printed out all the text, Emacs is still slow because the line is still in view. A simple way to scroll it out of view is print "\n" * 50.

    In general, I try to avoid printing long lines. For example, if print a happens to print out a lot, I might change it to print "\n".join(a) or print a[:10].