bug#27405: 25.2; Make eshell-next-prompt more reliable

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27405: 25.2; Make eshell-next-prompt more reliable

Pierre Neidhardt
Current definition of `eshell-next-prompt' merely skips a
paragraph. This won't produce the right result as soon the output
contains a paragraph separator (typically an empty line).

I have been using the following redefinition for a while and it works much
better for me:

        (defun eshell-next-prompt (n)
          "Move to end of Nth next prompt in the buffer.
        See `eshell-prompt-regexp'."
          (interactive "p")
          (re-search-forward eshell-prompt-regexp nil t n)
          (when eshell-highlight-prompt
            (while (not (get-text-property (line-beginning-position) 'read-only) )
              (re-search-forward eshell-prompt-regexp nil t n)))
          (eshell-skip-prompt))

        (defun eshell-previous-prompt (n)
          "Move to end of Nth previous prompt in the buffer.
        See `eshell-prompt-regexp'."
          (interactive "p")
          (backward-char)
          (eshell-next-prompt (- n))))

Quite naturally, I search for the `eshell-prompt-regexp'. If that prompt
is too simple (say "^\$ "), some output could easily match the regexp
and the function would move the point there instead of its right
location. To work around that case, I check if the text is read-only,
which is a property of the prompt (if `eshell-highlight-prompt' is `t')
but not of the output.

What do you think? Would you accept a patch?


In GNU Emacs 25.2.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.22.10)
 of 2017-04-22 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.11903000
System Description: Arch Linux



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27405: 25.2; Make eshell-next-prompt more reliable

npostavs
severity 27405 minor
tags 27405 + confirmed
quit

Pierre Neidhardt <[hidden email]> writes:

> Current definition of `eshell-next-prompt' merely skips a
> paragraph. This won't produce the right result as soon the output
> contains a paragraph separator (typically an empty line).
>
> I have been using the following redefinition for a while and it works much
> better for me:

Seems reasonable.

> (defun eshell-next-prompt (n)
>  "Move to end of Nth next prompt in the buffer.
> See `eshell-prompt-regexp'."
>  (interactive "p")
>  (re-search-forward eshell-prompt-regexp nil t n)
>  (when eshell-highlight-prompt
>    (while (not (get-text-property (line-beginning-position) 'read-only) )
>      (re-search-forward eshell-prompt-regexp nil t n)))
>  (eshell-skip-prompt))
>
> (defun eshell-previous-prompt (n)
>  "Move to end of Nth previous prompt in the buffer.
> See `eshell-prompt-regexp'."
>  (interactive "p")
>  (backward-char)
>  (eshell-next-prompt (- n))))

What's the backward-char for?



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27405: 25.2; Make eshell-next-prompt more reliable

Pierre Neidhardt
> > (defun eshell-previous-prompt (n)
> >  "Move to end of Nth previous prompt in the buffer.
> > See `eshell-prompt-regexp'."
> >  (interactive "p")
> >  (backward-char)
> >  (eshell-next-prompt (- n))))
>
> What's the backward-char for?

That would have definitely deserved a comment...

Without it, if point is right after the prompt, it won't move. That would be
disturbing for the user.

Detailed rules:

- If point is on the command line _after_ eshell-bol, then go back to eshell-bol.

- If point is between eshell-bol (included) and _after_ eshell-bol of the last
prompt (excluded), go to the last prompt.

--
Pierre Neidhardt



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27405: 25.2; Make eshell-next-prompt more reliable

npostavs
Pierre Neidhardt <[hidden email]> writes:

>> > (defun eshell-previous-prompt (n)
>> >  "Move to end of Nth previous prompt in the buffer.
>> > See `eshell-prompt-regexp'."
>> >  (interactive "p")
>> >  (backward-char)
>> >  (eshell-next-prompt (- n))))
>>
>> What's the backward-char for?
>
> That would have definitely deserved a comment...
>
> Without it, if point is right after the prompt, it won't move. That would be
> disturbing for the user.

Hmm, maybe beginning-of-line would make more sense?  If I have point on
the same line of the prompt I can get to the beginning of the prompted
line with C-a, so C-c C-p probably means I want to go farther back.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

bug#27405: 25.2; Make eshell-next-prompt more reliable

Pierre Neidhardt
On 17-06-18 09:52:13, [hidden email] wrote:

> Pierre Neidhardt <[hidden email]> writes:
>
> >> > (defun eshell-previous-prompt (n)
> >> >  "Move to end of Nth previous prompt in the buffer.
> >> > See `eshell-prompt-regexp'."
> >> >  (interactive "p")
> >> >  (backward-char)
> >> >  (eshell-next-prompt (- n))))
> >>
> >> What's the backward-char for?
> >
> > That would have definitely deserved a comment...
> >
> > Without it, if point is right after the prompt, it won't move. That would be
> > disturbing for the user.
>
> Hmm, maybe beginning-of-line would make more sense?  If I have point on
> the same line of the prompt I can get to the beginning of the prompted
> line with C-a, so C-c C-p probably means I want to go farther back.

Agreed. Please make the change and add a comment.

--
Pierre Neidhardt



Loading...