首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Haskell (haskeline)单词完成

Haskell (haskeline)单词完成
EN

Stack Overflow用户
提问于 2011-05-27 10:23:40
回答 1查看 1.9K关注 0票数 24

Haskeline使得获取文件名制表符完成功能变得非常容易:

代码语言:javascript
复制
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)中的函数的推荐也很有帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-29 12:15:18

这就是你要找的东西吗?

代码语言:javascript
复制
import Data.List

wordList = [ "Apple", "Pear", "Peach", "Grape", "Grapefruit", "Slime Mold"]

searchFunc :: String -> [Completion]
searchFunc str = map simpleCompletion $ filter (str `isPrefixOf`) wordList

mySettings :: Settings IO
mySettings = Settings { historyFile = Just "myhist"
                      , complete = completeWord Nothing " \t" $ return . searchFunc
                      , autoAddHistory = True
                      }

将代码片段中的mySettings定义替换为该定义,它应该可以工作。

票数 23
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6147201

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档