emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Matthew Bauer
Subject: [PATCH] Add more rebind functions to em-rebind.el
Date: Fri, 14 Jul 2017 10:05:32 -0700

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 via email to

[Prev in Thread] Current Thread [Next in Thread]