From: kobarity Date: Mon, 15 Aug 2022 14:30:23 +0000 (+0200) Subject: Fix `python-nav-forward-block' moving backward under certain conditions X-Git-Tag: emacs-29.0.90~1447^2~137 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0d3aebec0141ab57362477c50065222a03d57c08;p=emacs.git Fix `python-nav-forward-block' moving backward under certain conditions * lisp/progmodes/python.el (python-nav-forward-block): Add check for not moving backward (bug#57223). --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 96f9d14832d..44df3186b27 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1822,7 +1822,8 @@ backward to previous block." (or arg (setq arg 1)) (let ((block-start-regexp (python-rx line-start (* whitespace) block-start)) - (starting-pos (point))) + (starting-pos (point)) + (orig-arg arg)) (while (> arg 0) (python-nav-end-of-statement) (while (and @@ -1836,7 +1837,8 @@ backward to previous block." (python-syntax-context-type))) (setq arg (1+ arg))) (python-nav-beginning-of-statement) - (if (not (looking-at (python-rx block-start))) + (if (or (and (> orig-arg 0) (< (point) starting-pos)) + (not (looking-at (python-rx block-start)))) (and (goto-char starting-pos) nil) (and (not (= (point) starting-pos)) (point-marker))))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index d303050fad9..9e8fa7f5520 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -2942,6 +2942,22 @@ if request.user.is_authenticated(): (python-tests-look-at "if request.user.is_authenticated():" -1))))) +(ert-deftest python-nav-forward-block-2 () + (python-tests-with-temp-buffer + " +if True: + pass +" + (python-tests-look-at "if True:") + (should (not (save-excursion (python-nav-forward-block)))) + (should (not (save-excursion (python-nav-forward-block -1)))) + (forward-char) + (should (not (save-excursion (python-nav-forward-block)))) + (should (= (save-excursion (python-nav-forward-block -1)) + (progn + (end-of-line) + (python-tests-look-at "if True:" -1)))))) + (ert-deftest python-nav-forward-sexp-1 () (python-tests-with-temp-buffer "