From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dmitry Lazurkin Newsgroups: gmane.emacs.bugs Subject: bug#24820: Imenu in `python-mode' does not display function name for async def Date: Sat, 29 Oct 2016 17:34:53 +0300 Message-ID: <2a59e0dc-45f4-b482-475a-d8db7e5c2ef6@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: blaine.gmane.org 1477771342 24949 195.159.176.226 (29 Oct 2016 20:02:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Oct 2016 20:02:22 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 To: 24820@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Oct 29 22:02:19 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0ZpS-0004sV-1M for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Oct 2016 22:02:10 +0200 Original-Received: from localhost ([::1]:55844 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0ZpU-0002ph-PP for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Oct 2016 16:02:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52718) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0ZpO-0002pP-2j for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2016 16:02:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0ZpK-0008Di-T8 for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2016 16:02:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49665) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1c0ZpK-0008De-Pg for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2016 16:02:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1c0ZpK-0002Gp-CM for bug-gnu-emacs@gnu.org; Sat, 29 Oct 2016 16:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Lazurkin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 29 Oct 2016 20:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 24820 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.14777712668641 (code B ref -1); Sat, 29 Oct 2016 20:02:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Oct 2016 20:01:06 +0000 Original-Received: from localhost ([127.0.0.1]:36830 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0ZoQ-0002FJ-19 for submit@debbugs.gnu.org; Sat, 29 Oct 2016 16:01:06 -0400 Original-Received: from mail-lf0-f68.google.com ([209.85.215.68]:36751) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c0Uiq-00014V-Ne for submit@debbugs.gnu.org; Sat, 29 Oct 2016 10:35:01 -0400 Original-Received: by mail-lf0-f68.google.com with SMTP id b75so5115265lfg.3 for ; Sat, 29 Oct 2016 07:35:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=sUa1g5HQAjl1gupj116Xl+48ypvd7ea5oB7R82VLSOA=; b=mVUG5C8k72ptpdjdQ1XqXFMpS706ddQ+bxoI+Sl8wQ+Dc+VtSwbsXxwlePno8SbtVe LkZujOw1XWCjD/6WAfLfUCCMX99twI6+zuItJvnCEP4BOZBfMYVUoW/PSY/CphXRdSlj XUvMs887uCTBSHESSUhCGTB61hh5LcePwqXqMl+nf0sfdknlUsCoZ0kQPCiy9bB6de0q Y0jSkKqtPZbe8qN9+PgIoL1lm8ejDooQ4N5Ri0EbWZ/DsqNqxSh2YDOadapGVgvzvKWB fupD7cZj+Go87OVxII5OEA85DKPmErs5FPvPGcfXqK/ns/hq9v+b8JB+ZcfBgs553i7u GCPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=sUa1g5HQAjl1gupj116Xl+48ypvd7ea5oB7R82VLSOA=; b=EiAYJ2LGjDyU8CvqxFYdNxYAdup94El6Nf4rb8ECMBjwkXQon4q3yxapTo8Ta5uJp/ ZOjZ85s2zvH/bIATFQC7Pxvmtieg1N8c/pIkuVq0DOu4gxyY35ZcWNrR+/HEg9rishRf Aiib298hh5aC4fI+9d/f04gXjh2s74fQuHdg4OzgrqQ27KoU/ecAq4XUdHvoi+mwyAmc y1sQO4luS+irYc/94XWjcTs6pRValoO/qpJzrUoGZiGgzsrXM744LgwsGkd3nfO5Ebzu CzFfR8ynrYdTXPMBGtAvGbkAmNmNaSSPYkHSIbGb40GmmQoWMjIgd544Cy44nVyflvyM l0zQ== X-Gm-Message-State: ABUngvdzwUrdIJKvEExobeivydapvyDaGTzrX2jGMOjSpehqPMdX9/3QsmQ2zGiF6dLXlA== X-Received: by 10.25.44.66 with SMTP id s63mr13226890lfs.69.1477751694484; Sat, 29 Oct 2016 07:34:54 -0700 (PDT) Original-Received: from [192.168.1.101] (nat4-minsk-pool-46-53-176-8.telecom.by. [46.53.176.8]) by smtp.gmail.com with ESMTPSA id f65sm316105lji.24.2016.10.29.07.34.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 29 Oct 2016 07:34:54 -0700 (PDT) X-Mailman-Approved-At: Sat, 29 Oct 2016 16:01:04 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:125122 Archived-At: Package: emacs Version: 25 Tags: patch From 9429522de96c27980f61bc107c4801216994d80b Mon Sep 17 00:00:00 2001 From: Dmitry Lazurkin 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