From 1f0480d4cdea9a266d73f184c56dc94915f1c67a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Fri, 12 Jul 2013 22:55:58 -0300 Subject: [PATCH] * lisp/progmodes/python.el (python-imenu--build-tree): Fix corner case in nested defuns. * test/automated/python-tests.el (python-imenu-create-index-2) (python-imenu-create-index-3): New tests. --- lisp/ChangeLog | 5 +++++ lisp/progmodes/python.el | 9 ++++++-- test/ChangeLog | 5 +++++ test/automated/python-tests.el | 47 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a6a0850b346..1213e509692 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-07-13 Fabián Ezequiel Gallina + + * progmodes/python.el (python-imenu--build-tree): Fix corner case + in nested defuns. + 2013-07-13 Leo Liu * ido.el (ido-exhibit): Handle ido-enter-matching-directory before diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 915b52ce04d..62870f9085b 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -3091,7 +3091,12 @@ you are doing." ;; Stop collecting nodes after moving to a position with ;; indentation equaling min-indent. This is specially ;; useful for navigating nested definitions recursively. - tree) + (if (> num-children 0) + tree + ;; When there are no children, the collected tree is a + ;; single node intended to be added in the list of defuns + ;; of its parent. + (car tree))) (t (python-imenu--build-tree min-indent @@ -3131,7 +3136,7 @@ you are doing." (cons (prog1 (python-imenu--build-tree - prev-indent indent 1 (list (cons label pos))) + prev-indent indent 0 (list (cons label pos))) ;; Adjustment: after scanning backwards ;; for all deeper children, we need to ;; continue our scan for a parent from diff --git a/test/ChangeLog b/test/ChangeLog index d3d8db6b501..d69155a27ff 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2013-07-13 Fabián Ezequiel Gallina + + * automated/python-tests.el (python-imenu-create-index-2) + (python-imenu-create-index-3): New tests. + 2013-07-11 Glenn Morris * automated/ert-tests.el: Require cl-lib at runtime too. diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 1dffe9544fe..fdae235ad38 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el @@ -1745,6 +1745,53 @@ class Baz(object): (cons "c (def)" (copy-marker 626))))) (python-imenu-create-index))))) +(ert-deftest python-imenu-create-index-2 () + (python-tests-with-temp-buffer + " +class Foo(object): + def foo(self): + def foo1(): + pass + + def foobar(self): + pass +" + (goto-char (point-max)) + (should (equal + (list + (list + "Foo (class)" + (cons "*class definition*" (copy-marker 2)) + (list + "foo (def)" + (cons "*function definition*" (copy-marker 21)) + (cons "foo1 (def)" (copy-marker 40))) + (cons "foobar (def)" (copy-marker 78)))) + (python-imenu-create-index))))) + +(ert-deftest python-imenu-create-index-3 () + (python-tests-with-temp-buffer + " +class Foo(object): + def foo(self): + def foo1(): + pass + def foo2(): + pass +" + (goto-char (point-max)) + (should (equal + (list + (list + "Foo (class)" + (cons "*class definition*" (copy-marker 2)) + (list + "foo (def)" + (cons "*function definition*" (copy-marker 21)) + (cons "foo1 (def)" (copy-marker 40)) + (cons "foo2 (def)" (copy-marker 77))))) + (python-imenu-create-index))))) + (ert-deftest python-imenu-create-flat-index-1 () (python-tests-with-temp-buffer " -- 2.11.4.GIT