[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r115481: * lisp/progmodes/python.el (python-indent-c
From: |
Fabián Ezequiel Gallina |
Subject: |
[Emacs-diffs] trunk r115481: * lisp/progmodes/python.el (python-indent-context) |
Date: |
Thu, 12 Dec 2013 05:37:33 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 115481
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15916
committer: Fabián Ezequiel Gallina <address@hidden>
branch nick: trunk
timestamp: Thu 2013-12-12 02:37:09 -0300
message:
* lisp/progmodes/python.el (python-indent-context)
(python-indent-calculate-indentation): Fix auto-identation
behavior for comment blocks.
* test/automated/python-tests.el (python-indent-after-comment-1)
(python-indent-after-comment-2): New tests.
modified:
lisp/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1432
lisp/progmodes/python.el python.el-20091113204419-o5vbwnq5f7feedwu-3008
test/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-8588
test/automated/python-tests.el
pythontests.el-20130220195218-kqcioz3fssz9hwe1-1
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-12-12 04:17:40 +0000
+++ b/lisp/ChangeLog 2013-12-12 05:37:09 +0000
@@ -1,3 +1,9 @@
+2013-12-12 Fabián Ezequiel Gallina <address@hidden>
+
+ * progmodes/python.el (python-indent-context)
+ (python-indent-calculate-indentation): Fix auto-identation
+ behavior for comment blocks. (Bug#15916)
+
2013-12-12 Nathan Trapuzzano <address@hidden> (tiny change)
* progmodes/python.el (python-indent-calculate-indentation): When
=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el 2013-12-12 03:47:41 +0000
+++ b/lisp/progmodes/python.el 2013-12-12 05:37:09 +0000
@@ -686,6 +686,8 @@
\(STATUS . START)
Where status can be any of the following symbols:
+
+ * after-comment: When current line might continue a comment block
* inside-paren: If point in between (), {} or []
* inside-string: If point is inside a string
* after-backslash: Previous line ends in a backslash
@@ -704,6 +706,17 @@
(goto-char (line-beginning-position))
(bobp))
'no-indent)
+ ;; Comment continuation
+ ((save-excursion
+ (when (and
+ (or
+ (python-info-current-line-comment-p)
+ (python-info-current-line-empty-p))
+ (progn
+ (forward-comment -1)
+ (python-info-current-line-comment-p)))
+ (setq start (point))
+ 'after-comment)))
;; Inside string
((setq start (python-syntax-context 'string ppss))
'inside-string)
@@ -755,6 +768,9 @@
(save-excursion
(pcase context-status
(`no-indent 0)
+ (`after-comment
+ (goto-char context-start)
+ (current-indentation))
;; When point is after beginning of block just add one level
;; of indentation relative to the context-start
(`after-beginning-of-block
=== modified file 'test/ChangeLog'
--- a/test/ChangeLog 2013-12-12 03:47:41 +0000
+++ b/test/ChangeLog 2013-12-12 05:37:09 +0000
@@ -1,3 +1,8 @@
+2013-12-12 Fabián Ezequiel Gallina <address@hidden>
+
+ * automated/python-tests.el (python-indent-after-comment-1)
+ (python-indent-after-comment-2): New tests.
+
2013-12-12 Nathan Trapuzzano <address@hidden>
* automated/python-test.el (python-indent-block-enders-1): Rename
=== modified file 'test/automated/python-tests.el'
--- a/test/automated/python-tests.el 2013-12-12 03:47:41 +0000
+++ b/test/automated/python-tests.el 2013-12-12 05:37:09 +0000
@@ -199,6 +199,83 @@
(should (eq (car (python-indent-context)) 'inside-paren))
(should (= (python-indent-calculate-indentation) 4))))
+(ert-deftest python-indent-after-comment-1 ()
+ "The most simple after-comment case that shouldn't fail."
+ (python-tests-with-temp-buffer
+ "# Contents will be modified to correct indentation
+class Blag(object):
+ def _on_child_complete(self, child_future):
+ if self.in_terminal_state():
+ pass
+ # We only complete when all our async children have entered a
+ # terminal state. At that point, if any child failed, we fail
+# with the exception with which the first child failed.
+"
+ (python-tests-look-at "# We only complete")
+ (should (eq (car (python-indent-context)) 'after-line))
+ (should (= (python-indent-calculate-indentation) 8))
+ (python-tests-look-at "# terminal state")
+ (should (eq (car (python-indent-context)) 'after-comment))
+ (should (= (python-indent-calculate-indentation) 8))
+ (python-tests-look-at "# with the exception")
+ (should (eq (car (python-indent-context)) 'after-comment))
+ ;; This one indents relative to previous block, even given the fact
+ ;; that it was under-indented.
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "# terminal state" -1)
+ ;; It doesn't hurt to check again.
+ (should (eq (car (python-indent-context)) 'after-comment))
+ (python-indent-line)
+ (should (= (current-indentation) 8))
+ (python-tests-look-at "# with the exception")
+ (should (eq (car (python-indent-context)) 'after-comment))
+ ;; Now everything should be lined up.
+ (should (= (python-indent-calculate-indentation) 8))))
+
+(ert-deftest python-indent-after-comment-2 ()
+ "Test after-comment in weird cases."
+ (python-tests-with-temp-buffer
+ "# Contents will be modified to correct indentation
+def func(arg):
+ # I don't do much
+ return arg
+ # This comment is badly indented just because.
+ # But we won't mess with the user in this line.
+
+now_we_do_mess_cause_this_is_not_a_comment = 1
+
+# yeah, that.
+"
+ (python-tests-look-at "# I don't do much")
+ (should (eq (car (python-indent-context)) 'after-beginning-of-block))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "return arg")
+ ;; Comment here just gets ignored, this line is not a comment so
+ ;; the rules won't apply here.
+ (should (eq (car (python-indent-context)) 'after-beginning-of-block))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "# This comment is badly")
+ (should (eq (car (python-indent-context)) 'after-line))
+ ;; The return keyword moves indentation backwards 4 spaces, but
+ ;; let's assume this comment was placed there because the user
+ ;; wanted to (manually adding spaces or whatever).
+ (should (= (python-indent-calculate-indentation) 0))
+ (python-tests-look-at "# but we won't mess")
+ (should (eq (car (python-indent-context)) 'after-comment))
+ (should (= (python-indent-calculate-indentation) 4))
+ ;; Behave the same for blank lines: potentially a comment.
+ (forward-line 1)
+ (should (eq (car (python-indent-context)) 'after-comment))
+ (should (= (python-indent-calculate-indentation) 4))
+ (python-tests-look-at "now_we_do_mess")
+ ;; Here is where comment indentation starts to get ignored and
+ ;; where the user can't freely indent anymore.
+ (should (eq (car (python-indent-context)) 'after-line))
+ (should (= (python-indent-calculate-indentation) 0))
+ (python-tests-look-at "# yeah, that.")
+ (should (eq (car (python-indent-context)) 'after-line))
+ (should (= (python-indent-calculate-indentation) 0))))
+
(ert-deftest python-indent-inside-paren-1 ()
"The most simple inside-paren case that shouldn't fail."
(python-tests-with-temp-buffer
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r115481: * lisp/progmodes/python.el (python-indent-context),
Fabián Ezequiel Gallina <=