Toggling between Python buffers

I work with Python a lot, and as any swashbuckling Pythoneer knows, using the Python REPL is a big part of the day-to-day routine.

I often find myself switching from one python buffer to the shell (also known in Emacs lingo as the inferior python process) and back again. That means copious use of C-x b or winner-mode yet.. it just doesn’t feel right. Sure, I could use C-c C-z (in Emacs’ own Python mode) but to me that’s a different use case.

I wanted something easier, so I wrote this a while back to toggle from a Python buffer to the shell, and from the shell you can go back to the last buffer you toggled from. In effect, it works like a very localized “alt-tab”.

Now I can quickly toggle between buffer and shell with a keypress. I’ve set it up so it won’t split windows but will instead switch the active buffer – like when you use C-x b .

I bind the toggle command to F12 in all Python buffers and in the shell, so it’s easy to reach. Feel free to change the keybind if you like (read Mastering Key Bindings in Emacs to learn how.)

Note: I can’t promise it’ll work in the non-Emacs Python mode!