unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Add more rebind functions to em-rebind.el
@ 2017-07-14 17:05 Matthew Bauer
  2017-07-15  6:59 ` John Wiegley
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Bauer @ 2017-07-14 17:05 UTC (permalink / raw)
  To: emacs-devel

This adds two new functions for em-rebind to handle "killing" without
messing up the prompt:

- eshell-kill-whole-line
- eshell-backward-kill-word

They are roughly the same as ‘kill-whole-line’ and
‘backward-kill-word’ respectively. In addition, the default values for
‘eshell-rebind-keys-alist’ have been updated to use these new commands
over the defaults.
---
 lisp/eshell/em-rebind.el | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)

diff --git a/lisp/eshell/em-rebind.el b/lisp/eshell/em-rebind.el
index a1f9054dae..c34c0cf9c3 100644
--- a/lisp/eshell/em-rebind.el
+++ b/lisp/eshell/em-rebind.el
@@ -55,8 +55,13 @@ the behavior of normal shells while the user editing new input text."
     ([(control ?d)] . eshell-delchar-or-maybe-eof)
     ([backspace]    . eshell-delete-backward-char)
     ([delete]       . eshell-delete-backward-char)
-    ([(control ?w)] . backward-kill-word)
-    ([(control ?u)] . eshell-kill-input))
+    ([(control ?u)] . eshell-kill-input)
+    ([(control ?w)] . eshell-backward-kill-word)
+    ([(control backspace)] . eshell-backward-kill-word)
+    ([(meta backspace)] . eshell-backward-kill-word)
+    ([(control delete)] . eshell-backward-kill-word)
+    ([(meta delete)] . eshell-backward-kill-word)
+    ([(control shift backspace)] . eshell-kill-whole-line))
   "Bind some keys differently if point is in input text."
   :type '(repeat (cons (vector :tag "Keys to bind"
 			       (repeat :inline t sexp))
@@ -222,7 +227,12 @@ lock it at that."
   "Delete the last character, unless it's part of the output."
   (interactive "P")
   (let ((count (prefix-numeric-value n)))
-    (if (eshell-point-within-input-p (- (point) count))
+    (if (or (eshell-point-within-input-p (- (point) count))
+	    (and (use-region-p)
+		 delete-active-region
+		 (= count 1)
+		 (eshell-point-within-input-p (region-beginning))
+		 (eshell-point-within-input-p (region-end))))
 	(delete-backward-char count n)
       (beep))))
 
@@ -242,6 +252,27 @@ input."
 	  (eshell-life-is-too-much)))
       (eshell-delete-backward-char (- arg)))))
 
+(defun eshell-kill-whole-line ()
+  "Kill the whole line except for the eshell prompt."
+  (interactive)
+  (kill-region (point) (save-excursion
+                         (eshell-bol)
+                         (point))))
+
+(defun eshell-backward-kill-word (arg)
+  "Delete the last word, or else everything until the beginning of line.
+ARG number of words to kill."
+  (interactive "p")
+  (let ((word-point (save-excursion
+		      (forward-word (- arg))
+		      (point))))
+    (if (eshell-point-within-input-p word-point)
+	(backward-kill-word arg)
+      (kill-region (point) (save-excursion
+			     (eshell-bol)
+			     (point)))
+      (beep))))
+
 (provide 'em-rebind)
 
 ;; Local Variables:
-- 
2.13.2




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

* Re: [PATCH] Add more rebind functions to em-rebind.el
  2017-07-14 17:05 [PATCH] Add more rebind functions to em-rebind.el Matthew Bauer
@ 2017-07-15  6:59 ` John Wiegley
  2017-07-17  3:33   ` Matthew Bauer
  0 siblings, 1 reply; 6+ messages in thread
From: John Wiegley @ 2017-07-15  6:59 UTC (permalink / raw)
  To: Matthew Bauer; +Cc: emacs-devel

>>>>> "MB" == Matthew Bauer <mjbauer95@gmail.com> writes:

MB> This adds two new functions for em-rebind to handle "killing" without
MB> messing up the prompt:

MB> - eshell-kill-whole-line
MB> - eshell-backward-kill-word

I've never noticed the current backward-kill-word messing up the prompt
before, so can you clarify what effect these changes have?

Thanks,
-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Add more rebind functions to em-rebind.el
  2017-07-15  6:59 ` John Wiegley
