yi-core-0.19.4: Yi editor core library

License | GPL-2
Maintainer | yi-devel@googlegroups.com
Stability | experimental
Portability | portable
Safe Haskell | None
Language | Haskell2010

Yi.CompletionTree

Contents

- CompletionTree type
- Lists
- Modification
- Debugging
  - Lens

Description

Little helper for completion interfaces.

Intended to be imported qualified:

    import qualified Yi.CompletionTree as CT

Synopsis

- newtype CompletionTree a = CompletionTree (Map a (CompletionTree a))
- fromList :: (Ord a, ListLike a i, Eq i) => [a] -> CompletionTree a
- toList :: (Ord a, ListLike a i) => CompletionTree a -> [a]
- complete :: (Eq i, Ord a, ListLike a i) => CompletionTree a -> (a, CompletionTree a)
- update :: (Ord a, ListLike a i, Eq i) => CompletionTree a -> a -> CompletionTree a
- pretty :: Show a => CompletionTree a -> String
- unCompletionTree :: forall a f. Functor f => (Map a (CompletionTree a) -> f (Map a (CompletionTree a))) -> CompletionTree a -> f (CompletionTree a)

# 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

Instances details

Binary a => Binary (CompletionTree a) Source # |
Instance details Defined in Yi.CompletionTree Methods put :: CompletionTree a -> Put Source # get :: Get (CompletionTree a) Source # putList :: [CompletionTree a] -> Put Source #
Ord a => Monoid (CompletionTree a) Source # |
Instance details Defined in Yi.CompletionTree Methods mempty :: CompletionTree a Source # mappend :: CompletionTree a -> CompletionTree a -> CompletionTree a Source # mconcat :: [CompletionTree a] -> CompletionTree a Source #
Ord a => Semigroup (CompletionTree a) Source # |
Instance details Defined in Yi.CompletionTree Methods (<>) :: CompletionTree a -> CompletionTree a -> CompletionTree a Source # sconcat :: NonEmpty (CompletionTree a) -> CompletionTree a Source # stimes :: Integral b => b -> CompletionTree a -> CompletionTree a Source #
(Ord a, Show a, ListLike a i) => Show (CompletionTree a) Source # |
Instance details Defined in Yi.CompletionTree Methods showsPrec :: Int -> CompletionTree a -> ShowS Source # show :: CompletionTree a -> String Source # showList :: [CompletionTree a] -> ShowS Source #
Eq a => Eq (CompletionTree a) Source # |
Instance details Defined in Yi.CompletionTree Methods (==) :: CompletionTree a -> CompletionTree a -> Bool Source # (/=) :: CompletionTree a -> CompletionTree a -> Bool Source #

# 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

unCompletionTree :: forall a f. Functor f => (Map a (CompletionTree a) -> f (Map a (CompletionTree a))) -> CompletionTree a -> f (CompletionTree a) Source #