@@ -118,20 +118,18 @@ maybeAutoComplete args getSuggestions =
118getCompIndex :: String -> IO (Int, [String])
118getCompIndex :: String -> IO (Int, [String])
119getCompIndex line =
119getCompIndex line =
120 do maybePoint <- Env.lookupEnv "COMP_POINT"
120 do maybePoint <- Env.lookupEnv "COMP_POINT"
121− case Read.readMaybe =<< maybePoint :: Maybe Int of
121+ case Read.readMaybe =<< maybePoint of
122 Nothing ->
122 Nothing ->
123 do let chunks = words line
123 do let chunks = words line
124 return (length chunks, chunks)
124 return (length chunks, chunks)
126 Just point ->
126 Just point ->
128− isPoint (_,i) = i == point
129 groups = List.groupBy grouper (zip line [0..])
128 groups = List.groupBy grouper (zip line [0..])
130 rawChunks = drop 1 (filter (all (not . isSpace . fst)) groups)
129 rawChunks = drop 1 (filter (all (not . isSpace . fst)) groups)
131− maybeIndex = List.findIndex (any isPoint) rawChunks
134− ( maybe (length rawChunks) id maybeIndex
132+ ( findIndex 1 point rawChunks
135 , map (map fst) rawChunks
133 , map (map fst) rawChunks
@@ -146,6 +144,25 @@ isSpace char =
146 char == ' ' || char == '\t' || char == '\n'
144 char == ' ' || char == '\t' || char == '\n'
147+findIndex :: Int -> Int -> [[(Char,Int)]] -> Int
148+findIndex index point chunks =
155+ lo = snd (head chunk)
156+ hi = snd (last chunk)
160+ else if point <= hi + 1 then
163+ findIndex (index + 1) point cs
149complexSuggest :: [Interface] -> Int -> [String] -> IO [String]
166complexSuggest :: [Interface] -> Int -> [String] -> IO [String]
150complexSuggest interfaces index strings =
167complexSuggest interfaces index strings =
151 case strings of
168 case strings of
@@ -153,15 +170,15 @@ complexSuggest interfaces index strings =
153 return (map toName interfaces)
170 return (map toName interfaces)
155 command : chunks ->
172 command : chunks ->
156− case List.find (\iface -> toName iface == command) interfaces of
158− if index == 1 then
173+ if index == 1 then
159− return (filter (List.isPrefixOf command) (map toName interfaces))
174+ return (filter (List.isPrefixOf command) (map toName interfaces))
176+ case List.find (\iface -> toName iface == command) interfaces of
161 return []
178 return []
163− Just (Interface _ _ _ _ args_ flags_ _) ->
180+ Just (Interface _ _ _ _ args_ flags_ _) ->
164− fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
181+ fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_