diff options
author | tv <tv@shackspace.de> | 2014-12-31 13:18:42 +0100 |
---|---|---|
committer | tv <tv@shackspace.de> | 2014-12-31 13:18:42 +0100 |
commit | 3c70b1c4a5dd2e66280bc234d5d4e626ded4cc33 (patch) | |
tree | da61da021a00d7129ce23d3973c9c3de01a21d0e | |
parent | 4b545f878a9e9c372a7749c16c2bd5a3245eae58 (diff) |
\t moves cursor to next unread message
-rw-r--r-- | test5.hs | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -232,6 +232,8 @@ keymap "\ESC[d" = moveTreeRight 1 -- S-Left keymap "\ESC[5~" = \q -> moveTreeDown (screenHeight q `div` 2) q -- PgUp keymap "\ESC[6~" = \q -> moveTreeUp (screenHeight q `div` 2) q -- PgDn keymap "\n" = toggleFold +keymap "\ESC[Z" = moveCursorUpToPrevUnreadMessage -- S-Tab +keymap "\t" = moveCursorDownToNextUnreadMessage keymap "\DEL" = moveToParent -- backspace -- TODO Stuff Vim sends after exit (also there is more...) @@ -336,6 +338,42 @@ moveToParent q@State{..} = i -> moveTreeDown i q' +moveCursorToUnreadMessage + :: (Num a, Monad m, Eq a) + => (Z.TreePos Z.Full TreeView -> Maybe (Z.TreePos Z.Full TreeView)) + -> (State -> a) + -> (a -> State -> m State) + -> State -> m State +moveCursorToUnreadMessage cursorMove getTreeMoveCount treeMove q@State{..} = + case cursorMove cursor >>= rec of + Just cursor' -> + let q' = q { cursor = cursor' } + in case getTreeMoveCount q' of + 0 -> return q' + i -> treeMove i q' + Nothing -> + return q { flashMessage = "no unread message in sight" } + where + rec loc = + if isUnreadMessage loc + then Just loc + else cursorMove loc >>= rec + isUnreadMessage loc = + case Z.label loc of + TVMessage m -> + "unread" `elem` Notmuch.messageTags m + _ -> + False + +moveCursorUpToPrevUnreadMessage :: Monad m => State -> m State +moveCursorUpToPrevUnreadMessage = + moveCursorToUnreadMessage findPrev topOverrun moveTreeDown + +moveCursorDownToNextUnreadMessage :: Monad m => State -> m State +moveCursorDownToNextUnreadMessage = + moveCursorToUnreadMessage findNext botOverrun moveTreeUp + + toggleFold :: State -> IO State toggleFold q@State{..} = case Z.label cursor of TVMessage _ -> do |