From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Lele Gaifax Newsgroups: gmane.emacs.bugs Subject: bug#21783: 25.0.50; python.el does not support new Python 3.5 keywords Date: Thu, 29 Oct 2015 10:00:04 +0100 Message-ID: <87h9ladp7v.fsf@metapensiero.it> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1446121713 26888 80.91.229.3 (29 Oct 2015 12:28:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 29 Oct 2015 12:28:33 +0000 (UTC) To: 21783@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Oct 29 13:28:22 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZrmJQ-00026y-D4 for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Oct 2015 13:28:12 +0100 Original-Received: from localhost ([::1]:43792 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrmJP-0001I0-N6 for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Oct 2015 08:28:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrmJK-0001Hj-Kx for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 08:28:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrmJH-0001Tu-BO for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 08:28:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:52658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrmJH-0001Tj-8y for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 08:28:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1ZrmJG-0005oB-Os for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 08:28:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lele Gaifax Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 29 Oct 2015 12:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 21783 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.144612165622258 (code B ref -1); Thu, 29 Oct 2015 12:28:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 29 Oct 2015 12:27:36 +0000 Original-Received: from localhost ([127.0.0.1]:43353 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1ZrmIV-0005mV-Uw for submit@debbugs.gnu.org; Thu, 29 Oct 2015 08:27:36 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47277) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Zrj4M-0007ha-DY for submit@debbugs.gnu.org; Thu, 29 Oct 2015 05:00:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zrj4K-000827-M2 for submit@debbugs.gnu.org; Thu, 29 Oct 2015 05:00:26 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:42260) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zrj4K-000823-Ix for submit@debbugs.gnu.org; Thu, 29 Oct 2015 05:00:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zrj4J-0008MJ-2m for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 05:00:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zrj4C-0007zv-Gn for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 05:00:23 -0400 Original-Received: from mail.arstecnica.it ([144.76.81.238]:40944) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zrj4C-0007z4-6z for bug-gnu-emacs@gnu.org; Thu, 29 Oct 2015 05:00:16 -0400 Original-Received: from nautilus (unknown [192.168.1.102]) by mail.arstecnica.it (Postfix) with ESMTPSA id A1DF783E365 for ; Thu, 29 Oct 2015 09:00:05 +0000 (UTC) Original-Received: from nautilus ([151.62.147.82] helo=nautilus) by assp.arstecnica.it with SMTPS(AES128-GCM-SHA256) (2.3.3); 29 Oct 2015 09:00:04 +0000 User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/25.0.50.12 (x86_64-pc-linux-gnu) X-Assp-Version: 2.3.3(14029) on assp.arstecnica.it X-Assp-ID: assp.arstecnica.it m1-09205-04025 X-Assp-Session: 13AACEF4 (mail 1) X-Assp-Envelope-From: lele@metapensiero.it X-Assp-Intended-For: bug-gnu-emacs@gnu.org X-Assp-Client-TLS: yes X-Assp-Server-TLS: yes X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Mailman-Approved-At: Thu, 29 Oct 2015 08:27:14 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x 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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:108142 Archived-At: --=-=-= Content-Type: text/plain Python 3.5, released in mid September 2015, introduced a few new keywords to better support asynchronous code, "async" and "await" in particular. See https://www.python.org/dev/peps/pep-0492/ for details. To avoid breaking already written users code, they are technically not "reserved keywords", but accordingly to the plan they will become that in Python 3.7 (https://www.python.org/dev/peps/pep-0492/#id75). Currently python.el doesn't know anything about them, so it obviously cannot properly indent the following code: async def coroutine(foo, bar): | where "|" represent the cursor position, nor highlight them in any way. I'm attaching a patch that implements such support, with some test cases. See also the thread http://thread.gmane.org/gmane.emacs.devel/190950 where I initially sent the same patch and where I've been solicited to create a bug report. Hope this helps, thanks in advance, ciao, lele. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=python_el+pep492.patch Content-Description: Add PEP492 support to python.el diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 6ff12b5..9f5c087 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -384,7 +384,10 @@ python-mode-map (defconst python-rx-constituents `((block-start . ,(rx symbol-start (or "def" "class" "if" "elif" "else" "try" - "except" "finally" "for" "while" "with") + "except" "finally" "for" "while" "with" + ;; Python 3.5+ PEP492 + (and "async" (+ space) + (or "def" "for" "with"))) symbol-end)) (dedenter . ,(rx symbol-start (or "elif" "else" "except" "finally") @@ -395,7 +398,11 @@ python-mode-map symbol-end)) (decorator . ,(rx line-start (* space) ?@ (any letter ?_) (* (any word ?_)))) - (defun . ,(rx symbol-start (or "def" "class") symbol-end)) + (defun . ,(rx symbol-start + (or "def" "class" + ;; Python 3.5+ PEP492 + (and "async" (+ space) "def")) + symbol-end)) (if-name-main . ,(rx line-start "if" (+ space) "__name__" (+ space) "==" (+ space) (any ?' ?\") "__main__" (any ?' ?\") @@ -527,6 +534,8 @@ python-font-lock-keywords ;; fontified like that in order to keep font-lock consistent between ;; Python versions. "nonlocal" + ;; Python 3.5+ PEP492 + (and "async" (+ space) (or "def" "for" "with")) ;; Extra: "self") symbol-end) diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el index 44b05e2..23d799a 100644 --- a/test/automated/python-tests.el +++ b/test/automated/python-tests.el @@ -604,6 +604,42 @@ python-tests-visible-string (should (eq (car (python-indent-context)) :after-line)) (should (= (python-indent-calculate-indentation) 0)))) +(ert-deftest python-indent-after-async-block-1 () + "Test PEP492 async def." + (python-tests-with-temp-buffer + " +async def foo(a, b, c=True): +" + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (goto-char (point-max)) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + +(ert-deftest python-indent-after-async-block-2 () + "Test PEP492 async with." + (python-tests-with-temp-buffer + " +async with foo(a) as mgr: +" + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (goto-char (point-max)) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + +(ert-deftest python-indent-after-async-block-3 () + "Test PEP492 async for." + (python-tests-with-temp-buffer + " +async for a in sequencer(): +" + (should (eq (car (python-indent-context)) :no-indent)) + (should (= (python-indent-calculate-indentation) 0)) + (goto-char (point-max)) + (should (eq (car (python-indent-context)) :after-block-start)) + (should (= (python-indent-calculate-indentation) 4)))) + (ert-deftest python-indent-after-backslash-1 () "The most common case." (python-tests-with-temp-buffer @@ -1483,6 +1519,26 @@ python-tests-visible-string (beginning-of-line) (point)))))) +(ert-deftest python-nav-beginning-of-defun-3 () + (python-tests-with-temp-buffer + " +class C(object): + + async def m(self): + return await self.c() + + async def c(self): + pass +" + (python-tests-look-at "self.c()") + (should (= (save-excursion + (python-nav-beginning-of-defun) + (point)) + (save-excursion + (python-tests-look-at "async def m" -1) + (beginning-of-line) + (point)))))) + (ert-deftest python-nav-end-of-defun-1 () (python-tests-with-temp-buffer " --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 nickname: Lele Gaifax | Quando vivr=C3=B2 di quello che ho pensato ieri real: Emanuele Gaifas | comincer=C3=B2 ad aver paura di chi mi copia. lele@metapensiero.it | -- Fortunato Depero, 1929. --=-=-=--