From cd1ed6c8f4a50c0bc499bdcf78bbd4e39bdfc4d2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:03:36 -0300 Subject: [PATCH] python-end-of-defun-function now works correctly when comments are not indented properly. 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index ff790bdc25c..7f4aa940d8d 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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)))) -- 2.39.2