From 99e05daccbf04f92ffa20b56f7b93827f939c95b Mon Sep 17 00:00:00 2001
From: Andrea Rossato <andrea.rossato@unibz.it>
Date: Thu, 15 Nov 2007 20:07:34 +0100
Subject: Prompt: add killWord edit action

With this bindings:
^ - Delete kill forward
^ - BackSpace kill backward

darcs-hash:20071115190734-32816-d086d681a480cf9388b04a439d1920b3ee945533.gz
---
 XMonad/Prompt.hs | 28 +++++++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)

(limited to 'XMonad')

diff --git a/XMonad/Prompt.hs b/XMonad/Prompt.hs
index 7b70b7e..c2fc75a 100644
--- a/XMonad/Prompt.hs
+++ b/XMonad/Prompt.hs
@@ -270,11 +270,13 @@ keyPressHandle mask (ks,_)
     | mask == controlMask =
         -- control sequences
         case () of
-          _ | ks == xK_u -> killBefore  >> go
-            | ks == xK_k -> killAfter   >> go
-            | ks == xK_a -> startOfLine >> go
-            | ks == xK_e -> endOfLine   >> go
-            | ks == xK_y -> pasteString >> go
+          _ | ks == xK_u               -> killBefore    >> go
+            | ks == xK_k               -> killAfter     >> go
+            | ks == xK_a               -> startOfLine   >> go
+            | ks == xK_e               -> endOfLine     >> go
+            | ks == xK_y               -> pasteString   >> go
+            | ks == xK_Delete          -> killWord Next >> go
+            | ks == xK_BackSpace       -> killWord Prev >> go
             | ks == xK_g || ks == xK_c -> quit
             | otherwise  -> eventLoop handle -- unhandled control sequence
     | ks == xK_Return    = historyPush       >> return ()
@@ -310,6 +312,22 @@ killAfter :: XP ()
 killAfter =
   modify $ \s -> s { command = take (offset s) (command s) }
 
+-- | Kill the next/previous word
+killWord :: Direction -> XP ()
+killWord d = do
+  XPS { command = c, offset = o } <- get
+  let (f,ss)        = splitAt o c
+      delNextWord w = 
+          case w of
+            ' ':x -> x
+            word  -> snd . break isSpace $ word
+      delPrevWord   = reverse . delNextWord . reverse
+      (ncom,noff)   = 
+          case d of
+            Next -> (f ++ delNextWord ss, o)
+            Prev -> (delPrevWord f ++ ss, length $ delPrevWord f) -- laziness!!
+  modify $ \s -> s { command = ncom, offset = noff}
+
 -- | Put the cursor at the end of line
 endOfLine :: XP ()
 endOfLine  =
-- 
cgit v1.2.3