diff options
author | Andrea Rossato <andrea.rossato@unibz.it> | 2007-11-15 20:07:34 +0100 |
---|---|---|
committer | Andrea Rossato <andrea.rossato@unibz.it> | 2007-11-15 20:07:34 +0100 |
commit | 99e05daccbf04f92ffa20b56f7b93827f939c95b (patch) | |
tree | f69b7266a6f973d464372a45bd8f5347117ba9da /XMonad | |
parent | 60dd83c5fe998af0b3a709852b8275e1b718212b (diff) | |
download | XMonadContrib-99e05daccbf04f92ffa20b56f7b93827f939c95b.tar.gz XMonadContrib-99e05daccbf04f92ffa20b56f7b93827f939c95b.tar.xz XMonadContrib-99e05daccbf04f92ffa20b56f7b93827f939c95b.zip |
Prompt: add killWord edit action
With this bindings:
^ - Delete kill forward
^ - BackSpace kill backward
darcs-hash:20071115190734-32816-d086d681a480cf9388b04a439d1920b3ee945533.gz
Diffstat (limited to '')
-rw-r--r-- | XMonad/Prompt.hs | 28 |
1 files changed, 23 insertions, 5 deletions
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 = |