aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorkobarity2023-02-14 00:30:15 +0900
committerEli Zaretskii2023-02-18 18:43:11 +0200
commit5190ea6259a5fd13ba5e87b92b20f450658cf532 (patch)
tree2ba3e8c9b0476c88d833a604a0a993064a9eb970 /lisp/progmodes/python.el
parent6c0d8210175e72dcd7cef2ad77b8f8b680b240bc (diff)
downloademacs-5190ea6259a5fd13ba5e87b92b20f450658cf532.tar.gz
emacs-5190ea6259a5fd13ba5e87b92b20f450658cf532.zip
Fix point moving when calling python-shell-send-region
* lisp/progmodes/python.el (python-shell-buffer-substring): Add `save-excursion' to prevent the point from moving. * test/lisp/progmodes/python-tests.el (python-tests-should-not-move): New helper function to assert that point does not move while calling a function. (python-shell-buffer-substring-*): Use `python-tests-should-not-move'. (Bug#61463)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el26
1 files changed, 14 insertions, 12 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index df0d1c96965..0d714c31e9e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3759,14 +3759,15 @@ the python shell:
3759 whitespaces will be removed. Otherwise, wraps indented 3759 whitespaces will be removed. Otherwise, wraps indented
3760 regions under an \"if True:\" block so the interpreter 3760 regions under an \"if True:\" block so the interpreter
3761 evaluates them correctly." 3761 evaluates them correctly."
3762 (let* ((single-p (save-restriction 3762 (let* ((single-p (save-excursion
3763 (narrow-to-region start end) 3763 (save-restriction
3764 (= (progn 3764 (narrow-to-region start end)
3765 (goto-char start) 3765 (= (progn
3766 (python-nav-beginning-of-statement)) 3766 (goto-char start)
3767 (progn 3767 (python-nav-beginning-of-statement))
3768 (goto-char end) 3768 (progn
3769 (python-nav-beginning-of-statement))))) 3769 (goto-char end)
3770 (python-nav-beginning-of-statement))))))
3770 (start (save-excursion 3771 (start (save-excursion
3771 ;; If we're at the start of the expression, and if 3772 ;; If we're at the start of the expression, and if
3772 ;; the region consists of a single statement, then 3773 ;; the region consists of a single statement, then
@@ -3785,10 +3786,11 @@ the python shell:
3785 (line-beginning-position) 3786 (line-beginning-position)
3786 start)))) 3787 start))))
3787 (substring (buffer-substring-no-properties start end)) 3788 (substring (buffer-substring-no-properties start end))
3788 (starts-at-first-line-p (save-restriction 3789 (starts-at-first-line-p (save-excursion
3789 (widen) 3790 (save-restriction
3790 (goto-char start) 3791 (widen)
3791 (= (line-number-at-pos) 1))) 3792 (goto-char start)
3793 (= (line-number-at-pos) 1))))
3792 (encoding (python-info-encoding)) 3794 (encoding (python-info-encoding))
3793 (toplevel-p (zerop (save-excursion 3795 (toplevel-p (zerop (save-excursion
3794 (goto-char start) 3796 (goto-char start)