yi-core-0.18.0: Yi editor core library

LicenseGPL-2
Maintaineryi-devel@googlegroups.com
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Yi.CompletionTree

Contents

Description

Little helper for completion interfaces.

Intended to be imported qualified:

import qualified Yi.CompletionTree as CT
Synopsis

CompletionTree type

newtype CompletionTree a Source #

A CompletionTree is a map of partial completions.

Example:

fromList ["put","putStr","putStrLn","print","abc"]

Gives the following tree:

/ "p" "abc" / "ut" "rint" / Str "" / Ln ""

(The empty strings are needed to denote the end of a word) (A CompletionTree is not limited to a binary tree)

Constructors

CompletionTree (Map a (CompletionTree a)) 
Instances
Eq a => Eq (CompletionTree a) Source # 
Instance details

Defined in Yi.CompletionTree

(Ord a, Show a, ListLike a i) => Show (CompletionTree a) Source # 
Instance details

Defined in Yi.CompletionTree

Ord a => Semigroup (CompletionTree a) Source # 
Instance details

Defined in Yi.CompletionTree

Ord a => Monoid (CompletionTree a) Source # 
Instance details

Defined in Yi.CompletionTree

Binary a => Binary (CompletionTree a) Source # 
Instance details

Defined in Yi.CompletionTree

Lists

fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a Source #

This function converts a list of completable elements to a CompletionTree It finds elements that share a common prefix and groups them.

fromList . toList = id

toList :: (Ord a, ListLike a i) => CompletionTree a -> [a] Source #

Converts a CompletionTree to a list of completions.

toList . fromList = sort . nub

Examples:

>>> toList mempty
[]
>>> toList (fromList ["a"])
["a"]
>>> toList (fromList ["a","a","a"])
["a"]
>>> toList (fromList ["z","x","y"])
["x","y","z"]

Modification

complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a) Source #

Complete as much as possible without guessing.

Examples:

>>> complete $ fromList ["put","putStrLn","putStr"]
("put", fromList ["","Str","StrLn"])
>>> complete $ fromList ["put","putStr","putStrLn","abc"]
("", fromList ["put","putStr","putStrLn","abc"])

update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a Source #

Update the CompletionTree with new information. An empty list means that there is no completion left. A [mempty] means that the end of a word is reached.

Examples:

>>> update (fromList ["put","putStr"]) "p"
fromList ["ut","utStr"]
>>> update (fromList ["put","putStr"]) "put"
fromList ["","Str"]
>>> update (fromList ["put","putStr"]) "putS"
fromList ["tr"]
>>> update (fromList ["put"]) "find"
fromList []
>>> update (fromList ["put"]) "put"
fromList [""]

Debugging

pretty :: Show a => CompletionTree a -> String Source #

For debugging purposes.

Example:

>>> putStrLn $ pretty $ fromList ["put", "putStr", "putStrLn"]
["put"[""|"Str"[""|"Ln"]]]

Lens