]> git.eshelyaron.com Git - emacs.git/commitdiff
Indent python multiline strings to start and previous levels
authorCarlos Pita <carlosjosepita@gmail.com>
Sun, 9 Aug 2020 18:44:50 +0000 (20:44 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 9 Aug 2020 18:44:55 +0000 (20:44 +0200)
* progmodes/python.el (python-indent--calculate-indentation): Add an
additional indentation point to match indentation of previous line in
a multiline string.  Then Tab iterates between 0, the start indentation
level and the previous line level (bug#37726).

lisp/progmodes/python.el

index 3af55be4a19f8a28547f11758f780dbd472ad0e2..dcdadae0c4bdda1ee01666ca1c8ee24f3354fcdd 100644 (file)
@@ -1070,11 +1070,18 @@ possibilities can be narrowed to specific indentation points."
         (`(:no-indent . ,_) (prog-first-column)) ; usually 0
         (`(,(or :after-line
                 :after-comment
-                :inside-string
                 :after-backslash) . ,start)
          ;; Copy previous indentation.
          (goto-char start)
          (current-indentation))
+        (`(,(or :inside-string
+                :inside-docstring) . ,start)
+         ;; Copy previous indentation inside string
+         (let ((prev (progn (forward-line -1)
+                            (current-indentation)))
+               (base (progn (goto-char start)
+                            (current-column))))
+           (sort (delete-dups (list 0 prev base)) #'<)))
         (`(,(or :inside-paren-at-closing-paren
                 :inside-paren-at-closing-nested-paren) . ,start)
          (goto-char (+ 1 start))
@@ -1083,12 +1090,6 @@ possibilities can be narrowed to specific indentation points."
              (current-indentation)
            ;; Align with opening paren.
            (current-column)))
-        (`(:inside-docstring . ,start)
-         (let* ((line-indentation (current-indentation))
-                (base-indent (progn
-                               (goto-char start)
-                               (current-indentation))))
-           (max line-indentation base-indent)))
         (`(,(or :after-block-start
                 :after-backslash-first-line
                 :after-backslash-assignment-continuation