Spurious newline with ipython in Emacs
Piet van Oostrum <[email protected]> Sun, 21 Aug 2016 16:09:08 +0200
| Newsgroups | gmane.comp.python.ipython.devel |
|---|---|
| Message-ID | <[email protected]> |
I get spurious newlines when running ipython in Emacs (Aquamacs on Mac
OS X). I use python-mode.el and its ipython command. There is a newline
after the output prompt. The newline is not there when running in a
Terminal window.
In [2]: 2+3
Out[2]:
5
In [3]:
You see the newline after Out[2]:
I traced this behaviour to the method write_output_prompt in the class
RichPromptDisplayHook in IPython/terminal/prompts.py.
The last line is
print(*(s for t, s in tokens), sep='')
and this prints a newline after the output prompt.
Changing this to
print(*(s for t, s in tokens), sep='', end='')
solves the problem.
An alternative would be to use a write in
IPython/terminal/prompts.py
sys.stdout.write(''.join(s for t, s in tokens))
The reason that ipython in Terminal does not print the newline, is that
in such an ipython sys.displayhook.shell.pt_cli is set to a
promp_toolkit.interface.CommandLineInterface instance and its
print_tokens() method is used, and that one use write to print the
output. In ipython within Emacs sys.displayhook.shell.pt_cli = None. I
don't know why. Probably because the power of prompt_toolkit is not
needed as Emacs does the work.
Anyway, printing a newline after the output prompt is just wrong, IMHO.
--
Piet van Oostrum <[email protected]>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]