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

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