@@ -406,7 +406,7 @@ blacklist = do
406406jumpToRandom :: HState -> IO HState
407407jumpToRandom st = do
408408 n' <- randomIO
409- let n = abs n' `mod` ( size st - 1 )
409+ let n = abs n' `mod` size st
410410 playAtN st (const n)
411411
412412-- | Play the song before the current song, if we're not at the beginning
@@ -520,46 +520,22 @@ genericJumpToMatch :: Lookup a
520520 -> IO ()
521521
522522genericJumpToMatch re sw k sel = do
523- found <- modifySTM_ $ \ st -> do
523+ found <- modifySTM_ $ \ st -> pure do
524524 let mre = case re of
525- -- work out if we have no pattern, a cached pattern, or a new pattern
526- Nothing -> case regex st of
527- Nothing -> Nothing
528- Just (r,d) -> Just (r,d== sw)
529- Just s -> case compileM (P. pack s) [caseless,utf8] of
530- Left _ -> Nothing
531- Right v -> Just (v,sw)
532- case mre of
533- Nothing -> pure (st,False ) -- no pattern
534- Just (p,forwards) -> do
535-
536- let (fs,cur,m) = k st
537-
538- {-
539- loop fn inc n
540- | fn n = pure Nothing
541- | otherwise = do
542- let s = extract (fs ! n)
543- case match p s [] of
544- Nothing -> loop fn inc $! inc n
545- -}
546-
547- check n = let s = extract (fs ! n) in
548- case match p s [] of
549- Nothing -> pure Nothing
550- Just _ -> pure $ Just n
551-
552- -- mi <- if forwards then loop (>=m) (+1) (cur+1)
553- -- else loop (<0) (subtract 1) (cur-1)
554- mi <- fmap msum $ traverse check $
555- if forwards then [cur+ 1 .. m- 1 ] ++ [0 .. cur]
556- else [cur- 1 ,cur- 2 .. 0 ] ++ [m- 1 ,m- 2 .. cur]
557-
558-
559- let st' = st { regex = Just (p,forwards== sw) }
560- pure case mi of
561- Nothing -> (st',False )
562- Just i -> (st' { cursor = sel i st }, True )
525+ Nothing -> case regex st of
526+ Nothing -> Nothing
527+ Just (r, d) -> Just (r, d== sw)
528+ Just s -> case compileM (P. pack s) [caseless, utf8] of
529+ Left _ -> Nothing
530+ Right v -> Just (v, sw)
531+ flip (maybe (st, False )) mre \ (p, forwards) -> do
532+ let (fs, cur, m) = k st
533+ l = if forwards then [cur+ 1 .. m- 1 ] ++ [0 .. cur]
534+ else [cur- 1 ,cur- 2 .. 0 ] ++ [m- 1 ,m- 2 .. cur]
535+ st' = st { regex = Just (p, forwards== sw) }
536+ case [ i | i <- l, isJust $ match p (extract (fs ! i)) [] ] of
537+ i: _ -> (st' { cursor = sel i st }, True )
538+ _ -> (st', False )
563539
564540 unless found $ putmsg (Fast " No match found." defaultSty) *> touchST
565541
@@ -580,6 +556,7 @@ toggleExit = modifyST $ \st -> st { exitVisible = not (exitVisible st) }
580556-- | History on or off
581557hideHist :: IO ()
582558hideHist = modifyST $ \ st -> st { histVisible = Nothing }
559+
583560showHist :: IO ()
584561showHist = do
585562 now <- getMonoTime
0 commit comments