Skip to content

Commit 9014d69

Browse files
author
Arthur Colombini Gusmao
committed
Python: Fix python-shell-send-string
1 parent 35dfe8d commit 9014d69

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

acg-emacs/major-modes-config/acg-python.el

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,27 @@ any, similar to what a Jupyter REPL would do."
8383
;; Fix newline indentation (indent according to previous blank line)
8484
(setq acg/electric-indent-newline-as-previous-if-blank t))
8585

86+
(defun acg/python-shell-send-string (str &optional beg end)
87+
(python-shell-send-string str))
88+
8689
;; The functions below are just sending the code to the shell
8790
;; ("invisibly"), but not printing it. @TODO: create a new function
8891
;; that prints the results of the last variable, so that it works
8992
;; like the Jupyter REPL.
9093
(define-key python-mode-map (kbd "C-c C-b") (acg/eval-with 'acg/python-shell-send-region 'mark-whole-buffer))
9194
(define-key python-mode-map (kbd "C-c C-p") (acg/eval-with 'acg/python-shell-send-region 'mark-page))
9295
(define-key python-mode-map (kbd "C-c C-c") (acg/eval-with 'acg/python-shell-send-region 'acg/mark-dwim))
93-
(define-key python-mode-map (kbd "C-c C-l") (acg/eval-with 'python-shell-send-string 'acg/expand-region-to-whole-lines 'acg/unindent-add-last-var))
96+
(define-key python-mode-map (kbd "C-c C-l") (acg/eval-with 'acg/python-shell-send-string 'acg/expand-region-to-whole-lines 'acg/unindent-add-last-var))
97+
98+
(defun acg/run-python-project-root ()
99+
"Runs `run-python' at the project's root directory.
100+
Prompts for a directory if not in project."
101+
(interactive)
102+
(let ((default-directory
103+
(or (project-root (project-current nil))
104+
(read-directory-name "Not in project, choose dir: "
105+
default-directory nil t))))
106+
(call-interactively 'run-python)))
94107

95108
:hook
96109
(python-mode . acg/after-python-hook)
@@ -102,5 +115,6 @@ any, similar to what a Jupyter REPL would do."
102115
("M->" . python-indent-shift-right)
103116
("<f7>" . python-shell-switch-to-shell)
104117
("<f8>" . python-shell-send-buffer)
105-
("C-c C-y" . run-python)
118+
("C-c y y" . run-python)
119+
("C-c y p" . acg/run-python-project-root)
106120
))

0 commit comments

Comments
 (0)