dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 655c230b2303a2299bffd24d5346ab791f289f68
parent 8d9fe0e6fd337531dbc2eff3a571efc9a28ee3d1
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 17 Jul 2019 09:33:04 +0200

Handle cursor functionality in snippets plugin

Diffstat:
M.config/vis/plugins/snippets.lua | 34+++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/.config/vis/plugins/snippets.lua b/.config/vis/plugins/snippets.lua @@ -1,4 +1,12 @@ -snipleader = '@@' +-- vis-snippets: Insert predefined text snippets from INSERT mode +-- +-- Usage: +-- Press the snipleader (default @@) and a key specified in the +-- insert_snippets table. This will insert the corresponding value from +-- insert_snippets. Optionally, a cursor position can be specified with the +-- string '<0>'. +-- +-- Author: Anders Damsgaard <anders@adamsgaard.dk>, adc on #vis-editor insert_snippets = { ae = 'æ', AE = 'Æ', @@ -6,8 +14,8 @@ insert_snippets = { ae = 'æ', OE = 'Ø', aa = 'å', AA = 'Å', - sig = - '-- \n' .. + q = "\\emph{``<0>''}", + sig = '-- \n' .. 'Anders Damsgaard\n' .. '--\n' .. 'Academia: https://adamsgaard.dk\n' .. @@ -16,6 +24,22 @@ insert_snippets = { ae = 'æ', 'PGP fingerprint: 5C95 9DF2 43CE 4DD1 7A5B 2610 B790 F4AD 1BF8 58FE', } -for k,v in pairs(insert_snippets) do - vis:map(vis.modes.INSERT, snipleader..k, v) +snippets_leader = '@@' +snippets_cursor = '<0>' + +for k, v in pairs(insert_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