@@ -83,14 +83,27 @@ any, similar to what a Jupyter REPL would do."
83
83
; ; Fix newline indentation (indent according to previous blank line)
84
84
(setq acg/electric-indent-newline-as-previous-if-blank t ))
85
85
86
+ (defun acg/python-shell-send-string (str &optional beg end )
87
+ (python-shell-send-string str))
88
+
86
89
; ; The functions below are just sending the code to the shell
87
90
; ; ("invisibly"), but not printing it. @TODO: create a new function
88
91
; ; that prints the results of the last variable, so that it works
89
92
; ; like the Jupyter REPL.
90
93
(define-key python-mode-map (kbd " C-c C-b" ) (acg/eval-with 'acg/python-shell-send-region 'mark-whole-buffer ))
91
94
(define-key python-mode-map (kbd " C-c C-p" ) (acg/eval-with 'acg/python-shell-send-region 'mark-page ))
92
95
(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 )))
94
107
95
108
:hook
96
109
(python-mode . acg/after-python-hook)
@@ -102,5 +115,6 @@ any, similar to what a Jupyter REPL would do."
102
115
(" M->" . python-indent-shift-right)
103
116
(" <f7>" . python-shell-switch-to-shell)
104
117
(" <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)
106
120
))
0 commit comments