diff options
author | kobarity <kobarity@gmail.com> | 2023-02-14 00:30:15 +0900 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2023-02-18 18:43:11 +0200 |
commit | 5190ea6259a5fd13ba5e87b92b20f450658cf532 (patch) | |
tree | 2ba3e8c9b0476c88d833a604a0a993064a9eb970 /lisp/progmodes/python.el | |
parent | 6c0d8210175e72dcd7cef2ad77b8f8b680b240bc (diff) | |
download | emacs-5190ea6259a5fd13ba5e87b92b20f450658cf532.tar.gz emacs-5190ea6259a5fd13ba5e87b92b20f450658cf532.tar.bz2 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.el | 26 |
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: whitespaces will be removed. Otherwise, wraps indented regions under an \"if True:\" block so the interpreter evaluates them correctly." - (let* ((single-p (save-restriction - (narrow-to-region start end) - (= (progn - (goto-char start) - (python-nav-beginning-of-statement)) - (progn - (goto-char end) - (python-nav-beginning-of-statement))))) + (let* ((single-p (save-excursion + (save-restriction + (narrow-to-region start end) + (= (progn + (goto-char start) + (python-nav-beginning-of-statement)) + (progn + (goto-char end) + (python-nav-beginning-of-statement)))))) (start (save-excursion ;; If we're at the start of the expression, and if ;; the region consists of a single statement, then @@ -3785,10 +3786,11 @@ the python shell: (line-beginning-position) start)))) (substring (buffer-substring-no-properties start end)) - (starts-at-first-line-p (save-restriction - (widen) - (goto-char start) - (= (line-number-at-pos) 1))) + (starts-at-first-line-p (save-excursion + (save-restriction + (widen) + (goto-char start) + (= (line-number-at-pos) 1)))) (encoding (python-info-encoding)) (toplevel-p (zerop (save-excursion (goto-char start) |