all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tomas Nordin <tomasn@posteo.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 40563@debbugs.gnu.org
Subject: bug#40563: 28.0.50; Narrow to defun in python buffer
Date: Sun, 13 Dec 2020 14:32:38 +0100	[thread overview]
Message-ID: <87y2i1x24p.fsf@posteo.net> (raw)
In-Reply-To: <87pn55145g.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

Hello

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Tomas Nordin <tomasn@posteo.net> 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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: beginning-of-defun.patch --]
[-- Type: text/x-diff, Size: 2024 bytes --]

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)))

  parent reply	other threads:[~2020-12-13 13:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 22:52 bug#40563: 28.0.50; Narrow to defun in python buffer Tomas Nordin
2020-10-26 13:57 ` Lars Ingebrigtsen
2020-12-01 21:01   ` Tomas Nordin
2020-12-01 21:05     ` Tomas Nordin
2020-12-04  7:48       ` Andreas Röhler
2020-12-13 13:32   ` Tomas Nordin [this message]
2020-12-14 16:00     ` Lars Ingebrigtsen
2020-12-14 19:38       ` Tomas Nordin
2020-12-14 20:03         ` Lars Ingebrigtsen
2020-12-14 22:18           ` Tomas Nordin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y2i1x24p.fsf@posteo.net \
    --to=tomasn@posteo.net \
    --cc=40563@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.