all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matthew Bauer <mjbauer95@gmail.com>
To: emacs-devel@gnu.org
Subject: [PATCH] Add more rebind functions to em-rebind.el
Date: Fri, 14 Jul 2017 10:05:32 -0700	[thread overview]
Message-ID: <5968fc78.8243630a.fed3c.2be5@mx.google.com> (raw)

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	other threads:[~2017-07-14 17:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-14 17:05 Matthew Bauer [this message]
2017-07-15  6:59 ` [PATCH] Add more rebind functions to em-rebind.el 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5968fc78.8243630a.fed3c.2be5@mx.google.com \
    --to=mjbauer95@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.