aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorYuan Fu2022-11-21 12:54:35 -0800
committerYuan Fu2022-11-21 12:54:35 -0800
commitaaeaa310f0391f5a5193e1a3d6e026986c4f2c0c (patch)
tree67765b95359bfc462e95606043e6b0cea3bb7c49 /lisp/progmodes/python.el
parentb2ea38ab03e801859163b74a292aa75008e36541 (diff)
parentf176a36f4629b56c9fd9e3fc15aebd04a168c4f5 (diff)
downloademacs-aaeaa310f0391f5a5193e1a3d6e026986c4f2c0c.tar.gz
emacs-aaeaa310f0391f5a5193e1a3d6e026986c4f2c0c.zip
Merge remote-tracking branch 'savannah/master' into feature/tree-sitter
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el74
1 files changed, 53 insertions, 21 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index bb2aa37ca61..af59b8e1467 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3682,15 +3682,25 @@ detecting a prompt at the end of the buffer."
3682 "Send STRING to PROCESS and inhibit output. 3682 "Send STRING to PROCESS and inhibit output.
3683Return the output." 3683Return the output."
3684 (or process (setq process (python-shell-get-process-or-error))) 3684 (or process (setq process (python-shell-get-process-or-error)))
3685 (cl-letf (((process-filter process) 3685 (cl-letf* (((process-filter process)
3686 (lambda (_proc str) 3686 (lambda (_proc str)
3687 (with-current-buffer (process-buffer process) 3687 (with-current-buffer (process-buffer process)
3688 (python-shell-output-filter str)))) 3688 (python-shell-output-filter str))))
3689 (python-shell-output-filter-in-progress t) 3689 (python-shell-output-filter-in-progress t)
3690 (inhibit-quit t)) 3690 (inhibit-quit t)
3691 (buffer (process-buffer process))
3692 (last-prompt (cond ((boundp 'comint-last-prompt-overlay)
3693 'comint-last-prompt-overlay)
3694 ((boundp 'comint-last-prompt)
3695 'comint-last-prompt)))
3696 (last-prompt-value (buffer-local-value last-prompt buffer)))
3691 (or 3697 (or
3692 (with-local-quit 3698 (with-local-quit
3693 (python-shell-send-string string process) 3699 (unwind-protect
3700 (python-shell-send-string string process)
3701 (when (not (null last-prompt))
3702 (with-current-buffer buffer
3703 (set last-prompt last-prompt-value))))
3694 (while python-shell-output-filter-in-progress 3704 (while python-shell-output-filter-in-progress
3695 ;; `python-shell-output-filter' takes care of setting 3705 ;; `python-shell-output-filter' takes care of setting
3696 ;; `python-shell-output-filter-in-progress' to NIL after it 3706 ;; `python-shell-output-filter-in-progress' to NIL after it
@@ -3699,7 +3709,7 @@ Return the output."
3699 (prog1 3709 (prog1
3700 python-shell-output-filter-buffer 3710 python-shell-output-filter-buffer
3701 (setq python-shell-output-filter-buffer nil))) 3711 (setq python-shell-output-filter-buffer nil)))
3702 (with-current-buffer (process-buffer process) 3712 (with-current-buffer buffer
3703 (comint-interrupt-subjob))))) 3713 (comint-interrupt-subjob)))))
3704 3714
3705(defun python-shell-internal-send-string (string) 3715(defun python-shell-internal-send-string (string)
@@ -4328,7 +4338,8 @@ With argument MSG show activation/deactivation message."
4328Optional argument PROCESS forces completions to be retrieved 4338Optional argument PROCESS forces completions to be retrieved
4329using that one instead of current buffer's process." 4339using that one instead of current buffer's process."
4330 (setq process (or process (get-buffer-process (current-buffer)))) 4340 (setq process (or process (get-buffer-process (current-buffer))))
4331 (let* ((line-start (if (derived-mode-p 'inferior-python-mode) 4341 (let* ((is-shell-buffer (derived-mode-p 'inferior-python-mode))
4342 (line-start (if is-shell-buffer
4332 ;; Working on a shell buffer: use prompt end. 4343 ;; Working on a shell buffer: use prompt end.
4333 (cdr (python-util-comint-last-prompt)) 4344 (cdr (python-util-comint-last-prompt))
4334 (line-beginning-position))) 4345 (line-beginning-position)))
@@ -4338,15 +4349,18 @@ using that one instead of current buffer's process."
4338 (buffer-substring-no-properties line-start (point))) 4349 (buffer-substring-no-properties line-start (point)))
4339 (buffer-substring-no-properties line-start (point)))) 4350 (buffer-substring-no-properties line-start (point))))
4340 (start 4351 (start
4341 (save-excursion 4352 (if (< (point) line-start)
4342 (if (not (re-search-backward 4353 (point)
4343 (python-rx 4354 (save-excursion
4344 (or whitespace open-paren close-paren string-delimiter simple-operator)) 4355 (if (not (re-search-backward
4345 line-start 4356 (python-rx
4346 t 1)) 4357 (or whitespace open-paren close-paren
4347 line-start 4358 string-delimiter simple-operator))
4348 (forward-char (length (match-string-no-properties 0))) 4359 line-start
4349 (point)))) 4360 t 1))
4361 line-start
4362 (forward-char (length (match-string-no-properties 0)))
4363 (point)))))
4350 (end (point)) 4364 (end (point))
4351 (prompt-boundaries 4365 (prompt-boundaries
4352 (with-current-buffer (process-buffer process) 4366 (with-current-buffer (process-buffer process)
@@ -4359,7 +4373,11 @@ using that one instead of current buffer's process."
4359 (completion-fn 4373 (completion-fn
4360 (with-current-buffer (process-buffer process) 4374 (with-current-buffer (process-buffer process)
4361 (cond ((or (null prompt) 4375 (cond ((or (null prompt)
4362 (< (point) (cdr prompt-boundaries))) 4376 (and is-shell-buffer
4377 (< (point) (cdr prompt-boundaries)))
4378 (and (not is-shell-buffer)
4379 (string-match-p
4380 python-shell-prompt-pdb-regexp prompt)))
4363 #'ignore) 4381 #'ignore)
4364 ((or (not python-shell-completion-native-enable) 4382 ((or (not python-shell-completion-native-enable)
4365 ;; Even if native completion is enabled, for 4383 ;; Even if native completion is enabled, for
@@ -4626,7 +4644,9 @@ For this to work as best as possible you should call
4626`python-shell-send-buffer' from time to time so context in 4644`python-shell-send-buffer' from time to time so context in
4627inferior Python process is updated properly." 4645inferior Python process is updated properly."
4628 (let ((process (python-shell-get-process))) 4646 (let ((process (python-shell-get-process)))
4629 (when process 4647 (when (and process
4648 (python-shell-with-shell-buffer
4649 (python-util-comint-end-of-output-p)))
4630 (python-shell-completion-at-point process)))) 4650 (python-shell-completion-at-point process))))
4631 4651
4632(define-obsolete-function-alias 4652(define-obsolete-function-alias
@@ -5051,6 +5071,8 @@ def __FFAP_get_module_path(objstr):
5051(defun python-ffap-module-path (module) 5071(defun python-ffap-module-path (module)
5052 "Function for `ffap-alist' to return path for MODULE." 5072 "Function for `ffap-alist' to return path for MODULE."
5053 (when-let ((process (python-shell-get-process)) 5073 (when-let ((process (python-shell-get-process))
5074 (ready (python-shell-with-shell-buffer
5075 (python-util-comint-end-of-output-p)))
5054 (module-file 5076 (module-file
5055 (python-shell-send-string-no-output 5077 (python-shell-send-string-no-output
5056 (format "%s\nprint(__FFAP_get_module_path(%s))" 5078 (format "%s\nprint(__FFAP_get_module_path(%s))"
@@ -5169,7 +5191,9 @@ If not FORCE-INPUT is passed then what `python-eldoc--get-symbol-at-point'
5169returns will be used. If not FORCE-PROCESS is passed what 5191returns will be used. If not FORCE-PROCESS is passed what
5170`python-shell-get-process' returns is used." 5192`python-shell-get-process' returns is used."
5171 (let ((process (or force-process (python-shell-get-process)))) 5193 (let ((process (or force-process (python-shell-get-process))))
5172 (when process 5194 (when (and process
5195 (python-shell-with-shell-buffer
5196 (python-util-comint-end-of-output-p)))
5173 (let* ((input (or force-input 5197 (let* ((input (or force-input
5174 (python-eldoc--get-symbol-at-point))) 5198 (python-eldoc--get-symbol-at-point)))
5175 (docstring 5199 (docstring
@@ -5731,6 +5755,7 @@ likely an invalid python file."
5731 ;; block and the current line, otherwise it 5755 ;; block and the current line, otherwise it
5732 ;; is not an opening block. 5756 ;; is not an opening block.
5733 (save-excursion 5757 (save-excursion
5758 (python-nav-end-of-statement)
5734 (forward-line) 5759 (forward-line)
5735 (let ((no-back-indent t)) 5760 (let ((no-back-indent t))
5736 (save-match-data 5761 (save-match-data
@@ -6024,6 +6049,13 @@ This is for compatibility with Emacs < 24.4."
6024 comint-last-prompt) 6049 comint-last-prompt)
6025 (t nil))) 6050 (t nil)))
6026 6051
6052(defun python-util-comint-end-of-output-p ()
6053 "Return non-nil if the last prompt matches input prompt."
6054 (when-let ((prompt (python-util-comint-last-prompt)))
6055 (python-shell-comint-end-of-output-p
6056 (buffer-substring-no-properties
6057 (car prompt) (cdr prompt)))))
6058
6027(defun python-util-forward-comment (&optional direction) 6059(defun python-util-forward-comment (&optional direction)
6028 "Python mode specific version of `forward-comment'. 6060 "Python mode specific version of `forward-comment'.
6029Optional argument DIRECTION defines the direction to move to." 6061Optional argument DIRECTION defines the direction to move to."