unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement
@ 2013-02-06 23:50 Jorgen Schaefer
  2013-02-07  0:12 ` Daniel Colascione
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jorgen Schaefer @ 2013-02-06 23:50 UTC (permalink / raw)
  To: 13642

Hello!
In python-mode, I get the following behavior (with _|_ being point):

-----
def foo():
    bar = "bar"
    baz = "baz"_|_

=>

_|_def foo():
    bar = "bar"
    baz = "baz"
-----

I would have expected point to move to the beginning of the string, not
to the beginning of def.

I also get this:

-----
def foo():
    bar = "bar"_|_
    baz = "baz"

=>

def foo():
    _|_bar = "bar"
    baz = "baz"
-----

Again, I would have expected point to end up in front of the string, not
the beginning of the statement.

python-mode sets forward-sexp-function, so these operations are done
when using C-M-b (and C-M-f), which is very counterintuitive to me.

Regards,
        -- Jorgen





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

* bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement
  2013-02-06 23:50 bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement Jorgen Schaefer
@ 2013-02-07  0:12 ` Daniel Colascione
  2013-02-08 21:27   ` Jorgen Schaefer
  2013-05-15  5:55   ` Andreas Röhler
  2013-02-14  0:31 ` bug#13642: (no subject) Fabián Ezequiel Gallina
  2013-02-14  0:47 ` Fabián Ezequiel Gallina
  2 siblings, 2 replies; 6+ messages in thread
From: Daniel Colascione @ 2013-02-07  0:12 UTC (permalink / raw)
  To: Jorgen Schaefer; +Cc: 13642

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

On 2/6/2013 3:50 PM, Jorgen Schaefer wrote:
> Hello!
> In python-mode, I get the following behavior (with _|_ being point):
> 
> -----
> def foo():
>     bar = "bar"
>     baz = "baz"_|_
> 
> =>
> 
> _|_def foo():
>     bar = "bar"
>     baz = "baz"
> -----

That's by design. python-mode tries to emulate lisp movement as much as
possible, so it considers point to be at the end of a "defun" and tries to skip
over the entire "defun", back to the beginning.

This functionality appears to be buggy:

def foo():
    bar = "bar"
    baz = "baz"
    x=x()_|_

=>

def foo():
    bar = "bar"
    baz = "baz"
    x=x_|_()

I also find the behavior more counter-intuitive than useful, and I wish
python-mode acted more like cc-mode here.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 260 bytes --]

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

* bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement
  2013-02-07  0:12 ` Daniel Colascione
@ 2013-02-08 21:27   ` Jorgen Schaefer
  2013-05-15  5:55   ` Andreas Röhler
  1 sibling, 0 replies; 6+ messages in thread
From: Jorgen Schaefer @ 2013-02-08 21:27 UTC (permalink / raw)
  To: Daniel Colascione; +Cc: 13642

On Wed, 06 Feb 2013 16:12:43 -0800
Daniel Colascione <dancol@dancol.org> wrote:

> On 2/6/2013 3:50 PM, Jorgen Schaefer wrote:
> > Hello!
> > In python-mode, I get the following behavior (with _|_ being point):
> > 
> > -----
> > def foo():
> >     bar = "bar"
> >     baz = "baz"_|_
> > 
> > =>
> > 
> > _|_def foo():
> >     bar = "bar"
> >     baz = "baz"
> > -----
> 
> That's by design. python-mode tries to emulate lisp movement as much
> as possible, so it considers point to be at the end of a "defun" and
> tries to skip over the entire "defun", back to the beginning.

It would seem that it would make sense to assume the point is at the
end of the block only if it's *past* the last line of the block, not
while it's still on it.

> I also find the behavior more counter-intuitive than useful, and I
> wish python-mode acted more like cc-mode here.

cc-mode simply leaves `forward-sexp-function' nil. Setting that to nil
in python-mode-hook makes python-mode behave "intuitively" for me
again. I have no idea under which circumstances this is useful. There's
C-M-a to go to the beginning of a defun if I want to, and python.el
could bind python-nav-backward/forward-statement to M-a and M-e which
would make a lot of sense.

