unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#29608: python.el movement functions
@ 2017-12-07 21:08 Alex Branham
  2017-12-08 17:56 ` Glenn Morris
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Branham @ 2017-12-07 21:08 UTC (permalink / raw)
  To: 29608

Python movement statements do not always result in the behavior I'd expect. Consider this python file (with (|) representing point):

(|)for i in [1, 2, 3]:
    print(i)

I'd expect M-x python-nav-forward-statement to result in

for i in [1, 2, 3]:
    print(i)
(|)

but instead you wind up with

for i in [1, 2, 3]:
    (|)print(i)

and python-nav-forward-block (bound to M-e) is even worse. It results in point not moving at all:

(|)for i in [1, 2, 3]:
    print(i)





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

* bug#29608: python.el movement functions
  2017-12-07 21:08 bug#29608: python.el movement functions Alex Branham
@ 2017-12-08 17:56 ` Glenn Morris
  2017-12-08 21:37   ` Alex Branham
  0 siblings, 1 reply; 4+ messages in thread
From: Glenn Morris @ 2017-12-08 17:56 UTC (permalink / raw)
  To: Alex Branham; +Cc: 29608

Alex Branham wrote:

> Python movement statements do not always result in the behavior I'd
> expect. Consider this python file (with (|) representing point):
>
> (|)for i in [1, 2, 3]:
>     print(i)
>
> I'd expect M-x python-nav-forward-statement to result in
>
> for i in [1, 2, 3]:
>     print(i)
> (|)
>
> but instead you wind up with
>
> for i in [1, 2, 3]:
>     (|)print(i)

The actual result seems reasonable to me?

> and python-nav-forward-block (bound to M-e) is even worse. It results
> in point not moving at all:
>
> (|)for i in [1, 2, 3]:
>     print(i)

It seems that you disagree with python.el's definition of "statement" and
"block". Eg the block definition seems to be:

(defconst python-rx-constituents
  `((block-start          . ,(rx symbol-start
                                 (or "def" "class" "if" "elif" "else" "try"
                                     "except" "finally" "for" "while" "with"
                                     ;; Python 3.5+ PEP492
                                     (and "async" (+ space)
                                          (or "def" "for" "with")))
                                 symbol-end))






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

* bug#29608: python.el movement functions
  2017-12-08 17:56 ` Glenn Morris
@ 2017-12-08 21:37   ` Alex Branham
  2021-06-26 14:13     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Alex Branham @ 2017-12-08 21:37 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 29608


On Fri 08 Dec 2017 at 17:56, Glenn Morris <rgm@gnu.org> wrote:

> Alex Branham wrote:
>
>> Python movement statements do not always result in the behavior I'd
>> expect. Consider this python file (with (|) representing point):
>>
>> (|)for i in [1, 2, 3]:
>>     print(i)
>>
>> I'd expect M-x python-nav-forward-statement to result in
>>
>> for i in [1, 2, 3]:
>>     print(i)
>> (|)
>>
>> but instead you wind up with
>>
>> for i in [1, 2, 3]:
>>     (|)print(i)
>
> The actual result seems reasonable to me?

I'd argue that a "statement" should contain a whole logically valid statement, but I see your point.

>
>> and python-nav-forward-block (bound to M-e) is even worse. It results
>> in point not moving at all:
>>
>> (|)for i in [1, 2, 3]:
>>     print(i)
>
> It seems that you disagree with python.el's definition of "statement" and
> "block". Eg the block definition seems to be:
>
> (defconst python-rx-constituents
>   `((block-start          . ,(rx symbol-start
>                                  (or "def" "class" "if" "elif" "else" "try"
>                                      "except" "finally" "for" "while" "with"
>                                      ;; Python 3.5+ PEP492
>                                      (and "async" (+ space)
>                                           (or "def" "for" "with")))
>                                  symbol-end))

Shouldn't python-nav-forward-block actually navigate forward, though?
And if we're on the last block in the buffer, just leave point at the
end?

This might be off-topic, but what I'm trying to do is to write a function that I can bind so that C-<return> acts like it does in ESS where you can continue to hit it and it will eventually evaluate everything in the buffer. Here's what I have so far:

(defun python-shell-send-region-or-statement ()
  "Send the current region to the inferior python process if there is an active one, otherwise the current line."
  (interactive)
  (if (use-region-p)
      (python-shell-send-region (region-beginning) (region-end))
    (python-shell-send-statement)))

(defun python-shell-send-statement ()
  "Send the current line to the inferior python process for evaluation."
  (interactive)
  (save-excursion
    (let ((end (python-nav-end-of-statement))
          (beginning (python-nav-beginning-of-statement)))
      (python-shell-send-region beginning end))))

(defun python-shell-send-region-or-statement-and-step ()
  "Call `python-shell-send-region-or-statement' and then `python-nav-forward-statement'."
  (interactive)
  (python-shell-send-region-or-statement)
  (python-nav-forward-statement))









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

* bug#29608: python.el movement functions
  2017-12-08 21:37   ` Alex Branham
@ 2021-06-26 14:13     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-26 14:13 UTC (permalink / raw)
  To: Alex Branham; +Cc: Glenn Morris, 29608

Alex Branham <alex.branham@gmail.com> writes:

> Shouldn't python-nav-forward-block actually navigate forward, though?
> And if we're on the last block in the buffer, just leave point at the
> end?

Well, the `M-e' doc string says "Move forward to next block of code.",
so if there is no next code block, then there's nothing to move to.  So
I think it's working as intended, I guess?  It does seem slightly
eccentric -- I'd also expect it to move to the end of the current block,
but then there's `python-nav-end-of-block' for that.

But I don't think there's anything to fix here, so I'm closing this bug
report.  

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

end of thread, other threads:[~2021-06-26 14:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 21:08 bug#29608: python.el movement functions Alex Branham
2017-12-08 17:56 ` Glenn Morris
2017-12-08 21:37   ` Alex Branham
2021-06-26 14:13     ` Lars Ingebrigtsen

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