diff options
| author | lin.sun | 2019-11-29 03:10:12 -0500 |
|---|---|---|
| committer | Eli Zaretskii | 2019-12-21 11:13:27 +0200 |
| commit | 9b7f3b0f5774d994311af84d86465c77f00791e5 (patch) | |
| tree | d78686b02311107e964f5e20b65c940eeb878505 /lisp/progmodes/python.el | |
| parent | cc78faee7d23dd0433ba537818a68cbd20fa52a3 (diff) | |
| download | emacs-9b7f3b0f5774d994311af84d86465c77f00791e5.tar.gz emacs-9b7f3b0f5774d994311af84d86465c77f00791e5.zip | |
Add new function `python-shell-send-statement'
* lisp/progmodes/python.el (python-shell-send-statement): New function.
(python-mode-map): Bind it to key "C-c C-e", and define a python-menu
item for it. (Bug#38426)
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 08ef471f6b0..2956bfa0419 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -329,6 +329,7 @@ It returns a file name which can be used directly as argument of | |||
| 329 | ;; Shell interaction | 329 | ;; Shell interaction |
| 330 | (define-key map "\C-c\C-p" 'run-python) | 330 | (define-key map "\C-c\C-p" 'run-python) |
| 331 | (define-key map "\C-c\C-s" 'python-shell-send-string) | 331 | (define-key map "\C-c\C-s" 'python-shell-send-string) |
| 332 | (define-key map "\C-c\C-e" 'python-shell-send-statement) | ||
| 332 | (define-key map "\C-c\C-r" 'python-shell-send-region) | 333 | (define-key map "\C-c\C-r" 'python-shell-send-region) |
| 333 | (define-key map "\C-\M-x" 'python-shell-send-defun) | 334 | (define-key map "\C-\M-x" 'python-shell-send-defun) |
| 334 | (define-key map "\C-c\C-c" 'python-shell-send-buffer) | 335 | (define-key map "\C-c\C-c" 'python-shell-send-buffer) |
| @@ -368,6 +369,8 @@ It returns a file name which can be used directly as argument of | |||
| 368 | :help "Eval string in inferior Python session"] | 369 | :help "Eval string in inferior Python session"] |
| 369 | ["Eval buffer" python-shell-send-buffer | 370 | ["Eval buffer" python-shell-send-buffer |
| 370 | :help "Eval buffer in inferior Python session"] | 371 | :help "Eval buffer in inferior Python session"] |
| 372 | ["Eval statement" python-shell-send-statement | ||
| 373 | :help "Eval statement in inferior Python session"] | ||
| 371 | ["Eval region" python-shell-send-region | 374 | ["Eval region" python-shell-send-region |
| 372 | :help "Eval region in inferior Python session"] | 375 | :help "Eval region in inferior Python session"] |
| 373 | ["Eval defun" python-shell-send-defun | 376 | ["Eval defun" python-shell-send-defun |
| @@ -3162,6 +3165,25 @@ process running; defaults to t when called interactively." | |||
| 3162 | (message "Sent: %s..." (match-string 1 original-string)) | 3165 | (message "Sent: %s..." (match-string 1 original-string)) |
| 3163 | (python-shell-send-string string process))) | 3166 | (python-shell-send-string string process))) |
| 3164 | 3167 | ||
| 3168 | (defun python-shell-send-statement (&optional send-main msg) | ||
| 3169 | "Send the statement at point to inferior Python process. | ||
| 3170 | The statement is delimited by `python-nav-beginning-of-statement' and | ||
| 3171 | `python-nav-end-of-statement', but if the region is active, the text | ||
| 3172 | in the region is sent instead via `python-shell-send-region'. | ||
| 3173 | Optional argument SEND-MAIN, if non-nil, means allow execution of code | ||
| 3174 | inside blocks delimited by \"if __name__ == \\='__main__\\=':\". | ||
| 3175 | Interactively, SEND-MAIN is the prefix argument. | ||
| 3176 | Optional argument MSG, if non-nil, forces display of a user-friendly | ||
| 3177 | message if there's no process running; it defaults to t when called | ||
| 3178 | interactively." | ||
| 3179 | (interactive (list current-prefix-arg t)) | ||
| 3180 | (if (region-active-p) | ||
| 3181 | (python-shell-send-region (region-beginning) (region-end) send-main msg) | ||
| 3182 | (python-shell-send-region | ||
| 3183 | (save-excursion (python-nav-beginning-of-statement)) | ||
| 3184 | (save-excursion (python-nav-end-of-statement)) | ||
| 3185 | send-main msg))) | ||
| 3186 | |||
| 3165 | (defun python-shell-send-buffer (&optional send-main msg) | 3187 | (defun python-shell-send-buffer (&optional send-main msg) |
| 3166 | "Send the entire buffer to inferior Python process. | 3188 | "Send the entire buffer to inferior Python process. |
| 3167 | When optional argument SEND-MAIN is non-nil, allow execution of | 3189 | When optional argument SEND-MAIN is non-nil, allow execution of |