Skip to content

Commit 2519b04

Browse files
More specific search error messages.
1 parent 17ef129 commit 2519b04

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

Core.hs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,19 +444,22 @@ genericJumpToMatch :: Lookup a
444444
-> (Int -> HState -> Int)
445445
-> IO ()
446446
genericJumpToMatch re sw k sel = do
447-
found <- modifyHS \st -> let
447+
mmsg <- modifyHS \st -> let
448448
info = case re of
449449
Just s -> Just (st { searchFw = sw }, s, sw)
450450
_ -> listToMaybe [ (st, s, st.searchFw == sw) | s <- st.searchHist ]
451-
in flip (maybe (st, False)) info \(st', p, forwards) -> do
451+
in flip (maybe (st, Just "No previous search.")) info
452+
\ (st', p, forwards) -> do
452453
let (fs, cur, m) = k st
453454
l = if forwards then [cur+1 .. m-1] ++ [0 .. cur]
454455
else [cur-1, cur-2 .. 0] ++ [m-1, m-2 .. cur]
455-
match = matches p
456-
case [ i | i <- l, match $ extract (fs ! i) ] of
457-
i:_ -> (st' { cursor = sel i st }, True)
458-
_ -> (st', False)
459-
unless found $ putMessage [plainSeg "No match found."]
456+
case matches p of
457+
Just match ->
458+
case [ i | i <- l, match $ extract (fs ! i) ] of
459+
i:_ -> (st' { cursor = sel i st }, Nothing)
460+
_ -> (st', Just "No match found.")
461+
_ -> (st', Just "Invalid ERE search pattern.")
462+
whenJust mmsg \msg -> putMessage [plainSeg msg]
460463

461464
------------------------------------------------------------------------
462465

Text.hs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ spaces :: Int -> ByteString
3232
spaces = flip P.replicate ' '
3333

3434
-- | Swappable API for searching
35-
-- TODO report invalid regex
36-
matches :: ByteString -> ByteString -> Bool
37-
matches s = maybe (const False) match $
38-
makeRegexOptsM (compIgnoreCase + compExtended) 0 s
35+
matches :: ByteString -> Maybe (ByteString -> Bool)
36+
matches s = match <$> makeRegexOptsM (compIgnoreCase + compExtended) 0 s
3937

4038
readIntM :: ByteString -> Maybe Int
4139
readIntM = fmap fst . P.readInt

0 commit comments

Comments
 (0)