unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement
@ 2015-01-23 16:12 Carlos Pita
  2015-01-23 21:17 ` bug#19665: Carlos Pita
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Carlos Pita @ 2015-01-23 16:12 UTC (permalink / raw)
  To: 19665; +Cc: Fabian Ezequiel Gallina

Specifically, try the example below:

```
class A: pass


class B:

    def __init__(self): pass

    def fun(self): pass

class C: pass
```

1) If point is in the line immediately after "class B:", then C-M-h will
select the entire class B definition, as expected.

2) If point is in the line "class B:", then C-M-h will select just the
definition of the fun method, which is entirely unexpected!

Cheers
--
Carlos





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#19665:
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
@ 2015-01-23 21:17 ` Carlos Pita
  2015-02-02 19:33 ` bug#19665: Carlos Pita
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Carlos Pita @ 2015-01-23 21:17 UTC (permalink / raw)
  To: 19665

It seems to me that the problem is in python-nav--beginning-of-defun.
Specifically there is (< arg 0) guard that is testing the wrong case
(end-of-line should be called for the backwards case, not the forward
one):

        (found
           (progn
-            (when (and (< arg 0)
+            (when (and (> arg 0)
                        (python-info-looking-at-beginning-of-defun))
               (end-of-line 1))
             (while (and (funcall re-search-fn





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#19665:
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
  2015-01-23 21:17 ` bug#19665: Carlos Pita
@ 2015-02-02 19:33 ` Carlos Pita
  2015-02-09 16:46 ` bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Carlos Pita @ 2015-02-02 19:33 UTC (permalink / raw)
  To: 19665; +Cc: Fabian Ezequiel Gallina

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

Patch updated against current master (954ca0f017f62f52ee679f2aa68effb20c917278).

