When using python-mode
in Emacs, I first split the screen via C-x 3.
I'd like to be able do C-c ! to launch py-shell
in the other window, not in the window currently active. How can I configure Emacs to do that without having to switch windows with C-x o before launching the shell?
I'm using Emacs 24.3.1, and I've got all my configuration files in ~/.emacs.d
.
I just installed the python-mode
package using package-install
with the Marmalade repository, and I haven't yet edited any .el
file related to python-mode
.
As @BleedingFingers says you can simply use a macro and bind that to a key. It's up to you whether or not you want to re-use the C-c ! binding for the macro or bind it to a different key.
Here's how to proceed should you decide to go with the macro option, starting with Emacs showing only a single window:
F3
C-x 3
C-x o
M-x py-shell
RET
C-x o
F4
M-x name-last-kbd-macro
RET py-shell-other-window
RET
You can replace py-shell-other-window
with whatever name you would like to use for the macro.
Open your configuration file, move point (cursor) to an empty line and do
M-x insert-kbd-macro
RET
This will insert the macro definition into your configuration file.
Add the following code to your configuration file to bind the macro to a key in python-mode
:
(require 'python-mode) ; Make sure python-mode-map is available
; for modification
(define-key python-mode-map (kbd "C-c !") nil) ; Unset default binding
; for C-c !
; (not necessary if you choose an
; unused binding)
(define-key python-mode-map (kbd "C-c !") 'py-shell-other-window) ; Bind macro to C-c !
Mark the lines added in the previous step and run M-x eval-region
RET, or simply restart Emacs.