Skip to content

Commit 170ffa7

Browse files
committed
(py-parse-state): stop searching backwards when we found a keyword at
column zero. Perhaps a kludge, but similar in nature to Emacs' beginning-of-defun shortcut.
1 parent f831d81 commit 170ffa7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

Misc/python-mode.el

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ local bindings to py-newline-and-indent."))
17921792
(defun py-parse-state ()
17931793
(save-excursion
17941794
(let ((here (point))
1795-
pps done)
1795+
pps done ci)
17961796
(while (not done)
17971797
;; back up to the first preceding line (if any; else start of
17981798
;; buffer) that begins with a popular Python keyword, or a
@@ -1801,11 +1801,15 @@ local bindings to py-newline-and-indent."))
18011801
;; at a non-zero nesting level. It may be slow for people who
18021802
;; write huge code blocks or huge lists ... tough beans.
18031803
(re-search-backward py-parse-state-re nil 'move)
1804+
(setq ci (current-indentation))
18041805
(beginning-of-line)
18051806
(save-excursion
18061807
(setq pps (parse-partial-sexp (point) here)))
18071808
;; make sure we don't land inside a triple-quoted string
1808-
(setq done (or (not (nth 3 pps)) (bobp))))
1809+
(setq done (or (zerop ci)
1810+
(not (nth 3 pps))
1811+
(bobp)))
1812+
)
18091813
pps)))
18101814

18111815
;; if point is at a non-zero nesting level, returns the number of the

0 commit comments

Comments
 (0)