[-- Attachment #2: mark-defun.patch --]
[-- Type: text/x-patch, Size: 839 bytes --]

From 2f1cfe4b410d5d61a2230dbd5002a0824c908285 Mon Sep 17 00:00:00 2001
From: memeplex <carlosjosepita@gmail.com>
Date: Fri, 23 Jan 2015 18:01:32 -0300
Subject: [PATCH] python.el: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19665

---
 .emacs.d/lisp/python.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.emacs.d/lisp/python.el b/.emacs.d/lisp/python.el
index 30b62f5..500ced8 100644
--- a/.emacs.d/lisp/python.el
+++ b/.emacs.d/lisp/python.el
@@ -1285,7 +1285,7 @@ With positive ARG search backwards, else search forwards."
                      0))))
          (found
           (progn
-            (when (and (< arg 0)
+            (when (and (> arg 0)
                        (python-info-looking-at-beginning-of-defun))
               (end-of-line 1))
             (while (and (funcall re-search-fn
-- 
2.2.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
  2015-01-23 21:17 ` bug#19665: Carlos Pita
  2015-02-02 19:33 ` bug#19665: Carlos Pita
@ 2015-02-09 16:46 ` Carlos Pita
  2015-02-09 17:36 ` Carlos Pita
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Carlos Pita @ 2015-02-09 16:46 UTC (permalink / raw)
  To: 19665

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

Updated patch, see detailed discussion in

http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19748



On Fri, Jan 23, 2015 at 1:13 PM, GNU bug Tracking System
<help-debbugs@gnu.org> wrote:
> Thank you for filing a new bug report with debbugs.gnu.org.
>
> This is an automatically generated reply to let you know your message
> has been received.
>
> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.
>
> Your message has been sent to the package maintainer(s):
>  bug-gnu-emacs@gnu.org
>
> If you wish to submit further information on this problem, please
> send it to 19665@debbugs.gnu.org.
>
> Please do not send mail to help-debbugs@gnu.org unless you wish
> to report a problem with the Bug-tracking system.
>
> --
> 19665: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=19665
> GNU Bug Tracking System
> Contact help-debbugs@gnu.org with problems

[-- Attachment #2: mark-defun.patch --]
[-- Type: text/x-patch, Size: 1260 bytes --]

diff --git a/.emacs.d/lisp/python.el b/.emacs.d/lisp/python.el
index 30b62f5..0337a17 100644
--- a/.emacs.d/lisp/python.el
+++ b/.emacs.d/lisp/python.el
@@ -284,6 +284,7 @@
     (define-key map [remap backward-sentence] 'python-nav-backward-block)
     (define-key map [remap forward-sentence] 'python-nav-forward-block)
     (define-key map [remap backward-up-list] 'python-nav-backward-up-list)
+    (define-key map [remap mark-defun] 'python-mark-defun)
     (define-key map "\C-c\C-j" 'imenu)
     ;; Indent specific
     (define-key map "\177" 'python-indent-dedent-line-backspace)
@@ -1285,7 +1286,7 @@ With positive ARG search backwards, else search forwards."
                      0))))
          (found
           (progn
-            (when (and (< arg 0)
+            (when (and (> arg 0)
                        (python-info-looking-at-beginning-of-defun))
               (end-of-line 1))
             (while (and (funcall re-search-fn
@@ -4460,6 +4461,12 @@ default to utf-8."
 \f
 ;;; Utility functions
 
+(defun python-mark-defun ()
+  (interactive)
+  (when (python-info-looking-at-beginning-of-defun)
+    (end-of-line 1))
+  (mark-defun))
+
 (defun python-util-goto-line (line-number)
   "Move point to LINE-NUMBER."
   (goto-char (point-min))

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
                   ` (2 preceding siblings ...)
  2015-02-09 16:46 ` bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
@ 2015-02-09 17:36 ` Carlos Pita
  2015-02-11 15:52 ` Carlos Pita
  2015-07-06  4:05 ` Fabián Ezequiel Gallina
  5 siblings, 0 replies; 7+ messages in thread
From: Carlos Pita @ 2015-02-09 17:36 UTC (permalink / raw)
  To: 19665

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

Here is a variation of the last patch that behaves better when the
point is in empty lines above a defun.

Another entirely different approach to solve this issue without
redefining mark-defun could be to differentiate:

class M:
     def m():
          pass*

and

class M:
   def m():
      pass
*

(where * stands for the point)

In the second case, C-M-h will select the class, while in the first it
will select the method. Then, there would be no need to hack
mark-defun.

What do you think?

[-- Attachment #2: mark-defun.patch --]
[-- Type: text/x-patch, Size: 1260 bytes --]

diff --git a/.emacs.d/lisp/python.el b/.emacs.d/lisp/python.el
index 30b62f5..0337a17 100644
--- a/.emacs.d/lisp/python.el
+++ b/.emacs.d/lisp/python.el
@@ -284,6 +284,7 @@
     (define-key map [remap backward-sentence] 'python-nav-backward-block)
     (define-key map [remap forward-sentence] 'python-nav-forward-block)
     (define-key map [remap backward-up-list] 'python-nav-backward-up-list)
+    (define-key map [remap mark-defun] 'python-mark-defun)
     (define-key map "\C-c\C-j" 'imenu)
     ;; Indent specific
     (define-key map "\177" 'python-indent-dedent-line-backspace)
@@ -1285,7 +1286,7 @@ With positive ARG search backwards, else search forwards."
                      0))))
          (found
           (progn
-            (when (and (< arg 0)
+            (when (and (> arg 0)
                        (python-info-looking-at-beginning-of-defun))
               (end-of-line 1))
             (while (and (funcall re-search-fn
@@ -4460,6 +4461,12 @@ default to utf-8."
 \f
 ;;; Utility functions
 
+(defun python-mark-defun ()
+  (interactive)
+  (when (python-info-looking-at-beginning-of-defun)
+    (end-of-line 1))
+  (mark-defun))
+
 (defun python-util-goto-line (line-number)
   "Move point to LINE-NUMBER."
   (goto-char (point-min))

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
                   ` (3 preceding siblings ...)
  2015-02-09 17:36 ` Carlos Pita
@ 2015-02-11 15:52 ` Carlos Pita
  2015-07-06  4:05 ` Fabián Ezequiel Gallina
  5 siblings, 0 replies; 7+ messages in thread
From: Carlos Pita @ 2015-02-11 15:52 UTC (permalink / raw)
  To: 19665

Sorry I mistakenly posted the same patch twice. The "when the point is
in empty lines above a defun" concern is addressed by defining
python-mark-defun as follows:

(defun python-mark-defun ()
  (interactive)
  (unless (eq last-command this-command)
    (skip-chars-forward " \t\n")
    (when (python-info-looking-at-beginning-of-defun)
      (end-of-line 1)))
  (mark-defun 1))

Cheers
--
Carlos





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement
  2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
                   ` (4 preceding siblings ...)
  2015-02-11 15:52 ` Carlos Pita
@ 2015-07-06  4:05 ` Fabián Ezequiel Gallina
  5 siblings, 0 replies; 7+ messages in thread
From: Fabián Ezequiel Gallina @ 2015-07-06  4:05 UTC (permalink / raw)
  To: 19665-done


Fix pushed at a5e39bf in master.

--
Thanks,
Fabián.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-07-06  4:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23 16:12 bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
2015-01-23 21:17 ` bug#19665: Carlos Pita
2015-02-02 19:33 ` bug#19665: Carlos Pita
2015-02-09 16:46 ` bug#19665: 25.0.50; python.el: mark defun bug when point is in class statement Carlos Pita
2015-02-09 17:36 ` Carlos Pita
2015-02-11 15:52 ` Carlos Pita
2015-07-06  4:05 ` Fabián Ezequiel Gallina

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).