mirror of
https://github.com/vale981/py-vterm-interaction.el
synced 2025-03-04 09:31:40 -05:00
only send top level functions
... and don't get confused by functions within functions
This commit is contained in:
parent
6b39ac33fc
commit
461b8c423b
1 changed files with 31 additions and 33 deletions
|
@ -584,14 +584,6 @@ point, the cell is assumed to end with the buffer."
|
|||
If the function has no arguments, the function call is run immediately."
|
||||
(interactive)
|
||||
(save-mark-and-excursion
|
||||
;; (let ((last-mark (mark)))
|
||||
;; (python-mark-defun)
|
||||
;; (while (not (eq (mark) last-mark))
|
||||
;; (setf last-mark (mark))
|
||||
;; (python-mark-defun 1)))
|
||||
;; (mark (region-beginning))
|
||||
;; (next-line)
|
||||
;; (cl-return)
|
||||
(let ((begin (save-mark-and-excursion
|
||||
(python-nav-beginning-of-defun 1)
|
||||
(point)))
|
||||
|
@ -599,34 +591,40 @@ If the function has no arguments, the function call is run immediately."
|
|||
(python-nav-end-of-defun)
|
||||
(point))))
|
||||
(python-nav-beginning-of-defun 1)
|
||||
(next-line)
|
||||
(let ((function-name-regex "def[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)[ \t]*(\\(.*\\))\\([ \t]*->[ \t]*.*?\\)?:"))
|
||||
(save-match-data
|
||||
(let ((name-found (re-search-backward function-name-regex nil nil)))
|
||||
(if name-found
|
||||
(progn
|
||||
(let ((name (match-string 1))
|
||||
(args (match-string 2))
|
||||
(py-vterm-interaction-paste-with-return nil))
|
||||
(beginning-of-line)
|
||||
(if (looking-at "[[:blank:]]+.*")
|
||||
(progn
|
||||
(previous-line)
|
||||
(py-vterm-interaction-run-current-function))
|
||||
(progn
|
||||
(next-line)
|
||||
(let ((function-name-regex "def[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)[ \t]*(\\(.*\\))\\([ \t]*->[ \t]*.*?\\)?:"))
|
||||
(save-match-data
|
||||
(let ((name-found (re-search-backward function-name-regex nil nil)))
|
||||
(if name-found
|
||||
(progn
|
||||
(let ((name (match-string 1))
|
||||
(args (match-string 2))
|
||||
(py-vterm-interaction-paste-with-return nil))
|
||||
|
||||
;; capture decorators too
|
||||
(save-excursion
|
||||
(while
|
||||
(progn (forward-line -1)
|
||||
(beginning-of-line)
|
||||
(if (looking-at "@")
|
||||
(setq begin (point))
|
||||
nil))))
|
||||
;; capture decorators too
|
||||
(save-excursion
|
||||
(while
|
||||
(progn (forward-line -1)
|
||||
(beginning-of-line)
|
||||
(if (looking-at "@")
|
||||
(setq begin (point))
|
||||
nil))))
|
||||
|
||||
(let ((func (buffer-substring-no-properties begin end)))
|
||||
(py-vterm-interaction--send-maybe-silent func name)
|
||||
(py-vterm-interaction-send-return-key))
|
||||
(if (= 0 (length args))
|
||||
(progn
|
||||
(py-vterm-interaction-paste-string (format "%s() " name))
|
||||
(let ((func (buffer-substring-no-properties begin end)))
|
||||
(py-vterm-interaction--send-maybe-silent func name)
|
||||
(py-vterm-interaction-send-return-key))
|
||||
(py-vterm-interaction-paste-string (format "%s(" name)))))
|
||||
(message "No function found"))))))))
|
||||
(if (= 0 (length args))
|
||||
(progn
|
||||
(py-vterm-interaction-paste-string (format "%s() " name))
|
||||
(py-vterm-interaction-send-return-key))
|
||||
(py-vterm-interaction-paste-string (format "%s(" name)))))
|
||||
(message "No function found"))))))))))
|
||||
|
||||
(defun py-vterm-interaction-send-buffer ()
|
||||
"Send the whole content of the script buffer to the Python REPL line by line."
|
||||
|
|
Loading…
Add table
Reference in a new issue