diff options
| author | Dmitry Lazurkin | 2017-01-04 21:46:21 +0300 |
|---|---|---|
| committer | Noam Postavsky | 2017-01-12 20:40:19 -0500 |
| commit | d4a97088f69eb5729261ee4581cfb7d60c673ebd (patch) | |
| tree | 01aa98aa5b6f31c31e4b66192a34a57868b45730 | |
| parent | 55b52658470322a701000e88728d096a03b7c8ca (diff) | |
| download | emacs-d4a97088f69eb5729261ee4581cfb7d60c673ebd.tar.gz emacs-d4a97088f69eb5729261ee4581cfb7d60c673ebd.zip | |
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.") | |||
| 4415 | "*class definition*" | 4415 | "*class definition*" |
| 4416 | "*function definition*")) | 4416 | "*function definition*")) |
| 4417 | 4417 | ||
| 4418 | (defun python-imenu--get-defun-type-name () | ||
| 4419 | "Return defun type and name at current position." | ||
| 4420 | (when (looking-at python-nav-beginning-of-defun-regexp) | ||
| 4421 | (let ((split (split-string (match-string-no-properties 0)))) | ||
| 4422 | (if (= (length split) 2) | ||
| 4423 | split | ||
| 4424 | (list (concat (car split) " " (cadr split)) | ||
| 4425 | (car (last split))))))) | ||
| 4426 | |||
| 4418 | (defun python-imenu--put-parent (type name pos tree) | 4427 | (defun python-imenu--put-parent (type name pos tree) |
| 4419 | "Add the parent with TYPE, NAME and POS to TREE." | 4428 | "Add the parent with TYPE, NAME and POS to TREE." |
| 4420 | (let ((label | 4429 | (let ((label |
| @@ -4432,11 +4441,9 @@ not be passed explicitly unless you know what you are doing." | |||
| 4432 | (setq min-indent (or min-indent 0) | 4441 | (setq min-indent (or min-indent 0) |
| 4433 | prev-indent (or prev-indent python-indent-offset)) | 4442 | prev-indent (or prev-indent python-indent-offset)) |
| 4434 | (let* ((pos (python-nav-backward-defun)) | 4443 | (let* ((pos (python-nav-backward-defun)) |
| 4435 | (type) | 4444 | (defun-type-name (and pos (python-imenu--get-defun-type-name))) |
| 4436 | (name (when (and pos (looking-at python-nav-beginning-of-defun-regexp)) | 4445 | (type (car defun-type-name)) |
| 4437 | (let ((split (split-string (match-string-no-properties 0)))) | 4446 | (name (cadr defun-type-name)) |
| 4438 | (setq type (car split)) | ||
| 4439 | (cadr split)))) | ||
| 4440 | (label (when name | 4447 | (label (when name |
| 4441 | (funcall python-imenu-format-item-label-function type name))) | 4448 | (funcall python-imenu-format-item-label-function type name))) |
| 4442 | (indent (current-indentation)) | 4449 | (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): | |||
| 3559 | 3559 | ||
| 3560 | def c(self): | 3560 | def c(self): |
| 3561 | pass | 3561 | pass |
| 3562 | |||
| 3563 | async def d(self): | ||
| 3564 | pass | ||
| 3562 | " | 3565 | " |
| 3563 | (goto-char (point-max)) | 3566 | (goto-char (point-max)) |
| 3564 | (should (equal | 3567 | (should (equal |
| @@ -3580,7 +3583,8 @@ class Baz(object): | |||
| 3580 | (list | 3583 | (list |
| 3581 | "Frob (class)" | 3584 | "Frob (class)" |
| 3582 | (cons "*class definition*" (copy-marker 601)) | 3585 | (cons "*class definition*" (copy-marker 601)) |
| 3583 | (cons "c (def)" (copy-marker 626))))) | 3586 | (cons "c (def)" (copy-marker 626)) |
| 3587 | (cons "d (async def)" (copy-marker 665))))) | ||
| 3584 | (python-imenu-create-index))))) | 3588 | (python-imenu-create-index))))) |
| 3585 | 3589 | ||
| 3586 | (ert-deftest python-imenu-create-index-2 () | 3590 | (ert-deftest python-imenu-create-index-2 () |
| @@ -3702,6 +3706,9 @@ class Baz(object): | |||
| 3702 | 3706 | ||
| 3703 | def c(self): | 3707 | def c(self): |
| 3704 | pass | 3708 | pass |
| 3709 | |||
| 3710 | async def d(self): | ||
| 3711 | pass | ||
| 3705 | " | 3712 | " |
| 3706 | (goto-char (point-max)) | 3713 | (goto-char (point-max)) |
| 3707 | (should (equal | 3714 | (should (equal |
| @@ -3714,7 +3721,8 @@ class Baz(object): | |||
| 3714 | (cons "Baz.a" (copy-marker 539)) | 3721 | (cons "Baz.a" (copy-marker 539)) |
| 3715 | (cons "Baz.b" (copy-marker 570)) | 3722 | (cons "Baz.b" (copy-marker 570)) |
| 3716 | (cons "Baz.Frob" (copy-marker 601)) | 3723 | (cons "Baz.Frob" (copy-marker 601)) |
| 3717 | (cons "Baz.Frob.c" (copy-marker 626))) | 3724 | (cons "Baz.Frob.c" (copy-marker 626)) |
| 3725 | (cons "Baz.Frob.d" (copy-marker 665))) | ||
| 3718 | (python-imenu-create-flat-index))))) | 3726 | (python-imenu-create-flat-index))))) |
| 3719 | 3727 | ||
| 3720 | (ert-deftest python-imenu-create-flat-index-2 () | 3728 | (ert-deftest python-imenu-create-flat-index-2 () |