Setting up Emacs for Python reddit / emacs ---------------------------------------------------------------------- pudentia · 2022-08-27 14:55 I have been setting up Emacs for Python use. When I build my code (by invoking `C-c C-c`) the screen divides into two and the python interpreter appears above my code with the cursor still in the python file. I would like to change three things about this behavior and would appreciate any help: 1. I would like the focus to move from the file to the interpreter. 2. I would like to remove the preamble text: `"Python 3.10.6 (main, Aug 2 2022, 00:00:00) [GCC 12.1.1 20220507 (Red Hat 12.1.1-1)] on linux. Type "help", "copyright", "credits" or "license" for more information."` 3. I would like to have the interpreter start at the bottom with the file on top. ---------------------------------------------------------------------- rrdoa · 2022-08-27 16:02 1. You might have to rebind `C-c C-c` to your own command that calls `python-shell-send-buffer`. Here is an example (untested): ``` (defun my-python-send-shell () (interactive) (python-shell-send-buffer) (python-shell-switch-to-shell)) ``` 3. You can configure `display-buffer-alist`: ``` (setq display-buffer-alist '(("\\*Python\\*" (display-buffer-reuse-mode-window display-buffer-below- selected) (window-height . 15)))) ``` ---------------------------------------------------------------------- pudentia · 2022-08-27 16:32 I am not sure why, but these do not solve the three problems identified in my post. It must be that I have a different configuration to yours. ---------------------------------------------------------------------- rrdoa · 2022-08-27 17:07 What is your configuration? What have you tried? When I type `M-x my- python-send-shell` as defined above, it works. Setting `display-buffer-alist` does not work for you? ---------------------------------------------------------------------- bestlem · 2022-08-28 10:31 2 is fixable by passing the switch -q in pythons command line https://docs.python.org/3/using/cmdline.html#miscellaneous-options ---------------------------------------------------------------------- pudentia · 2022-08-28 11:18 Thanks so much! ---------------------------------------------------------------------- jeffphil · 2022-08-28 15:53 You look like you are using built-in 'Gallina' python-mode. I assume OP is using https://gitlab.com/python-mode-devs/python-mode Edit: This should be equivalent for python-mode.el: `(defun my-python-send-shell () (interactive) (py-shell-send-string (buffer-string)) (py-switch-to-shell))` Also, since the window splitting is weird for python-mode IMHO, probably want to set this along with display-buffer-alist mentioned above: `(setq py-split-window-on-execute nil)`