diff options
author | Barry Warsaw <barry@python.org> | 1998-12-15 04:36:22 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 1998-12-15 04:36:22 (GMT) |
commit | 9c1696cff55375744281580438fe29d44de04397 (patch) | |
tree | ed2884fe7a9628ce69e8ce2564b97093025a6d49 /Misc | |
parent | ef30092207e684bd3e74fe3d6172b97327a0a089 (diff) | |
download | cpython-9c1696cff55375744281580438fe29d44de04397.zip cpython-9c1696cff55375744281580438fe29d44de04397.tar.gz cpython-9c1696cff55375744281580438fe29d44de04397.tar.bz2 |
(py-goto-beginning-of-tqs): Finds the beginning of the triple quoted
string we find ourselves in, based on the passed in delimiter.
(py-compute-indentation): Fixes for indentation errors when we land
inside a triple quoted string. For example:
def foo():
if os.path.isfile(o_pri_mbox_file) and os.path.isfile(o_pub_mbox_file):
print """\
I found both a private and a public mbox archive file
private: %s
public : %s
I won't move either file, but you should choose one and move it to
%s
You may want to merge them manually, but be careful about exposing private
correspondences to the public.""" % (
o_pri_mbox_file, o_pub_mbox_file, mbox_file)
*----indentation would be wrong on this line.
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/python-mode.el | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el index a99bfdf..ae570e5 100644 --- a/Misc/python-mode.el +++ b/Misc/python-mode.el @@ -1577,7 +1577,8 @@ dedenting." (beginning-of-line) (let* ((bod (py-point 'bod)) (pps (parse-partial-sexp bod (point))) - (boipps (parse-partial-sexp bod (py-point 'boi)))) + (boipps (parse-partial-sexp bod (py-point 'boi))) + placeholder) (cond ;; are we inside a multi-line string or comment? ((or (and (nth 3 pps) (nth 3 boipps)) @@ -1620,6 +1621,11 @@ dedenting." (current-indentation) ;; else they're about to enter the first item (goto-char open-bracket-pos) + (setq placeholder (point)) + (py-goto-initial-line) + (py-goto-beginning-of-tqs + (save-excursion (nth 3 (parse-partial-sexp + placeholder (point))))) (+ (current-indentation) py-indent-offset)))) ;; else on backslash continuation line @@ -1726,18 +1732,15 @@ dedenting." ;; if we landed inside a string, go to the beginning of that ;; string. this handles triple quoted, multi-line spanning ;; strings. - (let* ((delim (nth 3 (parse-partial-sexp bod (point)))) - (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)))) + (py-goto-beginning-of-tqs (nth 3 (parse-partial-sexp bod (point)))) ;; now skip backward over continued lines + (setq placeholder (point)) (py-goto-initial-line) + ;; we may *now* have landed in a TQS, so find the beginning of + ;; this string. + (py-goto-beginning-of-tqs + (save-excursion (nth 3 (parse-partial-sexp + placeholder (point))))) (+ (current-indentation) (if (py-statement-opens-block-p) py-indent-offset @@ -2747,6 +2750,20 @@ If nesting level is zero, return nil." (or (py-backslash-continuation-line-p) (py-nesting-level)))) +(defun py-goto-beginning-of-tqs (delim) + "Go to the beginning of the triple quoted string we find ourselves in. +DELIM is the TQS string delimiter character we're searching backwards +for." + (let ((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))))) + (defun py-goto-initial-line () "Go to the initial line of the current statement. Usually this is the line we're on, but if we're on the 2nd or |