(py-compute-indentation): Several changes made to improve navigation
over and around triple-quoted strings:
- move the beginning-of-line to above the p-p-s call
- in the `t' clause of the big cond, where we skip over
triple-quoted strings, first find out if we're looking at a
single or TQS, then skip over it in one fell swoop, instead of
trying to loop over skipage of SQS's.
(py-parse-state): Implement XEmacs only hack to more accurately figure
out whether we're in a string or not. Can't do this in Emacs because
it lacks the necessary primitive, so we just do it the old (and mostly
accurate, but foolable) way for Emacs.
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index 90a1020..9a62205 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -2,7 +2,7 @@
;; Copyright (C) 1992,1993,1994 Tim Peters
-;; Author: 1995-1997 Barry A. Warsaw
+;; Author: 1995-1998 Barry A. Warsaw
;; 1992-1994 Tim Peters
;; Maintainer: python-mode@python.org
;; Created: Feb 1992
@@ -1447,10 +1447,10 @@
;; honor-block-close-p is non-nil, statements such as return, raise,
;; break, continue, and pass force one level of outdenting.
(save-excursion
+ (beginning-of-line)
(let* ((bod (py-point 'bod))
(pps (parse-partial-sexp bod (point)))
(boipps (parse-partial-sexp bod (py-point 'boi))))
- (beginning-of-line)
(cond
;; are we inside a multi-line string or comment?
((or (and (nth 3 pps) (nth 3 boipps))
@@ -1587,10 +1587,17 @@
;; if we landed inside a string, go to the beginning of that
;; string. this handles triple quoted, multi-line spanning
;; strings.
- (let ((skip (nth 3 (parse-partial-sexp bod (point)))))
- (while skip
- (py-safe (search-backward (make-string 1 skip)))
- (setq skip (nth 3 (parse-partial-sexp bod (point))))))
+ (let* ((pps3 (nth 3 (parse-partial-sexp bod (point))))
+ (delim (and pps3 (int-to-char pps3)))
+ (skip (and delim (make-string 1 delim))))
+ (when skip
+ (save-excursion
+ (py-safe (search-backward skip))
+ (if (and (eq (char-before) delim)
+ (eq (char-before (1- (point))) delim))
+ (setq skip (make-string 3 delim))))
+ ;; we're looking at a triple-quoted string
+ (py-safe (search-backward skip))))
;; now skip backward over continued lines
(py-goto-initial-line)
(+ (current-indentation)
@@ -2494,20 +2501,32 @@
(re-search-backward py-parse-state-re nil 'move)
(setq ci (current-indentation))
(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 ;(zerop ci)
- (not (nth 3 pps))
- (bobp)))
- )
+ ;; In XEmacs, we have a much better way to test for whether
+ ;; we're in a triple-quoted string or not. Emacs does not
+ ;; have this built-in function, which is it's loss because
+ ;; without scanning from the beginning of the buffer, there's
+ ;; no accurate way to determine this otherwise.
+ (if (not (fboundp 'buffer-syntactic-context))
+ ;; Emacs
+ (save-excursion
+ (setq pps (parse-partial-sexp (point) here))
+ ;; make sure we don't land inside a triple-quoted string
+ (setq done (or ;(zerop ci)
+ (not (nth 3 pps))
+ (bobp))))
+ ;; XEmacs
+ (setq done (or (not (buffer-syntactic-context))
+ (bobp)))
+ (when done
+ (setq pps (parse-partial-sexp (point) here)))
+ ))
pps)))
;; if point is at a non-zero nesting level, returns the number of the
;; character that opens the smallest enclosing unclosed list; else
;; returns nil.
(defun py-nesting-level ()
- (let ((status (py-parse-state)) )
+ (let ((status (py-parse-state)))
(if (zerop (car status))
nil ; not in a nest
(car (cdr status))))) ; char# of open bracket