diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2020-05-04 18:44:27 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2020-05-04 18:44:27 +0200 |
commit | 2fc2173acd05f739e6555f24fafcea3574708411 (patch) | |
tree | f245d19d9b0dabe6409cb7e35e5e2cbecc025014 | |
parent | 48d67cf3a6689f40741a510c205198517b4d39da (diff) | |
download | vis-snippets-master.tar.gz |
-rw-r--r-- | README.rst | 14 | ||||
-rw-r--r-- | init.lua | 64 |
2 files changed, 35 insertions, 43 deletions
@@ -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 @@ -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 |