The current behavior is just ... weird.

Who is the person to decide that this should change? :-)

Regards,
	-- Jorgen





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

* bug#13642: (no subject)
  2013-02-06 23:50 bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement Jorgen Schaefer
  2013-02-07  0:12 ` Daniel Colascione
@ 2013-02-14  0:31 ` Fabián Ezequiel Gallina
  2013-02-14  0:47 ` Fabián Ezequiel Gallina
  2 siblings, 0 replies; 6+ messages in thread
From: Fabián Ezequiel Gallina @ 2013-02-14  0:31 UTC (permalink / raw)
  To: 13642

The current behavior follows pretty much what emacs-lisp-mode does for 
lisp movement, so I won't agree calling it weird, It's just a matter of 
taste. If setting the `forward-sexp-function' to nil fits your needs 
then feel free to do so. I'll add documentation in the header explaining 
how to disable such behavior.

The paren thing at end of defun Daniel found is a known cornercase, 
which unfortunately I can't fix because `blink-matching-open' needs 
`python-nav-forward-sexp' to behave this way to work correctly.

Also notice this is not a whimsical feature, it was in fact a feature 
request[0] by another user. And I honestly find it pretty cool overall.


[0] https://github.com/fgallina/python.el/issues/106



Regards,
Fabián.





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

* bug#13642: (no subject)
  2013-02-06 23:50 bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement Jorgen Schaefer
  2013-02-07  0:12 ` Daniel Colascione
  2013-02-14  0:31 ` bug#13642: (no subject) Fabián Ezequiel Gallina
@ 2013-02-14  0:47 ` Fabián Ezequiel Gallina
  2 siblings, 0 replies; 6+ messages in thread
From: Fabián Ezequiel Gallina @ 2013-02-14  0:47 UTC (permalink / raw)
  To: 13642

I added documentation how to disable this behavior in the header.

I also changed the behavior when inside strings/comments to follow the 
emacs-lisp-mode behavior.

All this in revno 111261.


Regards,
Fabián.





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

* bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement
  2013-02-07  0:12 ` Daniel Colascione
  2013-02-08 21:27   ` Jorgen Schaefer
@ 2013-05-15  5:55   ` Andreas Röhler
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Röhler @ 2013-05-15  5:55 UTC (permalink / raw)
  To: 13642

Am 07.02.2013 01:12, schrieb Daniel Colascione:
> On 2/6/2013 3:50 PM, Jorgen Schaefer wrote:
>> Hello!
>> In python-mode, I get the following behavior (with _|_ being point):
>>
>> -----
>> def foo():
>>      bar = "bar"
>>      baz = "baz"_|_
>>
>> =>
>>
>> _|_def foo():
>>      bar = "bar"
>>      baz = "baz"
>> -----
>
> That's by design. python-mode tries to emulate lisp movement as much as
> possible, so it considers point to be at the end of a "defun" and tries to skip
> over the entire "defun", back to the beginning.
>
> This functionality appears to be buggy:
>
> def foo():
>      bar = "bar"
>      baz = "baz"
>      x=x()_|_
>
> =>
>
> def foo():
>      bar = "bar"
>      baz = "baz"
>      x=x_|_()
>
> I also find the behavior more counter-intuitive than useful, and I wish
> python-mode acted more like cc-mode here.
>


[ ... ]

hmm, din't think so. In Python that point indicates the end of assignment
baz = "baz"

End of defun is reached with following dedent only.

So the OP's expection seems wrong too:

backward-sexp must reach the beginning of the assigment "baz =..."

BTW in python-mode.el we have py-beginning-of-expression for the OP's want.

Cheers,

Andreas







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

end of thread, other threads:[~2013-05-15  5:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-06 23:50 bug#13642: 24.3.50; python-nav-backward-sexp mishandles string movement Jorgen Schaefer
2013-02-07  0:12 ` Daniel Colascione
2013-02-08 21:27   ` Jorgen Schaefer
2013-05-15  5:55   ` Andreas Röhler
2013-02-14  0:31 ` bug#13642: (no subject) Fabián Ezequiel Gallina
2013-02-14  0:47 ` 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).