Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I suppress python-mode's output buffer?

Tags:

python

emacs

In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a complete pain, especially given that there's generally no output in the buffer anyway!

Is there a way to stop the buffer from appearing? Also, how can I send painful electric shocks to the programmer who thought unexpectedly interrupting my train of thought with an empty buffer was a good idea?

Edit: Apparently, there are uses for this behavior, most notably in seeing the output of a program. That's fine, but if there's no output (as in the program with which I'm tinkering), it is really dumb to cut my buffer in half with a blank window.

like image 628
Lee Crabtree Avatar asked Feb 17 '09 16:02

Lee Crabtree


People also ask

Why is Python stdout buffered?

stderr is line-buffered, which helps mitigate some of the problems with output not appearing. By default, Python buffers output to standard output (stdout) and standard error (stderr). This means that output from your code might not show up immediately, making debugging harder.

How do you not show output in Python?

To hide output of subprocess with Python, we can set stdout to subprocess. DEVNULL`. to output the echo command's output to dev null by setting the stdout to subprocess. DEVNULL when we call subprocess.

Why does Python buffer data before writing it to a file?

So, the purpose of buffering is to speed up your program. Its a buffer, meaning its a silo until its full and needs to be drained. Your program took less time because it was making fewer system calls.


4 Answers

What python-mode are you using? Unfortunately, there are several.

Type C-h k and then C-c C-c .. what does it say in the modeline? Does it say "py-execute-buffer" or does it say "python-send-buffer", the first kind indicates you're using Tim Peters' python-mode, while the second indicates you're using Dave Love's python-mode.

I myself prefer Dave Love's python mode, and it's the version that ships with Emacs 23 (and maybe earlier too?). Dave Love's does not pop up the buffer when you run C-c C-c, you have to explicitly switch to the *Python* buffer if you want to see it.

If you're really intent on sticking with Tim Peters' version, you could always put something like the following in your .emacs and you'll never see the output buffer again unless explicitly moved to.

(defadvice py-execute-buffer (after advice-delete-output-window activate)                                      
  (delete-windows-on "*Python Output*")) 
like image 74
EnigmaCurry Avatar answered Oct 06 '22 00:10

EnigmaCurry


Sorry that I can't help you with emacs, but as for your second question, a modified aluminum keyboard from Apple may be a solution:

http://www.apple.com/keyboard/

like image 40
Jason Coon Avatar answered Oct 05 '22 23:10

Jason Coon


In recent python-mode.el that behavior is controlled by a customizable variable:

py-shell-switch-buffers-on-execute

See these links:

  • An Emacs mode for editing Python code

  • Link to direct download

like image 26
Andreas Röhler Avatar answered Oct 05 '22 23:10

Andreas Röhler


You might want to customize the pop-up-windows variable; that controls the splitting functionality.

like image 43
jrockway Avatar answered Oct 06 '22 01:10

jrockway