Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ethercrow/yi-snippet
Snippets for Yi
https://github.com/ethercrow/yi-snippet
Last synced: 24 days ago
JSON representation
Snippets for Yi
- Host: GitHub
- URL: https://github.com/ethercrow/yi-snippet
- Owner: ethercrow
- License: gpl-2.0
- Created: 2015-10-16T17:48:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-10-17T07:43:48.000Z (about 9 years ago)
- Last Synced: 2024-10-14T10:13:19.197Z (2 months ago)
- Language: Haskell
- Size: 103 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
Awesome Lists containing this project
README
.. image:: https://travis-ci.org/yi-editor/yi-snippet.svg?branch=master
:target: https://travis-ci.org/yi-editor/yi-snippetThis plugin provides snippet editing.
Setup
=====You need to do two things: make a snippet collection and bind snippet expansion
action to some input.Here's a minimum viable snippet collection just for now::
mySnippets = [Snippet "text" (lit "import qualified Data.Text as T")]
Emacs and cua
-------------Binding the action would probably look like this::
(ctrlCh 's' ?>>! expandSnippetE (pure ()) mySnippets)
Vim
---For vim keymap it's slightly more convoluted::
imapE ""
(expandSnippetE (defEval "") mySnippets)where::
import qualified Yi.Keymap.Vim as V
imapE x y = V.VimBindingE (\evs state -> case V.vsMode state of
V.Insert _ ->
fmap (const (y >> return V.Drop))
(evs `V.matchesString` x)
_ -> V.NoMatch)If you want `` to be responsible for both snippet expansion and inserting a (possibly expanded) tab when there's no snippet to be expanded, you can use this::
imapY ""
(withEditor $ do
let defEval = V.pureEval (extractValue V.defVimConfig)
expanded <- Snippet.expandSnippetE (defEval "") mySnippets
when (not expanded) (defEval ""))Usage
=====This is pretty straightforward and should be familiar from other editors.
Press to go to the next placeholder.
Press to end snippet editing.
Type stuff to type stuff.Writing snippets
================`Snippet` record has two fields: a trigger and a body.
The body can be written using `do` notation::
Snippet "lp" $ do
lit "{-# LANGUAGE "
_ <- place "OverloadedStrings"
lit " #-}"Avaliable primitives are:
lit
just a piece of textplace
placeholder with default valuerefer
refer to current value offinish
mark a place where cursor must end up after visiting all placeholdersAnd there are some convenience functions:
nl
a newline, same as `lit "\n"`line
same as `do lit ; nl`mirror
same as `do value <- refer ; lit value`Predefined variables
--------------------Currently there's just one: `filename`. Here is how you can use it to write a
snippet for haskell module header::import Data.Char (isUpper)
import qualified Data.Text as T
import System.FilePath (dropExtension)
import qualified Yi.Rope as Rlet moduleHeaderSnippet =
Snippet "m" $ do
moduleName <- guessModuleName <$> refer filename
line ("module " <> moduleName)
lit " (" >> finish >> nl
lit " ) where"guessModuleName :: R.YiString -> R.YiString
guessModuleName =
R.fromText . T.intercalate "."
. reverse . takeWhile isCapitalized . reverse
. T.splitOn "/"
. T.pack . dropExtension . T.unpack
. R.toText
where
isCapitalized s = case T.uncons s of
Just (c, _) -> isUpper c
Nothing -> FalseExample snippets
----------------Some examples are available in examples/MySnippets.hs
When all else fails
===================Please don't hesitate to complain, request features or send patches at https://github.com/yi-editor/yi-snippet.
Our irc channel is #yi@freenode.