@ 2017-07-17  3:33   ` Matthew Bauer
  2017-07-17 12:58     ` John Wiegley
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Bauer @ 2017-07-17  3:33 UTC (permalink / raw)
  To: Matthew Bauer, emacs-devel

I cannot reproduce it on vanilla Emacs. Will try to figure out what's
going on with it and get back to you.

The basic problem was that it wasn't respecting the prompt and
deleting backwards from it. Seems to be related to custom prompts.

On Fri, Jul 14, 2017 at 11:59 PM, John Wiegley <jwiegley@gmail.com> wrote:
>>>>>> "MB" == Matthew Bauer <mjbauer95@gmail.com> writes:
>
> MB> This adds two new functions for em-rebind to handle "killing" without
> MB> messing up the prompt:
>
> MB> - eshell-kill-whole-line
> MB> - eshell-backward-kill-word
>
> I've never noticed the current backward-kill-word messing up the prompt
> before, so can you clarify what effect these changes have?
>
> Thanks,
> --
> John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
> http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Add more rebind functions to em-rebind.el
  2017-07-17  3:33   ` Matthew Bauer
@ 2017-07-17 12:58     ` John Wiegley
  2017-07-17 21:43       ` Matthew Bauer
  0 siblings, 1 reply; 6+ messages in thread
From: John Wiegley @ 2017-07-17 12:58 UTC (permalink / raw)
  To: Matthew Bauer; +Cc: emacs-devel

>>>>> "MB" == Matthew Bauer <mjbauer95@gmail.com> writes:

MB> The basic problem was that it wasn't respecting the prompt and deleting
MB> backwards from it. Seems to be related to custom prompts.

I can believe that.  Eshell does to rather some lengths to protect the prompt
from any modification; perhaps your custom prompt function need to apply the
same text property (or is it overlay?) that Eshell is using.

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Add more rebind functions to em-rebind.el
  2017-07-17 12:58     ` John Wiegley
@ 2017-07-17 21:43       ` Matthew Bauer
  2017-07-18 12:17         ` John Wiegley
  0 siblings, 1 reply; 6+ messages in thread
From: Matthew Bauer @ 2017-07-17 21:43 UTC (permalink / raw)
  To: Matthew Bauer, emacs-devel

It looks like "eshell-highlight-prompt" controls whether read only
properties are set to the prompt, I had that disabled.

On Mon, Jul 17, 2017 at 5:58 AM, John Wiegley <jwiegley@gmail.com> wrote:
>>>>>> "MB" == Matthew Bauer <mjbauer95@gmail.com> writes:
>
> MB> The basic problem was that it wasn't respecting the prompt and deleting
> MB> backwards from it. Seems to be related to custom prompts.
>
> I can believe that.  Eshell does to rather some lengths to protect the prompt
> from any modification; perhaps your custom prompt function need to apply the
> same text property (or is it overlay?) that Eshell is using.
>
> --
> John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
> http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

* Re: [PATCH] Add more rebind functions to em-rebind.el
  2017-07-17 21:43       ` Matthew Bauer
@ 2017-07-18 12:17         ` John Wiegley
  0 siblings, 0 replies; 6+ messages in thread
From: John Wiegley @ 2017-07-18 12:17 UTC (permalink / raw)
  To: Matthew Bauer; +Cc: emacs-devel

>>>>> "MB" == Matthew Bauer <mjbauer95@gmail.com> writes:

MB> It looks like "eshell-highlight-prompt" controls whether read only
MB> properties are set to the prompt, I had that disabled.

Thanks for looking into it, and discovering that no patch is needed. :)

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2



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

end of thread, other threads:[~2017-07-18 12:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-14 17:05 [PATCH] Add more rebind functions to em-rebind.el Matthew Bauer
2017-07-15  6:59 ` John Wiegley
2017-07-17  3:33   ` Matthew Bauer
2017-07-17 12:58     ` John Wiegley
2017-07-17 21:43       ` Matthew Bauer
2017-07-18 12:17         ` John Wiegley

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