2

I'm looking to be able to do the same thing as ESS but for python, ie to be able to have two windows side by side one with python shell and the other with text file and send current line or block pressing C-enter or C-p. So I tried to install (python-x) but I don't seem to be able to do that, I tried to install (eval-in-repl) (all this through the MELPA system) but none of it seems to work as when I select python-mode or python-activate nothing happens, and when I open M-x shell then split windows with a python file C-ret isn't binded. Me adding (python-x-setup) in my .spacemacs raise an error at the start.

Any idea how I am supposed to install and setup a package so I can send lines to python shell (or any shell in general) ? I got spacemacs based on emacs 25.1.1

I can run run-python however it opens a shell but how do I get to feed it from a persistent text file ?

1
  • Doesn't C-c C-p open a python shell in .py file and then C-c C-c python-shell-send-buffer or C-c C-r python-shell-send-region work? Commented Feb 2, 2017 at 13:47

3 Answers 3

2

Elpy can do that https://github.com/jorgenschaefer/elpy

The command you are looking for would be elpy-shell-send-current-statement.

You can also try elpy-shell-send-region-or-buffer

Send the active region or the buffer to the Python shell.

If there is an active region, send that. Otherwise, send the whole buffer.

3
  • I can't manage to install it, I've followed the instructions, but where am I supposed to put (package-initialize) (elpy-enable), when I put in .spacemacs user-config I can't start emacs but when I put in user-init I have no elpy command that are available. Commented Jan 3, 2017 at 13:04
  • Sorry I don't know anything about spacemacs.
    – bertfred
    Commented Jan 3, 2017 at 13:24
  • It was my bad I didn't know that I had to add the package in the dotspacemacs-additional-packages it's all good now with python-x Commented Jan 3, 2017 at 16:13
1

Install eval-in-repl from MELPA and configure it as described in the readme at https://github.com/kaz-yos/eval-in-repl/blob/master/README.md

Current instructions from the readme suggest

;;; Python support ;; 
(require 'python) ; if not done elsewhere 
(require 'eval-in-repl-python)
 (add-hook 'python-mode-hook
 '(lambda ()
 (local-set-key (kbd "<C-return>") 'eir-eval-in-python))) 

for python support.

0

I use python-shell-send-buffer-switch it's provided by the python layer in spacemacs (python-mode I assume?). It's bound to , s B and opens and runs your code in a python shell. You can choose python or python3 by customize the variable python-shell-interpreter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.