[PATCH] Add more rebind functions to em-rebind.el

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

[PATCH] Add more rebind functions to em-rebind.el

Matthew Bauer
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


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

Re: [PATCH] Add more rebind functions to em-rebind.el

John Wiegley
>>>>> "MB" == Matthew Bauer <[hidden email]> 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

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

Re: [PATCH] Add more rebind functions to em-rebind.el

Matthew Bauer
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 <[hidden email]> wrote:

>>>>>> "MB" == Matthew Bauer <[hidden email]> 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

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

Re: [PATCH] Add more rebind functions to em-rebind.el

John Wiegley
>>>>> "MB" == Matthew Bauer <[hidden email]> 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

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

Re: [PATCH] Add more rebind functions to em-rebind.el

Matthew Bauer
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 <[hidden email]> wrote:

>>>>>> "MB" == Matthew Bauer <[hidden email]> 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

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

Re: [PATCH] Add more rebind functions to em-rebind.el

John Wiegley
>>>>> "MB" == Matthew Bauer <[hidden email]> 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

Loading...