From 1890c032210a022b9a0b928e37707e71b074e135 Mon Sep 17 00:00:00 2001 From: memeplex Date: Sun, 13 Oct 2019 14:29:55 -0300 Subject: [PATCH] Indent python multiline strings to start and previous levels * 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. This is useful when writing docstrings in numpy/google formats. --- lisp/progmodes/python.el | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 8e7d9f2..9432bc3 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1035,19 +1035,20 @@ possibilities can be narrowed to specific indentation points." (`(:no-indent . ,_) (prog-first-column)) ; usually 0 (`(,(or :after-line :after-comment - :inside-string :after-backslash :inside-paren-at-closing-paren :inside-paren-at-closing-nested-paren) . ,start) ;; Copy previous indentation. (goto-char start) (current-indentation)) - (`(:inside-docstring . ,start) - (let* ((line-indentation (current-indentation)) - (base-indent (progn - (goto-char start) - (current-indentation)))) - (max line-indentation base-indent))) + (`(,(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 :after-block-start :after-backslash-first-line :after-backslash-assignment-continuation -- 2.20.1