GNU bug report logs - #27405
25.2; Make eshell-next-prompt more reliable

Previous Next

Package: emacs;

Reported by: Pierre Neidhardt <ambrevar <at> gmail.com>

Date: Sat, 17 Jun 2017 09:09:01 UTC

Severity: minor

Tags: confirmed, fixed, patch

Found in version 25.2

Fixed in version 26.1

Done: npostavs <at> users.sourceforge.net

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 27405 in the body.
You can then email your comments to 27405 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#27405; Package emacs. (Sat, 17 Jun 2017 09:09:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Pierre Neidhardt <ambrevar <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 17 Jun 2017 09:09:01 GMT) Full text and rfc822 format available.

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

From: Pierre Neidhardt <ambrevar <at> gmail.com>
To: GNU Emacs bug Tracking System <bug-gnu-emacs <at> gnu.org>
Subject: 25.2; Make eshell-next-prompt more reliable
Date: Sat, 17 Jun 2017 10:08:13 +0100
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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Sat, 17 Jun 2017 22:13:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Pierre Neidhardt <ambrevar <at> gmail.com>
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Sat, 17 Jun 2017 18:13:44 -0400
severity 27405 minor
tags 27405 + confirmed
quit

Pierre Neidhardt <ambrevar <at> gmail.com> 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?




Severity set to 'minor' from 'normal' Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 17 Jun 2017 22:13:02 GMT) Full text and rfc822 format available.

Added tag(s) confirmed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 17 Jun 2017 22:13:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Sun, 18 Jun 2017 13:30:02 GMT) Full text and rfc822 format available.

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

From: Pierre Neidhardt <ambrevar <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Sun, 18 Jun 2017 14:29:32 +0100
> > 	(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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Sun, 18 Jun 2017 13:51:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Pierre Neidhardt <ambrevar <at> gmail.com>
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Sun, 18 Jun 2017 09:52:13 -0400
Pierre Neidhardt <ambrevar <at> gmail.com> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Sun, 18 Jun 2017 14:21:01 GMT) Full text and rfc822 format available.

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

From: Pierre Neidhardt <ambrevar <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Sun, 18 Jun 2017 15:19:59 +0100
On 17-06-18 09:52:13, npostavs <at> users.sourceforge.net wrote:
> Pierre Neidhardt <ambrevar <at> gmail.com> 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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Wed, 12 Jul 2017 02:16:02 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Pierre Neidhardt <ambrevar <at> gmail.com>
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Tue, 11 Jul 2017 22:16:38 -0400
[Message part 1 (text/plain, inline)]
tags 27405 + patch
quit

Pierre Neidhardt <ambrevar <at> gmail.com> writes:

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

I think also that doing the text property check following the regexp
search doesn't really make sense, one or the other should be used, not
both:

[v2-0001-Make-eshell-next-prompt-more-reliable-Bug-27405.patch (text/x-diff, inline)]
From 1dd9644f1322d3b40ba98482d4aca0105db56d81 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> gmail.com>
Date: Tue, 11 Jul 2017 22:11:19 -0400
Subject: [PATCH v2] Make eshell-next-prompt more reliable (Bug#27405)

* lisp/eshell/em-prompt.el (eshell-next-prompt): Search for
`eshell-prompt-regexp' (and `read-only' text-property if
`eshell-highlight-prompt' is set) rather than trying to use
`forward-paragraph'.
(eshell-previous-prompt): Don't count prompt on current line.
---
 lisp/eshell/em-prompt.el | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el
index 8c81b43b1f..2fd1db2113 100644
--- a/lisp/eshell/em-prompt.el
+++ b/lisp/eshell/em-prompt.el
@@ -161,14 +161,25 @@ (defun eshell-next-prompt (n)
   "Move to end of Nth next prompt in the buffer.
 See `eshell-prompt-regexp'."
   (interactive "p")
-  (forward-paragraph n)
+  (if eshell-highlight-prompt
+      (progn
+        (while (< n 0)
+          (while (and (re-search-backward eshell-prompt-regexp nil t)
+                      (not (get-text-property (match-beginning 0) 'read-only))))
+          (setq n (1+ n)))
+        (while (> n 0)
+          (while (and (re-search-forward eshell-prompt-regexp nil t)
+                      (not (get-text-property (match-beginning 0) 'read-only))))
+          (setq n (1- n))))
+    (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")
-  (eshell-next-prompt (- (1+ n))))
+  (beginning-of-line)            ; Don't count prompt on current line.
+  (eshell-next-prompt (- n)))
 
 (defun eshell-skip-prompt ()
   "Skip past the text matching regexp `eshell-prompt-regexp'.
-- 
2.11.1


Added tag(s) patch. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Wed, 12 Jul 2017 02:16:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Wed, 12 Jul 2017 13:07:01 GMT) Full text and rfc822 format available.

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

From: Pierre Neidhardt <ambrevar <at> gmail.com>
To: npostavs <at> users.sourceforge.net
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Wed, 12 Jul 2017 14:06:05 +0100
Agreed.  If `eshell-highlight-prompt', then search for the first
read-only text, otherwise search for the regexp (less reliable).  No
need to bother with the regexp.  I don't think that anything but the
prompt would be read-only, but I may be wrong.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Wed, 12 Jul 2017 19:27:01 GMT) Full text and rfc822 format available.

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

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Pierre Neidhardt <ambrevar <at> gmail.com>
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Wed, 12 Jul 2017 15:26:07 -0400
On Wed, Jul 12, 2017 at 9:06 AM, Pierre Neidhardt <ambrevar <at> gmail.com> wrote:
> Agreed.  If `eshell-highlight-prompt', then search for the first
> read-only text, otherwise search for the regexp (less reliable).  No
> need to bother with the regexp.  I don't think that anything but the
> prompt would be read-only, but I may be wrong.

Nothing else will be read-only by default, but I think it's safer not
to assume things will always be that way.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#27405; Package emacs. (Fri, 21 Jul 2017 02:44:01 GMT) Full text and rfc822 format available.

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

From: npostavs <at> users.sourceforge.net
To: Pierre Neidhardt <ambrevar <at> gmail.com>
Cc: 27405 <at> debbugs.gnu.org
Subject: Re: bug#27405: 25.2; Make eshell-next-prompt more reliable
Date: Thu, 20 Jul 2017 22:44:52 -0400
tags 27405 fixed
close 27405 26.1
quit

I pushed to master

[1: 7a0ca227af]: 2017-07-20 22:40:34 -0400
  Make eshell-next-prompt more reliable (Bug#27405)
  http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=7a0ca227af1081ca7ada2e82a87b1a575ef04759>




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Fri, 21 Jul 2017 02:44:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 26.1, send any further explanations to 27405 <at> debbugs.gnu.org and Pierre Neidhardt <ambrevar <at> gmail.com> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Fri, 21 Jul 2017 02:44:02 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. (Fri, 18 Aug 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 35 days ago.

Previous Next


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