Advertisement
Guest User

python-shell-send-defun

a guest
Dec 13th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.09 KB | None | 0 0
  1. ;; python-shell-send-defun (bugfix)
  2. (with-eval-after-load 'python
  3.   (require 'rx)
  4.   (defun python-shell-send-defun (&optional arg msg)
  5.     "Send the current defun to inferior Python process.
  6. When argument ARG is non-nil do not include decorators.  When
  7. optional argument MSG is non-nil, forces display of a
  8. user-friendly message if there's no process running; defaults to
  9. t when called interactively."
  10.     (interactive (list current-prefix-arg t))
  11.     (save-excursion
  12.       (python-shell-send-region
  13.        (progn
  14.          (end-of-line 1)
  15.          (while (and (or (python-nav-beginning-of-defun)
  16.                          (beginning-of-line 1))
  17.                      (> (current-indentation) 0)))
  18.          (when (not arg)
  19.            (while (and (forward-line -1)
  20.                        (looking-at (python-rx decorator))))
  21.            (forward-line 1))
  22.          (point-marker))
  23.        (progn
  24.          (forward-line) ;; fixes a bug when a function has a decorator
  25.          (or (python-nav-end-of-defun)
  26.              (end-of-line 1))
  27.          (point-marker))
  28.        nil  ;; noop
  29.        msg))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement