1

How can I modify (or replace) elpy-shell-send-region-or-buffer (bound to C-c C-c) to behave like ess-eval-region-or-function-or-paragraph-and-step, i.e.

  1. if region is active, evaluate it (this currently works), goto 4.
  2. if inside a function, evaluate it, goto 4.
  3. evaluate current paragraph
  4. Jump to the beginning of next paragraph

Thank you very much!

2

I haven't tried this thoroughly, but should work: 1. if region is active, evaluate it (this currently works), goto 3. 2. if region not active, evaluate current statement, goto 3. 3. Jump to the beginning of next paragraph

(defun python-shell-send-region-or-line nil
  "Sends from python-mode buffer to a python shell, intelligently."
  (interactive)
  (cond ((region-active-p)
     (setq deactivate-mark t)
     (python-shell-send-region (region-beginning) (region-end))
     (python-nav-forward-statement)
 ) (t (elpy-shell-send-current-statement))))

Taken from this answer.

1

elpy-shell-send-region-or-buffer is meant only to send entire buffer or a region.

If you want to step through code, you should use elpy-shell-send-current-statement, which is bound to C-ENTER. This function sends current statement to Python shell and advances to next.

If you want to send entire function, you have to use python-shell-send-defun which is bound to C-M-x.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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