From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#58023: 29.0.50; end-of-defun in python-mode does not work with nested function with multi-line arguments Date: Fri, 23 Sep 2022 21:01:20 +0900 Message-ID: Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Fri_Sep_23_21:01:20_2022-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32362"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) To: 58023@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 23 14:28:18 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1obhn0-0008H8-6J for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 23 Sep 2022 14:28:18 +0200 Original-Received: from localhost ([::1]:51500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obhmz-0002M4-1t for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 23 Sep 2022 08:28:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obhNb-0002Um-NE for bug-gnu-emacs@gnu.org; Fri, 23 Sep 2022 08:02:09 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40539) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obhNa-0000TF-CI for bug-gnu-emacs@gnu.org; Fri, 23 Sep 2022 08:02:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1obhNa-0003hY-3Z for bug-gnu-emacs@gnu.org; Fri, 23 Sep 2022 08:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 23 Sep 2022 12:02:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58023 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.166393451814216 (code B ref -1); Fri, 23 Sep 2022 12:02:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 23 Sep 2022 12:01:58 +0000 Original-Received: from localhost ([127.0.0.1]:39617 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obhNW-0003hE-5J for submit@debbugs.gnu.org; Fri, 23 Sep 2022 08:01:58 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:34068) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obhNT-0003h5-CT for submit@debbugs.gnu.org; Fri, 23 Sep 2022 08:01:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48058) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obhNT-0002N7-3C for bug-gnu-emacs@gnu.org; Fri, 23 Sep 2022 08:01:55 -0400 Original-Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:40630) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obhNQ-0000Sl-4t for bug-gnu-emacs@gnu.org; Fri, 23 Sep 2022 08:01:54 -0400 Original-Received: by mail-pj1-x1031.google.com with SMTP id q9-20020a17090a178900b0020265d92ae3so5555899pja.5 for ; Fri, 23 Sep 2022 05:01:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date; bh=YlrKg9JKYRtjCZQLgPcBn3D0cFUww8Iy4qP6HZC4mtE=; b=GcNjjKdkYr1dVHkdgkIaOc1UhFiTG1+Jco80gxsmNZC4gylvuiwvicQVFcTYXeJc8Q 3MGB59q16g2nslvlCoyGJhbcxRqTNDS2anaerRGJBZQ26Erc0X30GUd15mqF2BXh8mym 1ooIDKDsyuIw1mfTgZe8Ur2LE4NOlMownL/eJHKxCxmi9EfrBzeDijhIYCmNRyQ30o+j bweWPIDmPCY6M7lTajo3G0XobiuVVTOMKzdmAOx63bQfhbyE7md+xUk1893KWyBX3bpe 0hQCfl63nsokJGskhHCGjWyXf/UdhdCHne02RyeN7k2syfmBUCQf42RlXq1QQkELqdl8 RsLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date; bh=YlrKg9JKYRtjCZQLgPcBn3D0cFUww8Iy4qP6HZC4mtE=; b=TJUjTzUUAzvyiliW1VBLTmu3RzjWqZHbvjv/anp77Caob8ZK9cboRAsr/+bq6p6PiR 3SpcgzCXuF6ltuC727HhVyXlgiPsbAcE843XiHgSVtwLD0CZMPIGJ0wTRF1SWX+EtScF D170otmPIdVhsk/+voklpjLixEwKVlpY7Xru2VhjHkzqz9seCM+ENdo8CwJfP/P6JooO Y7eQxz/6nbFEMYi9NcrxjcU8towWlMDw+K4n5WzH1vy42/2mVZbDOSX+zBLKp0NSVRwZ 1F5hRigXlk1J1UhA8zUShxLdaXIDqHNFjx+omfyIqlrk0a1xBCVHqt3mTRHDh/b5/lF8 POOw== X-Gm-Message-State: ACrzQf3CoGc5H6OHgVlrYSb6DeAADEnMAAaaREvFaEdd0+yldxJPCb2K Ix8VOpb7ur3A/FOX9ab44yq4LhKBRtr9sw== X-Google-Smtp-Source: AMsMyM7GtzPMdQqnDhGty4zA26LWunT80i/mAE9LRABZ2u5IheQqvReT099mDwmt44LIPQgz43rSmw== X-Received: by 2002:a17:90b:180e:b0:202:a0c3:6da with SMTP id lw14-20020a17090b180e00b00202a0c306damr8971922pjb.94.1663934509044; Fri, 23 Sep 2022 05:01:49 -0700 (PDT) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id b5-20020a170902d50500b00176ca533ea0sm5908097plg.90.2022.09.23.05.01.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 05:01:47 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=kobarity@gmail.com; helo=mail-pj1-x1031.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:243461 Archived-At: --Multipart_Fri_Sep_23_21:01:20_2022-1 Content-Type: text/plain; charset=US-ASCII Hi, The following steps will place the point at the end of the class C, not the end of the method a. 1. emacs -Q 2. Load the following Python file using M-x find-file #+begin_src python class C: def a(self ): pass def b(self): pass #+end_src 3. C-n (M-x forward-line) 4. C-M-e (M-x end-of-defun) This happens when the method (nested function) has multi-line arguments. This is caused by the wrong behavior of `python-nav-beginning-of-defun'. When the point is inside of the parens of the nested function, it fails to detect the beginning of the nested function and moves the point to the beginning of the outer class/function. The root cause of this problem exists in `python-info-looking-at-beginning-of-defun'. It checks syntax context to detect correct keywords, but it checks at the current position although keywords are searched for at the beginning of the line. If the point is inside of the parens of the function definition, syntax context is "paren" and `python-info-looking-at-beginning-of-defun' returns nil, which is not expected. The syntax context should be checked after moving the point to the beginning of the line. Attached is a patch to fix this issue. Best Regards, -- In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2022-09-23 built on ubuntu Repository revision: 8238d87e15e2b2b730b6290965d14787650a15af Repository branch: master System Description: Ubuntu 22.04.1 LTS Configured using: 'configure --without-libgmp' Configured features: ACL CAIRO FREETYPE GIF GLIB GNUTLS GSETTINGS HARFBUZZ JPEG LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM LUCID ZLIB Important settings: value of $LANG: en_US.UTF-8 locale-coding-system: utf-8-unix Major mode: Lisp Interaction Minor modes in effect: tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t Load-path shadows: None found. Features: (shadow sort mail-extr emacsbug message mailcap yank-media puny dired dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util text-property-search time-date subr-x mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader cl-loaddefs cl-lib sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils term/screen term/xterm xterm byte-opt gv bytecomp byte-compile cconv rmc iso-transl tooltip eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic indonesian philippine cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european ethiopic indian cyrillic chinese composite emoji-zwj charscript charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs faces cus-face macroexp files window text-properties overlay sha1 md5 base64 format env code-pages mule custom widget keymap hashtable-print-readable backquote threads inotify dynamic-setting system-font-setting font-render-setting cairo x-toolkit x multi-tty make-network-process emacs) Memory information: ((conses 16 45893 5646) (symbols 48 5782 0) (strings 32 15032 1212) (string-bytes 1 425800) (vectors 16 8334) (vector-slots 8 104450 6830) (floats 8 24 229) (intervals 56 200 0) (buffers 1000 10)) --Multipart_Fri_Sep_23_21:01:20_2022-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-syntax-check-in-python-info-looking-at-beginning.patch" Content-Disposition: attachment; filename="0001-Fix-syntax-check-in-python-info-looking-at-beginning.patch" Content-Transfer-Encoding: 7bit >From f5ed0ff20639e344c4309b67f2279a3ac80f7529 Mon Sep 17 00:00:00 2001 From: kobarity Date: Fri, 23 Sep 2022 15:46:22 +0900 Subject: [PATCH] Fix syntax check in python-info-looking-at-beginning-of-defun * lisp/progmodes/python.el (python-info-looking-at-beginning-of-defun): Check syntax after moving to the beginning of line. * test/lisp/progmodes/python-tests.el (python-nav-beginning-of-defun-6) (python-end-of-defun-1, python-info-looking-at-beginning-of-defun-3): New tests. --- lisp/progmodes/python.el | 10 +++--- test/lisp/progmodes/python-tests.el | 48 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index d5ff059cc8..80c5b31b6e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5505,11 +5505,11 @@ python-info-looking-at-beginning-of-defun "Check if point is at `beginning-of-defun' using SYNTAX-PPSS. When CHECK-STATEMENT is non-nil, the current statement is checked instead of the current physical line." - (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss)))) - (save-excursion - (when check-statement - (python-nav-beginning-of-statement)) - (beginning-of-line 1) + (save-excursion + (when check-statement + (python-nav-beginning-of-statement)) + (beginning-of-line 1) + (and (not (python-syntax-context-type (or syntax-ppss (syntax-ppss)))) (looking-at python-nav-beginning-of-defun-regexp)))) (defun python-info-looking-at-beginning-of-block () diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 20a7a0132a..fdaedb5fd7 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -2342,6 +2342,21 @@ python-nav-beginning-of-defun-5 (beginning-of-line) (point)))))) +(ert-deftest python-nav-beginning-of-defun-6 () + (python-tests-with-temp-buffer + " +class C: + def foo(self): + pass +" + (python-tests-look-at "self") + (should (= (save-excursion + (python-nav-beginning-of-defun) + (point)) + (save-excursion + (beginning-of-line) + (point)))))) + (ert-deftest python-nav-end-of-defun-1 () (python-tests-with-temp-buffer " @@ -2472,6 +2487,26 @@ python-nav-end-of-defun-3 (save-excursion (point-max)))))) +(ert-deftest python-end-of-defun-1 () + (python-tests-with-temp-buffer + " +class C: + def a(self + ): + pass + + def b(self): + pass +" + (should (= (save-excursion + (python-tests-look-at "def a") + (end-of-defun) + (point)) + (save-excursion + (python-tests-look-at "def b") + (forward-line -1) + (point)))))) + (ert-deftest python-nav-backward-defun-1 () (python-tests-with-temp-buffer " @@ -5734,6 +5769,19 @@ python-info-looking-at-beginning-of-defun-2 (should (not (python-info-looking-at-beginning-of-defun))) (should (not (python-info-looking-at-beginning-of-defun nil t))))) +(ert-deftest python-info-looking-at-beginning-of-defun-3 () + (python-tests-with-temp-buffer + " +def foo(arg=\"default\"): # Comment + pass +" + (python-tests-look-at "arg") + (should (python-info-looking-at-beginning-of-defun)) + (python-tests-look-at "default") + (should (python-info-looking-at-beginning-of-defun)) + (python-tests-look-at "Comment") + (should (python-info-looking-at-beginning-of-defun)))) + (ert-deftest python-info-looking-at-beginning-of-block-1 () (python-tests-with-temp-buffer " -- 2.34.1 --Multipart_Fri_Sep_23_21:01:20_2022-1--