Commit dc4f2e53 authored by Fabián Ezequiel Gallina's avatar Fabián Ezequiel Gallina Committed by Fabián Ezequiel Gallina

Enhancements on indentation for lines after a backslash continuation.

Backslashed continuations with parens in the middle are now handled
correctly. Things like this are now indented properly:

objects = Thing.objects.all() \
                       ) \
                       ) \

New Functions:

    * `python-info-beginning-of-backlash' returns the point where a
      backslashed line start.
parent 479a14cc
......@@ -701,7 +701,12 @@ START is the buffer position where the sexp starts."
(when (looking-at "\\.")
(forward-line -1)
;; If after moving one line back point is inside a paren it
;; needs to move back until it's not anymore
(while (prog2
(forward-line -1)
(and (not (bobp))
(python-info-ppss-context 'paren))))
(goto-char (line-end-position))
(while (and (re-search-backward
"\\." (line-beginning-position) t)
......@@ -742,10 +747,12 @@ START is the buffer position where the sexp starts."
(forward-line -1)
(goto-char (python-info-beginning-of-backlash))
(if (save-excursion
(forward-line -1)
(or (python-info-beginning-of-backlash) (point)))
;; The two previous lines ended in a backslash so we must
;; respect previous line indentation.
......@@ -2535,11 +2542,31 @@ not inside a defun."
With optional argument LINE-NUMBER, check that line instead."
(when line-number
(goto-char line-number))
(while (and (not (eobp))
(goto-char (line-end-position))
(python-info-ppss-context 'paren)
(not (equal (char-before (point)) ?\\)))
(forward-line 1))
(when (equal (char-before) ?\\)
(defun python-info-beginning-of-backlash (&optional line-number)
"Return the point where the backlashed line starts."
(goto-char (line-end-position))
(equal (char-after (1- (point))) ?\\))))
(when line-number
(goto-char line-number))
(when (python-info-line-ends-backslash-p)
(while (save-excursion
(goto-char (line-beginning-position))
(python-info-ppss-context 'paren))
(forward-line -1))
(defun python-info-continuation-line-p ()
"Check if current line is continuation of another.
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