unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24820: Imenu in `python-mode' does not display function name for async def
@ 2016-10-29 14:34 Dmitry Lazurkin
  2016-12-23 17:32 ` bug#24820: Any suggestions about patch? Dmitry Lazurkin
  2017-01-04 16:48 ` bug#24820: I think copyright is assigned Dmitry Lazurkin
  0 siblings, 2 replies; 17+ messages in thread
From: Dmitry Lazurkin @ 2016-10-29 14:34 UTC (permalink / raw)
  To: 24820

Package: emacs
Version: 25
Tags: patch

 From 9429522de96c27980f61bc107c4801216994d80b Mon Sep 17 00:00:00 2001
From: Dmitry Lazurkin <dilaz03@gmail.com>
Date: Sat, 29 Oct 2016 16:51:40 +0300
Subject: [PATCH] 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.
* test/automated/python-tests.el (python-imenu-create-index-1,
python-imenu-create-flat-index-1): Add async def's.
---
  lisp/progmodes/python.el       | 16 +++++++++++-----
  test/automated/python-tests.el | 12 ++++++++++--
  2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 49f7bcf..60bd4dc 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4389,6 +4389,14 @@ python-imenu-format-parent-item-jump-label
        "*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
+        (cdr split)))))
+
  (defun python-imenu--put-parent (type name pos tree)
    "Add the parent with TYPE, NAME and POS to TREE."
    (let ((label
@@ -4406,11 +4414,9 @@ python-imenu--build-tree
    (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/automated/python-tests.el b/test/automated/python-tests.el
index 54ed922..3cdabf8 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -3552,6 +3552,9 @@ python-tests-shell-interpreter
  
          def c(self):
              pass
+
+        async def d(self):
+            pass
  "
     (goto-char (point-max))
     (should (equal
@@ -3573,7 +3576,8 @@ python-tests-shell-interpreter
                (list
                 "Frob (class)"
                 (cons "*class definition*" (copy-marker 601))
-               (cons "c (def)" (copy-marker 626)))))
+               (cons "c (def)" (copy-marker 626))
+               (cons "d (def)" (copy-marker 665)))))
              (python-imenu-create-index)))))
  
  (ert-deftest python-imenu-create-index-2 ()
@@ -3695,6 +3699,9 @@ python-tests-shell-interpreter
  
          def c(self):
              pass
+
+        async def d(self):
+            pass
  "
     (goto-char (point-max))
     (should (equal
@@ -3707,7 +3714,8 @@ python-tests-shell-interpreter
                    (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 ()
-- 
2.7.4







^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2017-01-13  9:34 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-29 14:34 bug#24820: Imenu in `python-mode' does not display function name for async def Dmitry Lazurkin
2016-12-23 17:32 ` bug#24820: Any suggestions about patch? Dmitry Lazurkin
2016-12-26 22:26   ` npostavs
2017-01-04 16:48 ` bug#24820: I think copyright is assigned Dmitry Lazurkin
2017-01-04 16:55   ` Eli Zaretskii
2017-01-04 20:24     ` bug#24820: Rebase against master Dmitry Lazurkin
2017-01-04 20:27     ` Dmitry Lazurkin
2017-01-05  4:07       ` bug#24820: Imenu in `python-mode' does not display function name for async def npostavs
2017-01-05 10:14         ` Dmitry Lazurkin
2017-01-06  1:19           ` npostavs
2017-01-06 12:07             ` Dmitry Lazurkin
2017-01-06 14:00               ` npostavs
2017-01-06 19:41                 ` Dmitry Lazurkin
2017-01-13  1:49                   ` npostavs
2017-01-13  9:34                     ` dilaz03 .
2017-01-05 20:20         ` Dmitry Lazurkin
2017-01-05 21:03         ` Dmitry Lazurkin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).