summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina <fgallina@gnu.org>2012-10-07 13:13:52 -0300
committerFabián Ezequiel Gallina <fgallina@gnu.org>2012-10-07 13:13:52 -0300
commitbe0d5baecc14ae4dea87e159b803e7f8b1043451 (patch)
tree9d88737fa6a0cbe88766bad92cb263a9bef20ea0
parent662a9d0e1ca5f7e2de9aa2d4d59a038aa93ab146 (diff)
downloademacs-be0d5baecc14ae4dea87e159b803e7f8b1043451.tar.gz
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/ChangeLog8
-rw-r--r--lisp/progmodes/python.el19
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 @@
+2012-10-07 Fabián Ezequiel Gallina <fgallina@cuca>
+
+ Enhancements to indentation.
+ * 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.
+
2012-10-07 Stefan Monnier <monnier@iro.umontreal.ca>
* 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."
(goto-char (line-beginning-position))
(bobp))
'no-indent)
- ;; Inside a paren
- ((setq start (python-syntax-context 'paren ppss))
- 'inside-paren)
;; Inside string
((setq start (python-syntax-context 'string ppss))
'inside-string)
+ ;; Inside a paren
+ ((setq start (python-syntax-context 'paren ppss))
+ 'inside-paren)
;; After backslash
((setq start (when (not (or (python-syntax-context 'string ppss)
(python-syntax-context 'comment ppss)))
@@ -710,7 +710,7 @@ START is the buffer position where the sexp starts."
;; After normal line
((setq start (save-excursion
(back-to-indentation)
- (python-util-forward-comment -1)
+ (skip-chars-backward (rx (or whitespace ?\n)))
(python-nav-beginning-of-statement)
(point-marker)))
'after-line)
@@ -973,7 +973,16 @@ Called from a program, START and END specify the region to indent."
(back-to-indentation)
(setq word (current-word))
(forward-line 1)
- (when word
+ (when (and word
+ ;; Don't mess with strings, unless it's the
+ ;; enclosing set of quotes.
+ (or (not (python-syntax-context 'string))
+ (eq
+ (syntax-after
+ (+ (1- (point))
+ (current-indentation)
+ (python-syntax-count-quotes (char-after) (point))))
+ (string-to-syntax "|"))))
(beginning-of-line)
(delete-horizontal-space)
(indent-to (python-indent-calculate-indentation)))))