diff options
| author | Fabián Ezequiel Gallina | 2012-10-07 13:13:52 -0300 |
|---|---|---|
| committer | Fabián Ezequiel Gallina | 2012-10-07 13:13:52 -0300 |
| commit | be0d5baecc14ae4dea87e159b803e7f8b1043451 (patch) | |
| tree | 9d88737fa6a0cbe88766bad92cb263a9bef20ea0 | |
| parent | 662a9d0e1ca5f7e2de9aa2d4d59a038aa93ab146 (diff) | |
| download | emacs-be0d5baecc14ae4dea87e159b803e7f8b1043451.tar.gz emacs-be0d5baecc14ae4dea87e159b803e7f8b1043451.zip | |
Enhancements to indentation.
* lisp/progmodes/python.el (python-indent-context): Give priority to
inside-string context. Make comments indentation markers.
(python-indent-region): Do not mess with strings, unless it's the
enclosing set of quotes.
| -rw-r--r-- | lisp/ChangeLog | 8 | ||||
| -rw-r--r-- | lisp/progmodes/python.el | 19 |
2 files changed, 22 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index fe225a9ddd2..64b5d0828cd 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,11 @@ | |||
| 1 | 2012-10-07 Fabián Ezequiel Gallina <fgallina@cuca> | ||
| 2 | |||
| 3 | Enhancements to indentation. | ||
| 4 | * progmodes/python.el (python-indent-context): Give priority to | ||
| 5 | inside-string context. Make comments indentation markers. | ||
| 6 | (python-indent-region): Do not mess with strings, unless it's the | ||
| 7 | enclosing set of quotes. | ||
| 8 | |||
| 1 | 2012-10-07 Stefan Monnier <monnier@iro.umontreal.ca> | 9 | 2012-10-07 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 10 | ||
| 3 | * window.el (internal--before-save-selected-window) | 11 | * window.el (internal--before-save-selected-window) |
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 726c0b2d542..3ac871981e4 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -676,12 +676,12 @@ START is the buffer position where the sexp starts." | |||
| 676 | (goto-char (line-beginning-position)) | 676 | (goto-char (line-beginning-position)) |
| 677 | (bobp)) | 677 | (bobp)) |
| 678 | 'no-indent) | 678 | 'no-indent) |
| 679 | ;; Inside a paren | ||
| 680 | ((setq start (python-syntax-context 'paren ppss)) | ||
| 681 | 'inside-paren) | ||
| 682 | ;; Inside string | 679 | ;; Inside string |
| 683 | ((setq start (python-syntax-context 'string ppss)) | 680 | ((setq start (python-syntax-context 'string ppss)) |
| 684 | 'inside-string) | 681 | 'inside-string) |
| 682 | ;; Inside a paren | ||
| 683 | ((setq start (python-syntax-context 'paren ppss)) | ||
| 684 | 'inside-paren) | ||
| 685 | ;; After backslash | 685 | ;; After backslash |
| 686 | ((setq start (when (not (or (python-syntax-context 'string ppss) | 686 | ((setq start (when (not (or (python-syntax-context 'string ppss) |
| 687 | (python-syntax-context 'comment ppss))) | 687 | (python-syntax-context 'comment ppss))) |
| @@ -710,7 +710,7 @@ START is the buffer position where the sexp starts." | |||
| 710 | ;; After normal line | 710 | ;; After normal line |
| 711 | ((setq start (save-excursion | 711 | ((setq start (save-excursion |
| 712 | (back-to-indentation) | 712 | (back-to-indentation) |
| 713 | (python-util-forward-comment -1) | 713 | (skip-chars-backward (rx (or whitespace ?\n))) |
| 714 | (python-nav-beginning-of-statement) | 714 | (python-nav-beginning-of-statement) |
| 715 | (point-marker))) | 715 | (point-marker))) |
| 716 | 'after-line) | 716 | 'after-line) |
| @@ -973,7 +973,16 @@ Called from a program, START and END specify the region to indent." | |||
| 973 | (back-to-indentation) | 973 | (back-to-indentation) |
| 974 | (setq word (current-word)) | 974 | (setq word (current-word)) |
| 975 | (forward-line 1) | 975 | (forward-line 1) |
| 976 | (when word | 976 | (when (and word |
| 977 | ;; Don't mess with strings, unless it's the | ||
| 978 | ;; enclosing set of quotes. | ||
| 979 | (or (not (python-syntax-context 'string)) | ||
| 980 | (eq | ||
| 981 | (syntax-after | ||
| 982 | (+ (1- (point)) | ||
| 983 | (current-indentation) | ||
| 984 | (python-syntax-count-quotes (char-after) (point)))) | ||
| 985 | (string-to-syntax "|")))) | ||
| 977 | (beginning-of-line) | 986 | (beginning-of-line) |
| 978 | (delete-horizontal-space) | 987 | (delete-horizontal-space) |
| 979 | (indent-to (python-indent-calculate-indentation))))) | 988 | (indent-to (python-indent-calculate-indentation))))) |