aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2014-11-15 18:10:58 -0300
committerFabián Ezequiel Gallina2014-11-15 18:10:58 -0300
commit89ebffc1f60ead9b35c88663eadb345c3f569c3d (patch)
treed40ecde08eac62c35e4016caec0b41fbb28efa9d /lisp/progmodes/python.el
parenta6b42789b55688822b762a20865c8d2c812125b9 (diff)
downloademacs-89ebffc1f60ead9b35c88663eadb345c3f569c3d.tar.gz
emacs-89ebffc1f60ead9b35c88663eadb345c3f569c3d.zip
Fix region indentation
Fixes: debbugs:18843 * lisp/progmodes/python.el (python-indent-region): Use python-indent-line and skip special cases. * test/automated/python-tests.el (python-indent-region-1) (python-indent-region-2, python-indent-region-3) (python-indent-region-4, python-indent-region-5): New tests.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el46
1 files changed, 28 insertions, 18 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 95fc52d4d54..5f8d7a29fa6 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1061,24 +1061,34 @@ Called from a program, START and END specify the region to indent."
1061 (or (bolp) (forward-line 1)) 1061 (or (bolp) (forward-line 1))
1062 (while (< (point) end) 1062 (while (< (point) end)
1063 (or (and (bolp) (eolp)) 1063 (or (and (bolp) (eolp))
1064 (let (word) 1064 (when (and
1065 (forward-line -1) 1065 ;; Skip if previous line is empty or a comment.
1066 (back-to-indentation) 1066 (save-excursion
1067 (setq word (current-word)) 1067 (let ((line-is-comment-p
1068 (forward-line 1) 1068 (python-info-current-line-comment-p)))
1069 (when (and word 1069 (forward-line -1)
1070 ;; Don't mess with strings, unless it's the 1070 (not
1071 ;; enclosing set of quotes. 1071 (or (and (python-info-current-line-comment-p)
1072 (or (not (python-syntax-context 'string)) 1072 ;; Unless this line is a comment too.
1073 (eq 1073 (not line-is-comment-p))
1074 (syntax-after 1074 (python-info-current-line-empty-p)))))
1075 (+ (1- (point)) 1075 ;; Don't mess with strings, unless it's the
1076 (current-indentation) 1076 ;; enclosing set of quotes.
1077 (python-syntax-count-quotes (char-after) (point)))) 1077 (or (not (python-syntax-context 'string))
1078 (string-to-syntax "|")))) 1078 (eq
1079 (beginning-of-line) 1079 (syntax-after
1080 (delete-horizontal-space) 1080 (+ (1- (point))
1081 (indent-to (python-indent-calculate-indentation))))) 1081 (current-indentation)
1082 (python-syntax-count-quotes (char-after) (point))))
1083 (string-to-syntax "|")))
1084 ;; Skip if current line is a block start, a
1085 ;; dedenter or block ender.
1086 (save-excursion
1087 (back-to-indentation)
1088 (not (looking-at
1089 (python-rx
1090 (or block-start dedenter block-ender))))))
1091 (python-indent-line)))
1082 (forward-line 1)) 1092 (forward-line 1))
1083 (move-marker end nil)))) 1093 (move-marker end nil))))
1084 1094