From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.bugs Subject: bug#40563: 28.0.50; Narrow to defun in python buffer Date: Sun, 13 Dec 2020 14:32:38 +0100 Message-ID: <87y2i1x24p.fsf@posteo.net> References: <87sgh9my8y.fsf@fliptop.i-did-not-set--mail-host-address--so-tickle-me> <87pn55145g.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3324"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 40563@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 13 14:33:27 2020 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 1koRV9-0000kx-22 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 14:33:27 +0100 Original-Received: from localhost ([::1]:38308 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koRV8-00076A-2z for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 13 Dec 2020 08:33:26 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koRUk-00075j-HS for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 08:33:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36217) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koRUk-0000we-9c for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 08:33:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1koRUk-0000Y0-6U for bug-gnu-emacs@gnu.org; Sun, 13 Dec 2020 08:33:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tomas Nordin Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Dec 2020 13:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40563 X-GNU-PR-Package: emacs Original-Received: via spool by 40563-submit@debbugs.gnu.org id=B40563.16078663682057 (code B ref 40563); Sun, 13 Dec 2020 13:33:02 +0000 Original-Received: (at 40563) by debbugs.gnu.org; 13 Dec 2020 13:32:48 +0000 Original-Received: from localhost ([127.0.0.1]:47763 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koRUW-0000X3-Dq for submit@debbugs.gnu.org; Sun, 13 Dec 2020 08:32:48 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:48421) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koRUT-0000Wb-RE for 40563@debbugs.gnu.org; Sun, 13 Dec 2020 08:32:46 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout02.posteo.de (Postfix) with ESMTPS id 1744F2400FE for <40563@debbugs.gnu.org>; Sun, 13 Dec 2020 14:32:40 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1607866360; bh=pNoipxsZ3d4ni8tg/luHVjE8WLyU1KdABuRAqky6mZM=; h=From:To:Cc:Subject:Date:From; b=EipC9DmfWuXFxkzvTjpdu6XEFz6tjLx9aHIcig7CUFVAGoDXwQyD3SPkNa8II2rk2 dh51qRsEBPjyrE8Nrtlov4xZZpfM+H5wu4+VfUU1XcFd2fAWSurU8qYX/pzNcc16T3 eZSPnX/S78CiAVC4KqJADEPov3Yav1zub30lgcHX43pEO7sB8KLx47eXwM5e0+vBqt 9TeuG8YEX6WY4F/rVjxylTob8O4VB0DZbozwWLpVKeA9uTmm/4j0upQXdgeqU2P5z7 1Apqbt2VfhwCb6RwCQslULwtSfTSn93D+zTBS1A7Kr/cqkoAe/2emxlmFhfB2HD8vm k/tSgUR0NeWuQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Cv56v4Z7fz6tmX; Sun, 13 Dec 2020 14:32:39 +0100 (CET) In-Reply-To: <87pn55145g.fsf@gnus.org> 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:195959 Archived-At: --=-=-= Content-Type: text/plain Hello Lars Ingebrigtsen writes: > Tomas Nordin writes: > >> I then noticed that placing point just below the class definition and >> then narrow works as expected. But I think the recipe way should work as >> well. And even if not, this behavior is confusing. > > This bug is still present on the trunk. > > The problem is most easily reproduced by calling the > > (python-nav--beginning-of-defun) > > function directly. If point is on the first line, then this function > won't do the right thing: > > def a1(self): > pass Attached is a patch that fix the problems described in this report. The change of variable name 'beg-indentation' to 'body-indentation' is not part of the fix, but something I did during study making it easier for me to understand the meaning of it. Feel free to disagree on that change. The naming beg-indentation does not re-occur in python.el The patch mean to say it might be necessary to move forward on the line before search if point start off at the beginning of the defun, to allow re-search-backward to succeed on the intended place. The patch fixes this report, but it doesn't allow narrowing nested python defuns (like a def in a class). For that I think it is necassary to look at narrow-to-defun. I intend to suggest something about that in another report. What do you think? Best regards -- Tomas --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=beginning-of-defun.patch diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index e9c3b3986a..32ffc5a9d6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1404,7 +1404,7 @@ python-nav--beginning-of-defun (line-beg-pos (line-beginning-position)) (line-content-start (+ line-beg-pos (current-indentation))) (pos (point-marker)) - (beg-indentation + (body-indentation (and (> arg 0) (save-excursion (while (and @@ -1415,9 +1415,16 @@ python-nav--beginning-of-defun 0)))) (found (progn - (when (and (< arg 0) - (python-info-looking-at-beginning-of-defun)) + (when (and (python-info-looking-at-beginning-of-defun) + (or (< arg 0) + ;; If looking at beginning of defun, and if + ;; pos is > line-content-start, ensure a + ;; backward re search match this defun by + ;; going to end of line before calling + ;; re-search-fn bug#40563 + (and (> arg 0) (> pos line-content-start)))) (end-of-line 1)) + (while (and (funcall re-search-fn python-nav-beginning-of-defun-regexp nil t) (or (python-syntax-context-type) @@ -1425,7 +1432,7 @@ python-nav--beginning-of-defun ;; backwards by checking indentation. (and (> arg 0) (not (= (current-indentation) 0)) - (>= (current-indentation) beg-indentation))))) + (>= (current-indentation) body-indentation))))) (and (python-info-looking-at-beginning-of-defun) (or (not (= (line-number-at-pos pos) (line-number-at-pos))) --=-=-=--