]> git.eshelyaron.com Git - emacs.git/commitdiff
python-end-of-defun-function now works correctly when comments are not indented properly.
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:36 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:36 +0000 (00:03 -0300)
Calling `end-of-defun' on a python file will now do the correct thing,
even for cases like this:

    def fib(n):
        if n < 2:
    #       base cases
            return n
        else:
            return fib(n - 2) + fib(n - 1)

lisp/progmodes/python.el

index ff790bdc25c15acea97c2a2ecbcb8414d24f09a3..7f4aa940d8d10198b96e1853a7227bebf50ef105 100644 (file)
@@ -1062,7 +1062,12 @@ Returns nil if point is not in a def or class."
     (while (and (forward-line 1)
                 (not (eobp))
                 (or (not (current-word))
-                    (> (current-indentation) beg-defun-indent))))
+                    ;; This checks if the indentation is less than the base
+                    ;; one and if the line is not a comment
+                    (or (> (current-indentation) beg-defun-indent)
+                        (equal
+                         (char-after
+                          (+ (point) (current-indentation))) ?#)))))
     (python-util-forward-comment)
     (goto-char (line-beginning-position))))