aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.rst14
-rw-r--r--init.lua64
2 files changed, 35 insertions, 43 deletions
diff --git a/README.rst b/README.rst
index 4056102..2c9bd1c 100644
--- a/README.rst
+++ b/README.rst
@@ -11,6 +11,20 @@ not offend anybody.
Eventual dream goal is to be compatible with the Honza’s
vim-snippets_.
+After installation to ``~/.config/vis/plugins/vis-snippets`` Add definition of snippets in this style::
+
+ snip = require('plugins/vis-snippets')
+ snip.snippets = {
+ fdup = '%python_expand %fdupes %{buildroot}%{$python_sitelib}',
+ nopy = '%define skip_python2 1',
+ patch = [[
+ # PATCH-{FIX|FEATURE}-{OPENSUSE|SLE|UPSTREAM} name-of-file.patch bsc#[0-9]+ mcepl@suse.com
+ # this patch makes things totally awesome
+ Patch0: <1>
+ ]]
+ }
+ snip.init()
+
.. _vis:
https://github.com/martanne/vis
diff --git a/init.lua b/init.lua
index 1f36408..2a1de5f 100644
--- a/init.lua
+++ b/init.lua
@@ -7,52 +7,30 @@
--
-- Author: Anders Damsgaard <anders@adamsgaard.dk>, adc on #vis-editor
-local snippets = {
- fdup = '%python_expand %fdupes %{buildroot}%{$python_sitelib}',
- nopy = '%define skip_python2 1',
- patch = [[
-# PATCH-{FIX|FEATURE}-{OPENSUSE|SLE|UPSTREAM} name-of-file.patch bsc#[0-9]+ mcepl@suse.com
-# this patch makes things totally awesome
-Patch0: <1>
- ]],
- multi = [[
-%global flavor @BUILD_FLAVOR@%{nil}
-%if "%{flavor}" == "test"
-%define psuffix -test
-%bcond_without test
-%else
-%define psuffix %{nil}
-%bcond_with test
-%endif
-Name: python-${1:name}%{psuffix}
- ]],
- alt = [[
-Requires(post): update-alternatives
-Requires(postun): update-alternatives
-%post
-%python_install_alternative execname
+local M = {}
-%postun
-%python_uninstall_alternative execname
- ]]
-}
+M.snippets = {}
local snippets_leader = '@@'
snippets_cursor = '<1>'
-for k, v in pairs(snippets) do
- if string.find(v, snippets_cursor) then
- vis:map(vis.modes.INSERT, snippets_leader..k,
- function()
- _, j = string.find(v, snippets_cursor)
- vis:insert(string.gsub(v, snippets_cursor, ''))
- vis:feedkeys('<Escape>')
- for _ = j+1, string.len(v) do
- vis:feedkeys('h')
- end
- vis:feedkeys('i')
- end)
- else
- vis:map(vis.modes.INSERT, snippets_leader..k, v)
- end
+M.init = function()
+ for k, v in pairs(M.snippets) do
+ if string.find(v, snippets_cursor) then
+ vis:map(vis.modes.INSERT, snippets_leader..k,
+ function()
+ _, j = string.find(v, snippets_cursor)
+ vis:insert(string.gsub(v, snippets_cursor, ''))
+ vis:feedkeys('<Escape>')
+ for _ = j+1, string.len(v) do
+ vis:feedkeys('h')
+ end
+ vis:feedkeys('i')
+ end)
+ else
+ vis:map(vis.modes.INSERT, snippets_leader..k, v)
+ end
+ end
end
+
+return M