Haskell (haskeline) 单词补全
Haskeline 使获得文件名制表符补全功能变得非常容易:
module Main where
import System.Console.Haskeline
import System.Environment
mySettings :: Settings IO
mySettings = defaultSettings {historyFile = Just "myhist"}
main :: IO ()
main = do
args <- getArgs
let inputFunc = getInputLine
runInputT mySettings $ withInterrupt $ loop inputFunc 0
where
loop inputFunc n = do
minput <- handleInterrupt (return (Just "Caught interrupted"))
$ inputFunc (show n ++ ":")
case minput of
Nothing -> return ()
Just s -> do
outputStrLn ("line " ++ show n ++ ":" ++ s)
loop inputFunc (n+1)
它还提供了诸如completeWord和completeQuotedWord之类的函数,这些函数应该能够以与使用completeFilename来实现上述功能相同的方式使用。
(换句话说,基于单词列表(例如函数名称)进行制表符补全,而不是基于文件夹的内容)
任何人都可以提供一个工作示例或工作代码吗?
其他包(如 HCL)中的函数推荐也很有帮助。
Haskeline makes it very easy to get filename tab-completion functionality:
module Main where
import System.Console.Haskeline
import System.Environment
mySettings :: Settings IO
mySettings = defaultSettings {historyFile = Just "myhist"}
main :: IO ()
main = do
args <- getArgs
let inputFunc = getInputLine
runInputT mySettings $ withInterrupt $ loop inputFunc 0
where
loop inputFunc n = do
minput <- handleInterrupt (return (Just "Caught interrupted"))
$ inputFunc (show n ++ ":")
case minput of
Nothing -> return ()
Just s -> do
outputStrLn ("line " ++ show n ++ ":" ++ s)
loop inputFunc (n+1)
It also provides functions like completeWord and completeQuotedWord, which should be able to be used in the same way that completeFilename is used to make the above functionality.
(In other words, have tab-completion based on a list of words (say, function names), instead of based on the contents of a folder)
Can anyone provide a working example - or working code - of this?
Recommendations for functions from other packages (like HCL) are helpful also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是你所追求的东西吗?
将代码段中的
mySettings
的定义替换为该定义,它应该可以工作。Is this the sort of thing you're after?
Replace the definition of
mySettings
in your snippet with that and it should work.