Skip to content

New function "spacemacs/python-shell-send-block" to send block #16408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions layers/+lang/python/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,33 @@ Bind formatter to '==' for LSP and '='for all other backends."


;; REPL
(defun spacemacs/python-shell-send-block (&optional arg)
"Send the block under cursor to shell. If optional argument ARG is non-nil
(interactively, the prefix argument), send the block body with its header."
(interactive "P")
(if (fboundp 'python-shell-send-block)
(let ((python-mode-hook nil))
(call-interactively #'python-shell-send-block))
(let ((python-mode-hook nil)
(beg (save-excursion
(when (python-nav-beginning-of-block)
(if arg
(beginning-of-line)
(python-nav-end-of-statement)
(beginning-of-line 2)))
(point-marker)))
(end (save-excursion (python-nav-end-of-block)))
(python-indent-guess-indent-offset-verbose nil))
(if (and beg end)
(python-shell-send-region beg end nil msg t)
(user-error "Can't get code block from current position.")))))

(defun spacemacs/python-shell-send-block-switch (&optional arg)
"Send block to shell and switch to it in insert mode."
(interactive "P")
(call-interactively #'spacemacs/python-shell-send-block)
(python-shell-switch-to-shell)
(evil-insert-state))

(defun spacemacs/python-shell-send-buffer-switch ()
"Send buffer content to shell and switch to it in insert mode."
Expand Down
2 changes: 2 additions & 0 deletions layers/+lang/python/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,8 @@
"sF" 'spacemacs/python-shell-send-defun-switch
"sf" 'spacemacs/python-shell-send-defun
"si" 'spacemacs/python-start-or-switch-repl
"sK" 'spacemacs/python-shell-send-block-switch
"sk" 'spacemacs/python-shell-send-block
"sn" 'spacemacs/python-shell-restart
"sN" 'spacemacs/python-shell-restart-switch
"sR" 'spacemacs/python-shell-send-region-switch
Expand Down
Loading