 	(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

	;; 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))))))
	;; now skip backward over continued lines
	(py-goto-initial-line)
	(+ (current-indentation)

  ;; 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))))
      (cond
       ;; are we inside a multi-line string or comment?
       ((or (and (nth 3 pps) (nth 3 boipps))
