unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#27405: 25.2; Make eshell-next-prompt more reliable
@ 2017-06-17  9:08 Pierre Neidhardt
  2017-06-17 22:13 ` npostavs
  0 siblings, 1 reply; 9+ messages in thread
From: Pierre Neidhardt @ 2017-06-17  9:08 UTC (permalink / raw)
  To: 27405

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





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-06-17  9:08 bug#27405: 25.2; Make eshell-next-prompt more reliable Pierre Neidhardt
@ 2017-06-17 22:13 ` npostavs
  2017-06-18 13:29   ` Pierre Neidhardt
  0 siblings, 1 reply; 9+ messages in thread
From: npostavs @ 2017-06-17 22:13 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 27405

severity 27405 minor
tags 27405 + confirmed
quit

Pierre Neidhardt <ambrevar@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?





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-06-17 22:13 ` npostavs
@ 2017-06-18 13:29   ` Pierre Neidhardt
  2017-06-18 13:52     ` npostavs
  0 siblings, 1 reply; 9+ messages in thread
From: Pierre Neidhardt @ 2017-06-18 13:29 UTC (permalink / raw)
  To: npostavs; +Cc: 27405

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





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-06-18 13:29   ` Pierre Neidhardt
@ 2017-06-18 13:52     ` npostavs
  2017-06-18 14:19       ` Pierre Neidhardt
  0 siblings, 1 reply; 9+ messages in thread
From: npostavs @ 2017-06-18 13:52 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 27405

Pierre Neidhardt <ambrevar@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.





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-06-18 13:52     ` npostavs
@ 2017-06-18 14:19       ` Pierre Neidhardt
  2017-07-12  2:16         ` npostavs
  0 siblings, 1 reply; 9+ messages in thread
From: Pierre Neidhardt @ 2017-06-18 14:19 UTC (permalink / raw)
  To: npostavs; +Cc: 27405

On 17-06-18 09:52:13, npostavs@users.sourceforge.net wrote:
> Pierre Neidhardt <ambrevar@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





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-06-18 14:19       ` Pierre Neidhardt
@ 2017-07-12  2:16         ` npostavs
  2017-07-12 13:06           ` Pierre Neidhardt
  0 siblings, 1 reply; 9+ messages in thread
From: npostavs @ 2017-07-12  2:16 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 27405

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

tags 27405 + patch
quit

Pierre Neidhardt <ambrevar@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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 1848 bytes --]

From 1dd9644f1322d3b40ba98482d4aca0105db56d81 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@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


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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-07-12  2:16         ` npostavs
@ 2017-07-12 13:06           ` Pierre Neidhardt
  2017-07-12 19:26             ` Noam Postavsky
  0 siblings, 1 reply; 9+ messages in thread
From: Pierre Neidhardt @ 2017-07-12 13:06 UTC (permalink / raw)
  To: npostavs; +Cc: 27405

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.





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-07-12 13:06           ` Pierre Neidhardt
@ 2017-07-12 19:26             ` Noam Postavsky
  2017-07-21  2:44               ` npostavs
  0 siblings, 1 reply; 9+ messages in thread
From: Noam Postavsky @ 2017-07-12 19:26 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 27405

On Wed, Jul 12, 2017 at 9:06 AM, Pierre Neidhardt <ambrevar@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.





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

* bug#27405: 25.2; Make eshell-next-prompt more reliable
  2017-07-12 19:26             ` Noam Postavsky
@ 2017-07-21  2:44               ` npostavs
  0 siblings, 0 replies; 9+ messages in thread
From: npostavs @ 2017-07-21  2:44 UTC (permalink / raw)
  To: Pierre Neidhardt; +Cc: 27405

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>





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

end of thread, other threads:[~2017-07-21  2:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-17  9:08 bug#27405: 25.2; Make eshell-next-prompt more reliable Pierre Neidhardt
2017-06-17 22:13 ` npostavs
2017-06-18 13:29   ` Pierre Neidhardt
2017-06-18 13:52     ` npostavs
2017-06-18 14:19       ` Pierre Neidhardt
2017-07-12  2:16         ` npostavs
2017-07-12 13:06           ` Pierre Neidhardt
2017-07-12 19:26             ` Noam Postavsky
2017-07-21  2:44               ` npostavs

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