GNU bug report logs - #19748
python.el: navigate to beginning of defun gets stucked

Previous Next

Package: emacs;

Reported by: Carlos Pita <carlosjosepita <at> gmail.com>

Date: Mon, 2 Feb 2015 21:31:01 UTC

Severity: normal

Tags: notabug, patch

Merged with 19665

Fixed in version 25.0.50

Done: fgallina <at> gnu.org (Fabián Ezequiel Gallina)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19748 in the body.
You can then email your comments to 19748 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#19748; Package emacs. (Mon, 02 Feb 2015 21:31:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Carlos Pita <carlosjosepita <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 02 Feb 2015 21:31:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Carlos Pita <carlosjosepita <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Cc: galli.87 <at> gmail.com
Subject: python.el: navigate to beginning of defun gets stucked
Date: Mon, 02 Feb 2015 18:29:39 -0300
[Message part 1 (text/plain, inline)]
This report is for python.el in the current master
(c10828bd8520db83cc06a2ad5de6f8a1ad74b83c).

Pressing C-M-a one time correctly positions the point at the beginning
of the current class or defun statement. Pressing C-M-a multiple times
is futile, as the point gets stucked where the first movement left
it. This is not consistent with the usual emacs behavior and it's not
very convenient to navigate code anyway.

The problem is in python-nav--beginning-of-defun:

            (when (and (> arg 0)
                       (python-info-looking-at-beginning-of-defun))
              (end-of-line 1))

This puts the point at the end of the line when the point is at a defun
or class line and the navigation is backward. So the next
re-search-backward will match the current line. This is fine when the
point is *after* the column where the defun or class statement starts,
but not quite so when the point is *over the indentation* whitespace
(that is, before the beginning of the defun/class keyword).

One simple solution is to add another condition:

            (when (and (> arg 0)
                       (> (current-column) (current-indentation))
                       (python-info-looking-at-beginning-of-defun))
              (end-of-line 1))

[beg-defun.patch (text/x-diff, inline)]
diff --git a/.emacs.d/lisp/python.el b/.emacs.d/lisp/python.el
index 788d09f..ca69b68 100644
--- a/.emacs.d/lisp/python.el
+++ b/.emacs.d/lisp/python.el
@@ -1295,6 +1295,7 @@ With positive ARG search backwards, else search forwards."
          (found
           (progn
             (when (and (> arg 0)
+                       (> (current-column) (current-indentation))
                        (python-info-looking-at-beginning-of-defun))
               (end-of-line 1))
             (while (and (funcall re-search-fn

Added tag(s) patch. Request was from Carlos Pita <carlosjosepita <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 02 Feb 2015 21:37:02 GMT) Full text and rfc822 format available.

Added tag(s) notabug. Request was from fgallina <at> gnu.org (Fabián Ezequiel Gallina) to control <at> debbugs.gnu.org. (Sat, 07 Feb 2015 21:53:02 GMT) Full text and rfc822 format available.

Reply sent to fgallina <at> gnu.org (Fabián Ezequiel Gallina):
You have taken responsibility. (Sat, 07 Feb 2015 21:54:01 GMT) Full text and rfc822 format available.

Notification sent to Carlos Pita <carlosjosepita <at> gmail.com>:
bug acknowledged by developer. (Sat, 07 Feb 2015 21:54:02 GMT) Full text and rfc822 format available.

Message #14 received at 19748-done <at> debbugs.gnu.org (full text, mbox):

From: fgallina <at> gnu.org (Fabián Ezequiel Gallina)
To: 19748-done <at> debbugs.gnu.org
Subject: python.el: navigate to beginning of defun gets stucked
Date: Sat, 07 Feb 2015 18:53:51 -0300
This doesn't happen with master's python.el.

The regression you are experiencing seems to be happening because you
are working on a patched python.el version that includes the change you
proposed in http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19665


Cheers,
Fabián.




Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 09 Feb 2015 14:22:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19748; Package emacs. (Mon, 09 Feb 2015 16:46:02 GMT) Full text and rfc822 format available.

Message #19 received at 19748 <at> debbugs.gnu.org (full text, mbox):

From: Carlos Pita <carlosjosepita <at> gmail.com>
To: 19748 <at> debbugs.gnu.org
Date: Mon, 9 Feb 2015 13:45:17 -0300
Sorry for reopening this, Fabián. You're right in pointing that this
bug was introduced by my fix to 19665. But AFAICS 19665 is indeed a
bug: you want to go to the end of the defun line when the search is
backward, in order to match arg defun including the current one.

There is a more difficult problem here. Say * is the point:

1) You want C-M-a to move the point from def* to *def.

2) You want C-M-a to mode the point from *def to the previous definition.

(1) is addressed by 19665.
(2) is addressed by this report.

Still, there is:

3) You want C-M-h both in def* and in *def to select the current
defun. 19665 was intended to correct both cases (*def and def*), but
my patch here breaks again the case *def (because for *def the
selection reverts now to the pathological behavior described in 19665,
just because of the additional condition in the guard, which should be
kept anyway because of (2)).

Note: I'm checking my assertions 1, 2 and 3 against the standard
behavior of elisp mode, which I take as a reference. That's indeed the
behavior there.

More briefly: for C-M-a you want to distinguish between def* and *def,
but for C-M-h you don't. The previous fix here and 19665 correctly
address (1) and (2), and mostly address (3) except for the corner case
*class, which I address in what follows.

Looking at the definition of mark-defun one could clearly see what the
problem is. Starting from *class, say, mark-defun will mark the
previous defun and then check (if (> (point) opoint) to see that the
selected defun was not the desired one. So it goes through the else
part sending the point to the end of the class block and then moving
backward one defun to select just the last method. I think we could
fix this tweaking a bit the behavior of mark-defun, but -unusually-
mark-defun allows for no local extension points. A simple advice could
do the trick but I don't feel like adding an advice just for python
sake to a globally and often used function. The last option I'm able
figure out is to replace mark-defun in the python keymap. This is not
perfect, as mark-defun could be used programatically also, but I
believe it's good enough:

(define-key map [remap mark-defun] 'python-mark-defun)

(defun python-mark-defun ()
  (interactive)
  (when (python-info-looking-at-
beginning-of-defun)
    (end-of-line 1))
  (mark-defun))

Besides that, I want to emphazise that you still need:

-            (when (and (< arg 0)
+            (when (and (> arg 0)

and

+                       (> (current-column) (current-indentation))


Also, you may want to set allow-extend for mark-defun.

I will post a patch to 19665 including the original change and the
mark-defun fix.

The  (> (current-column) (current-indentation)) fix in this report
remains valid except you worked out a cleaner solution for 1, 2 and 3
above.




Merged 19665 19748. Request was from fgallina <at> gnu.org (Fabián Ezequiel Gallina) to control <at> debbugs.gnu.org. (Thu, 09 Apr 2015 04:08:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 03 Aug 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 323 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.