]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
(py-compute-indentation): In the most common case, where indentation
authorBarry Warsaw <barry@python.org>
Tue, 20 Jan 1998 22:52:56 +0000 (22:52 +0000)
committerBarry Warsaw <barry@python.org>
Tue, 20 Jan 1998 22:52:56 +0000 (22:52 +0000)
is based on the line above, watch out for landing inside a triple
quoted string.  In this case, use iterative search +
parse-partial-sexp backwards to find the beginning of the string.

Note this does affect performance, but very little in the common cases
(I hope).  It could be made *much* faster by adding Emacs and XEmacs
dependent code -- different code naturally.  :-(

Fixes the following reported bug:

if len(sys.argv) >= 6:
    # More lines here
    fptr = open('/etc/hosts', 'w')
    fptr.write("""# /etc/hosts -- autocreated by /etc/ppp/ip-up
#
# Address from pppd
%-15s %s

# For loopbacking
127.0.0.1 localhost

255.255.255.255 broadcast
""" % (ipaddr, ipname) )

os.chmod('/etc/hosts', 0644)

Misc/python-mode.el

index 4dd1de647e158189503233d1f8e7464711b9f7d1..a209f5bf4cc6c49365d7847c9668bf7181ebcfea 100644 (file)
@@ -1579,6 +1579,11 @@ the new line indented."
        ;; 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)
           (if (py-statement-opens-block-p)
@@ -2527,8 +2532,11 @@ local bindings to py-newline-and-indent."))
 ;; blocks, whether of the backslash or open-bracket varieties, or a
 ;; mix of the two.  The following manages to do that in the usual
 ;; cases.
+;;
+;; Also, if we're sitting inside a triple quoted string, this will
+;; drop us at the line that begins the string.
 (defun py-goto-initial-line ()
-  (let ( open-bracket-pos )
+  (let (open-bracket-pos state strchr bod done)
     (while (py-continuation-line-p)
       (beginning-of-line)
       (if (py-backslash-continuation-line-p)