mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
(py-parse-state): make sure we don't land inside a triple-quoted
string
This commit is contained in:
parent
ab69eb9673
commit
43ecf8ee58
1 changed files with 16 additions and 10 deletions
|
@ -1752,16 +1752,22 @@ local bindings to py-newline-and-indent."))
|
||||||
;; returns the parse state at point (see parse-partial-sexp docs)
|
;; returns the parse state at point (see parse-partial-sexp docs)
|
||||||
(defun py-parse-state ()
|
(defun py-parse-state ()
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((here (point)) )
|
(let ((here (point))
|
||||||
|
pps done)
|
||||||
|
(while (not done)
|
||||||
;; back up to the first preceding line (if any; else start of
|
;; back up to the first preceding line (if any; else start of
|
||||||
;; buffer) that begins with a popular Python keyword, or a non-
|
;; buffer) that begins with a popular Python keyword, or a
|
||||||
;; whitespace and non-comment character. These are good places
|
;; non- whitespace and non-comment character. These are good
|
||||||
;; to start parsing to see whether where we started is at a
|
;; places to start parsing to see whether where we started is
|
||||||
;; non-zero nesting level. It may be slow for people who write
|
;; at a non-zero nesting level. It may be slow for people who
|
||||||
;; huge code blocks or huge lists ... tough beans.
|
;; write huge code blocks or huge lists ... tough beans.
|
||||||
(re-search-backward py-parse-state-re nil 'move)
|
(re-search-backward py-parse-state-re nil 'move)
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(parse-partial-sexp (point) here))))
|
(save-excursion
|
||||||
|
(setq pps (parse-partial-sexp (point) here)))
|
||||||
|
;; make sure we don't land inside a triple-quoted string
|
||||||
|
(setq done (or (not (nth 3 pps)) (bobp))))
|
||||||
|
pps)))
|
||||||
|
|
||||||
;; if point is at a non-zero nesting level, returns the number of the
|
;; if point is at a non-zero nesting level, returns the number of the
|
||||||
;; character that opens the smallest enclosing unclosed list; else
|
;; character that opens the smallest enclosing unclosed list; else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue