diff options
author | Dmitry Lazurkin <dilaz03@gmail.com> | 2017-01-04 21:46:21 +0300 |
---|---|---|
committer | Noam Postavsky <npostavs@gmail.com> | 2017-01-12 20:40:19 -0500 |
commit | d4a97088f69eb5729261ee4581cfb7d60c673ebd (patch) | |
tree | 01aa98aa5b6f31c31e4b66192a34a57868b45730 | |
parent | 55b52658470322a701000e88728d096a03b7c8ca (diff) | |
download | emacs-d4a97088f69eb5729261ee4581cfb7d60c673ebd.tar.gz |
Fix extracting async def type and name in python mode imenu
* lisp/progmodes/python.el (python-imenu--get-defun-type-name):
New function.
(python-imenu--build-tree): Use python-imenu--get-defun-type-name for
extract async or simple def type and name at current
position (Bug#24820).
* test/lisp/progmodes/python-tests.el (python-imenu-create-index-1):
(python-imenu-create-flat-index-1): Add async def's.
-rw-r--r-- | lisp/progmodes/python.el | 17 | ||||
-rw-r--r-- | test/lisp/progmodes/python-tests.el | 12 |
2 files changed, 22 insertions, 7 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 68e19ef5b3b..d8262dd0a75 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -4415,6 +4415,15 @@ It must be a function with two arguments: TYPE and NAME.") "*class definition*" "*function definition*")) +(defun python-imenu--get-defun-type-name () + "Return defun type and name at current position." + (when (looking-at python-nav-beginning-of-defun-regexp) + (let ((split (split-string (match-string-no-properties 0)))) + (if (= (length split) 2) + split + (list (concat (car split) " " (cadr split)) + (car (last split))))))) + (defun python-imenu--put-parent (type name pos tree) "Add the parent with TYPE, NAME and POS to TREE." (let ((label @@ -4432,11 +4441,9 @@ not be passed explicitly unless you know what you are doing." (setq min-indent (or min-indent 0) prev-indent (or prev-indent python-indent-offset)) (let* ((pos (python-nav-backward-defun)) - (type) - (name (when (and pos (looking-at python-nav-beginning-of-defun-regexp)) - (let ((split (split-string (match-string-no-properties 0)))) - (setq type (car split)) - (cadr split)))) + (defun-type-name (and pos (python-imenu--get-defun-type-name))) + (type (car defun-type-name)) + (name (cadr defun-type-name)) (label (when name (funcall python-imenu-format-item-label-function type name))) (indent (current-indentation)) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 94c356b589e..2df1bbf50d8 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -3559,6 +3559,9 @@ class Baz(object): def c(self): pass + + async def d(self): + pass " (goto-char (point-max)) (should (equal @@ -3580,7 +3583,8 @@ class Baz(object): (list "Frob (class)" (cons "*class definition*" (copy-marker 601)) - (cons "c (def)" (copy-marker 626))))) + (cons "c (def)" (copy-marker 626)) + (cons "d (async def)" (copy-marker 665))))) (python-imenu-create-index))))) (ert-deftest python-imenu-create-index-2 () @@ -3702,6 +3706,9 @@ class Baz(object): def c(self): pass + + async def d(self): + pass " (goto-char (point-max)) (should (equal @@ -3714,7 +3721,8 @@ class Baz(object): (cons "Baz.a" (copy-marker 539)) (cons "Baz.b" (copy-marker 570)) (cons "Baz.Frob" (copy-marker 601)) - (cons "Baz.Frob.c" (copy-marker 626))) + (cons "Baz.Frob.c" (copy-marker 626)) + (cons "Baz.Frob.d" (copy-marker 665))) (python-imenu-create-flat-index))))) (ert-deftest python-imenu-create-flat-index-2 () |