cf :: Store s => CompletionFunc (StateT (Status s) IO)
cf = completeWordWithPrev Nothing " ()`\'-,[]" $ \pv wd -> do
  Status _ (Save (l,_)) <- get
  let
    (pva,pvb) = splitAt 4 $ dropWhile (==' ') pv
    op = pva == "nepo" && (null pvb || head pvb == ' ')
    wds = map pack $ splitOn "." wd
    toComp :: M.Map ByteString (Entity s) -> [Completion]
    toComp m = flip map (M.toList m) $ \(k,(Save (s,_),v)) -> let
        k' = unpack k
      in case v of
        Nothing -> if op
          then Completion k' k' True
          else Completion (k'++".") k' False
        Just e -> Completion k' k' $ M.null s
    addComp :: ByteString -> Completion -> Completion
    addComp s (Completion a b c) = Completion (t a) (t b) c where
      t x = s' ++ "." ++ x
      s' = unpack s
    word :: [ByteString] -> Save s -> [Completion]
    word [] (Save (s,_)) = toComp s
    word [x] (Save (s,_)) = toComp $ M.filterWithKey (\k _ -> x`B.isPrefixOf`k) s
    word (x:xs) (Save (s,_)) = case M.lookup x s of
      Nothing -> []
      Just (y,_) -> map (addComp x) $ word xs y
  return $ word wds $ Save $ (,const Nothing) $ if op
    then M.filter (\(Save (x,_),_) -> not $ M.null x) l
    else l
cf :: Store s => CompletionFunc (StateT (Status s) IO)
cf = completeWordWithPrev Nothing " ()`\'-,[]" $ \pv wd -> do
  Status _ (Save (l,_)) <- get
  let
    (pva,pvb) = splitAt 4 $ dropWhile (==' ') pv
    op = pva == "nepo" && (null pvb || head pvb == ' ')
    wds = map pack $ splitOn "." wd
    toComp :: M.Map ByteString (Entity s) -> [Completion]
    toComp m = flip map (M.toList m) $ \(k,(Save (s,_),v)) -> let
        k' = unpack k
      in case v of
        Nothing -> if op
          then Completion k' k' True
          else Completion (k'++".") k' False
        Just e -> Completion k' k' $ M.null s
    addComp :: ByteString -> Completion -> Completion
    addComp s (Completion a b c) = Completion (t a) (t b) c where
      t x = s' ++ "." ++ x
      s' = unpack s
    word :: [ByteString] -> Save s -> [Completion]
    word [] (Save (s,_)) = toComp s
    word [x] (Save (s,_)) = toComp $ M.filterWithKey (\k _ -> x`B.isPrefixOf`k) s
    word (x:xs) (Save (s,_)) = case M.lookup x s of
      Nothing -> []
      Just (y,_) -> map (addComp x) $ word xs y
  return $ word wds $ Save $ (,const Nothing) $ if op
    then M.filter (\(Save (x,_),_) -> not $ M.null x) l
    else l
cf = completeWordWithPrev Nothing " ()`\'-,[]" $ \pv wd -> do
  Status _ (Save (l,_)) <- get
  let
    (pva,pvb) = splitAt 4 $ dropWhile (==' ') pv
    op = pva == "nepo" && (null pvb || head pvb == ' ')
    wds = map pack $ splitOn "." wd
    toComp :: M.Map ByteString (Entity s) -> [Completion]
    toComp m = flip map (M.toList m) $ \(k,(Save (s,_),v)) -> let
        k' = unpack k
      in case v of
        Nothing -> if op
          then Completion k' k' True
          else Completion (k'++".") k' False
        Just e -> Completion k' k' $ M.null s
    addComp :: ByteString -> Completion -> Completion
    addComp s (Completion a b c) = Completion (t a) (t b) c where
      t x = s' ++ "." ++ x
      s' = unpack s
    word :: [ByteString] -> Save s -> [Completion]
    word [] (Save (s,_)) = toComp s
    word [x] (Save (s,_)) = toComp $ M.filterWithKey (\k _ -> x`B.isPrefixOf`k) s
    word (x:xs) (Save (s,_)) = case M.lookup x s of
      Nothing -> []
      Just (y,_) -> map (addComp x) $ word xs y
  return $ word wds $ Save $ (,const Nothing) $ if op
    then M.filter (\(Save (x,_),_) -> not $ M.null x) l
    else l