diff options
| author | Stefan Monnier | 2014-11-16 00:22:20 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2014-11-16 00:22:20 -0500 |
| commit | 9075fcc1937a211bc91e8bc49c332bc55ac99e24 (patch) | |
| tree | 1cff4991107011e0b5d13fac46b0881c30d31a63 /lisp/progmodes/python.el | |
| parent | 86009dd5d886f1101358990e4f8f69a5d1467eb8 (diff) | |
| parent | 4f4cf9c855f5818d4c3c0fb772db8bbcf4f33780 (diff) | |
| download | emacs-9075fcc1937a211bc91e8bc49c332bc55ac99e24.tar.gz emacs-9075fcc1937a211bc91e8bc49c332bc55ac99e24.zip | |
Merge from emacs-24
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 52 |
1 files changed, 33 insertions, 19 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 961aebeeecd..7ed218c7c98 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -964,7 +964,11 @@ START is the buffer position where the sexp starts." | |||
| 964 | 964 | ||
| 965 | (defun python-indent-calculate-levels () | 965 | (defun python-indent-calculate-levels () |
| 966 | "Calculate `python-indent-levels' and reset `python-indent-current-level'." | 966 | "Calculate `python-indent-levels' and reset `python-indent-current-level'." |
| 967 | (if (not (python-info-dedenter-statement-p)) | 967 | (if (or (python-info-continuation-line-p) |
| 968 | (not (python-info-dedenter-statement-p))) | ||
| 969 | ;; XXX: This asks for a refactor. Even if point is on a | ||
| 970 | ;; dedenter statement, it could be multiline and in that case | ||
| 971 | ;; the continuation lines should be indented with normal rules. | ||
| 968 | (let* ((indentation (python-indent-calculate-indentation)) | 972 | (let* ((indentation (python-indent-calculate-indentation)) |
| 969 | (remainder (% indentation python-indent-offset)) | 973 | (remainder (% indentation python-indent-offset)) |
| 970 | (steps (/ (- indentation remainder) python-indent-offset))) | 974 | (steps (/ (- indentation remainder) python-indent-offset))) |
| @@ -1070,24 +1074,34 @@ Called from a program, START and END specify the region to indent." | |||
| 1070 | (or (bolp) (forward-line 1)) | 1074 | (or (bolp) (forward-line 1)) |
| 1071 | (while (< (point) end) | 1075 | (while (< (point) end) |
| 1072 | (or (and (bolp) (eolp)) | 1076 | (or (and (bolp) (eolp)) |
| 1073 | (let (word) | 1077 | (when (and |
| 1074 | (forward-line -1) | 1078 | ;; Skip if previous line is empty or a comment. |
| 1075 | (back-to-indentation) | 1079 | (save-excursion |
| 1076 | (setq word (current-word)) | 1080 | (let ((line-is-comment-p |
| 1077 | (forward-line 1) | 1081 | (python-info-current-line-comment-p))) |
| 1078 | (when (and word | 1082 | (forward-line -1) |
| 1079 | ;; Don't mess with strings, unless it's the | 1083 | (not |
| 1080 | ;; enclosing set of quotes. | 1084 | (or (and (python-info-current-line-comment-p) |
| 1081 | (or (not (python-syntax-context 'string)) | 1085 | ;; Unless this line is a comment too. |
| 1082 | (eq | 1086 | (not line-is-comment-p)) |
| 1083 | (syntax-after | 1087 | (python-info-current-line-empty-p))))) |
| 1084 | (+ (1- (point)) | 1088 | ;; Don't mess with strings, unless it's the |
| 1085 | (current-indentation) | 1089 | ;; enclosing set of quotes. |
| 1086 | (python-syntax-count-quotes (char-after) (point)))) | 1090 | (or (not (python-syntax-context 'string)) |
| 1087 | (string-to-syntax "|")))) | 1091 | (eq |
| 1088 | (beginning-of-line) | 1092 | (syntax-after |
| 1089 | (delete-horizontal-space) | 1093 | (+ (1- (point)) |
| 1090 | (indent-to (python-indent-calculate-indentation))))) | 1094 | (current-indentation) |
| 1095 | (python-syntax-count-quotes (char-after) (point)))) | ||
| 1096 | (string-to-syntax "|"))) | ||
| 1097 | ;; Skip if current line is a block start, a | ||
| 1098 | ;; dedenter or block ender. | ||
| 1099 | (save-excursion | ||
| 1100 | (back-to-indentation) | ||
| 1101 | (not (looking-at | ||
| 1102 | (python-rx | ||
| 1103 | (or block-start dedenter block-ender)))))) | ||
| 1104 | (python-indent-line))) | ||
| 1091 | (forward-line 1)) | 1105 | (forward-line 1)) |
| 1092 | (move-marker end nil)))) | 1106 | (move-marker end nil)))) |
| 1093 | 1107 | ||