aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-04-09 01:41:55 -0300
committerFabián Ezequiel Gallina2015-04-09 01:41:55 -0300
commitc9415ccbf84fce152e0f4b98ac2ed60680272a47 (patch)
treec80e692a8b2871eb66eedd2736259d9335ad8e14 /lisp/progmodes/python.el
parent911ed2eba4ad691b35e4b81bcd8b24f58b0375ca (diff)
downloademacs-c9415ccbf84fce152e0f4b98ac2ed60680272a47.tar.gz
emacs-c9415ccbf84fce152e0f4b98ac2ed60680272a47.zip
python.el: Indent docstring lines to base-indent
Fixes: debbugs:19595 Thanks to immerrr <immerrr@gmail.com> for reporting and providing an initial patch. * lisp/progmodes/python.el (python-indent-context): Add :inside-docstring context. (python-indent--calculate-indentation): Handle :inside-docstring. (python-indent-region): Re-indent docstrings. * test/automated/python-tests.el (python-indent-region-5) (python-indent-inside-string-2): Fix tests.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el15
1 files changed, 12 insertions, 3 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index da38152558f..856ed322ec6 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -844,7 +844,9 @@ keyword
844 ;; Inside a string. 844 ;; Inside a string.
845 ((let ((start (python-syntax-context 'string ppss))) 845 ((let ((start (python-syntax-context 'string ppss)))
846 (when start 846 (when start
847 (cons :inside-string start)))) 847 (cons (if (python-info-docstring-p)
848 :inside-docstring
849 :inside-string) start))))
848 ;; Inside a paren. 850 ;; Inside a paren.
849 ((let* ((start (python-syntax-context 'paren ppss)) 851 ((let* ((start (python-syntax-context 'paren ppss))
850 (starts-in-newline 852 (starts-in-newline
@@ -989,6 +991,12 @@ possibilities can be narrowed to specific indentation points."
989 ;; Copy previous indentation. 991 ;; Copy previous indentation.
990 (goto-char start) 992 (goto-char start)
991 (current-indentation)) 993 (current-indentation))
994 (`(:inside-docstring . ,start)
995 (let* ((line-indentation (current-indentation))
996 (base-indent (progn
997 (goto-char start)
998 (current-indentation))))
999 (max line-indentation base-indent)))
992 (`(,(or :after-block-start 1000 (`(,(or :after-block-start
993 :after-backslash-first-line 1001 :after-backslash-first-line
994 :inside-paren-newline-start) . ,start) 1002 :inside-paren-newline-start) . ,start)
@@ -1138,14 +1146,15 @@ Called from a program, START and END specify the region to indent."
1138 (not line-is-comment-p)) 1146 (not line-is-comment-p))
1139 (python-info-current-line-empty-p))))) 1147 (python-info-current-line-empty-p)))))
1140 ;; Don't mess with strings, unless it's the 1148 ;; Don't mess with strings, unless it's the
1141 ;; enclosing set of quotes. 1149 ;; enclosing set of quotes or a docstring.
1142 (or (not (python-syntax-context 'string)) 1150 (or (not (python-syntax-context 'string))
1143 (eq 1151 (eq
1144 (syntax-after 1152 (syntax-after
1145 (+ (1- (point)) 1153 (+ (1- (point))
1146 (current-indentation) 1154 (current-indentation)
1147 (python-syntax-count-quotes (char-after) (point)))) 1155 (python-syntax-count-quotes (char-after) (point))))
1148 (string-to-syntax "|"))) 1156 (string-to-syntax "|"))
1157 (python-info-docstring-p))
1149 ;; Skip if current line is a block start, a 1158 ;; Skip if current line is a block start, a
1150 ;; dedenter or block ender. 1159 ;; dedenter or block ender.
1151 (save-excursion 1160 (save-excursion