"Move to start of current block."
(interactive "^")
(let ((starting-pos (point)))
+ ;; Go to first line beginning a statement
+ (while (and (not (bobp))
+ (or (and (python-nav-beginning-of-statement) nil)
+ (python-info-current-line-comment-p)
+ (python-info-current-line-empty-p)))
+ (forward-line -1))
(if (progn
(python-nav-beginning-of-statement)
(looking-at (python-rx block-start)))
(point-marker)
- ;; Go to first line beginning a statement
- (while (and (not (bobp))
- (or (and (python-nav-beginning-of-statement) nil)
- (python-info-current-line-comment-p)
- (python-info-current-line-empty-p)))
- (forward-line -1))
(let ((block-matching-indent
(- (current-indentation) python-indent-offset)))
(while
(point))
(python-tests-look-at "def wwrap(f):" -1)))))
+(ert-deftest python-nav-beginning-of-block-2 ()
+ (python-tests-with-temp-buffer
+ "
+if True:
+
+ pass
+if False:
+ # comment
+ pass
+"
+ (python-tests-look-at "if True:")
+ (forward-line)
+ (should (= (save-excursion
+ (python-nav-beginning-of-block)
+ (point))
+ (python-tests-look-at "if True:" -1)))
+ (python-tests-look-at "# comment")
+ (should (= (save-excursion
+ (python-nav-beginning-of-block)
+ (point))
+ (python-tests-look-at "if False:" -1)))))
+
(ert-deftest python-nav-end-of-block-1 ()
(python-tests-with-temp-buffer
"