Commit cc7c3c93 authored by Barry Warsaw's avatar Barry Warsaw

(py-parse-state): make sure we don't land inside a triple-quoted

string
parent 79f763d2
...@@ -1752,16 +1752,22 @@ local bindings to py-newline-and-indent.")) ...@@ -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))
;; back up to the first preceding line (if any; else start of pps done)
;; buffer) that begins with a popular Python keyword, or a non- (while (not done)
;; whitespace and non-comment character. These are good places ;; back up to the first preceding line (if any; else start of
;; to start parsing to see whether where we started is at a ;; buffer) that begins with a popular Python keyword, or a
;; non-zero nesting level. It may be slow for people who write ;; non- whitespace and non-comment character. These are good
;; huge code blocks or huge lists ... tough beans. ;; places to start parsing to see whether where we started is
(re-search-backward py-parse-state-re nil 'move) ;; at a non-zero nesting level. It may be slow for people who
(beginning-of-line) ;; write huge code blocks or huge lists ... tough beans.
(parse-partial-sexp (point) here)))) (re-search-backward py-parse-state-re nil 'move)
(beginning-of-line)
(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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment