I'm using run-python
on GNU Emacs 24.3 for its "Inferior python shell" and am trying to get behavior similar to lisp-send-last-sexp
, that sends and evaluates an expression in the running interpreter. I'm only trying to do this for one line at a time.
I shortened the solutions given here to the following function:
(add-hook 'python-mode-hook
'my-python-send-statement)
(defun my-python-send-statement ()
(interactive)
(local-set-key [S-return] 'my-python-send-statement)
(end-of-line)
(set-mark (line-beginning-position))
(call-interactively 'python-shell-send-region))
It works, halfway. When I run this command down several lines, I get a string of several >>> prompts and I can't figure out why, as only one line should be sent. Also, sometimes the result won't be shown immediately, and I have to run the command twice. For example:
9+9 # run the command on line 13 of .py file,
======
# result in Python shell.
>>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> 18