@@ -118,20 +118,18 @@ maybeAutoComplete args getSuggestions =
118118getCompIndex :: String -> IO (Int, [String])
119119getCompIndex line =
120120 do maybePoint <- Env.lookupEnv "COMP_POINT"
121− case Read.readMaybe =<< maybePoint :: Maybe Int of
121+ case Read.readMaybe =<< maybePoint of
122122 Nothing ->
123123 do let chunks = words line
124124 return (length chunks, chunks)
125125
126126 Just point ->
127127 let
128− isPoint (_,i) = i == point
129128 groups = List.groupBy grouper (zip line [0..])
130129 rawChunks = drop 1 (filter (all (not . isSpace . fst)) groups)
131− maybeIndex = List.findIndex (any isPoint) rawChunks
132130 in
133131 return
134− ( maybe (length rawChunks) id maybeIndex
132+ ( findIndex 1 point rawChunks
135133 , map (map fst) rawChunks
136134 )
137135
@@ -146,6 +144,25 @@ isSpace char =
146144 char == ' ' || char == '\t' || char == '\n'
147145
148146
147+findIndex :: Int -> Int -> [[(Char,Int)]] -> Int
148+findIndex index point chunks =
149+ case chunks of
150+ [] ->
151+ index
152+
153+ chunk:cs ->
154+ let
155+ lo = snd (head chunk)
156+ hi = snd (last chunk)
157+ in
158+ if point < lo then
159+ 0
160+ else if point <= hi + 1 then
161+ index
162+ else
163+ findIndex (index + 1) point cs
164+
165+
149166complexSuggest :: [Interface] -> Int -> [String] -> IO [String]
150167complexSuggest interfaces index strings =
151168 case strings of
@@ -153,15 +170,15 @@ complexSuggest interfaces index strings =
153170 return (map toName interfaces)
154171
155172 command : chunks ->
156− case List.find (\iface -> toName iface == command) interfaces of
157− Nothing ->
158− if index == 1 then
159− return (filter (List.isPrefixOf command) (map toName interfaces))
160− else
173+ if index == 1 then
174+ return (filter (List.isPrefixOf command) (map toName interfaces))
175+ else
176+ case List.find (\iface -> toName iface == command) interfaces of
177+ Nothing ->
161178 return []
162179
163− Just (Interface _ _ _ _ args_ flags_ _) ->
164− fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
180+ Just (Interface _ _ _ _ args_ flags_ _) ->
181+ fst $ Chomp.chomp (Just (index-1)) chunks args_ flags_
165182
166183
167184