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 25c72faa7cc74d604354f39ea71ebeb1a511ca85
parent 1331a0810e75c83fe49492fb678bb7f98c939c81
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 14 Jun 2019 20:59:59 +0200

Add dynamic interpreter handling, inspired by ninewise

Diffstat:
M.config/vis/visrc.lua | 85++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 45 insertions(+), 40 deletions(-)

diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua @@ -1,9 +1,43 @@ require('vis') require('plugins/vis-commentary') require('plugins/fzf-mru') +require('snippets') leader = '<Space>' +-- from https://github.com/ninewise/dotfiles/blob/master/config/vis/visrc.lua +vis:command_register("fzf", function(argv, force, cur_win, selection, range) + local out = io.popen("fzf"):read() + if out then + if argv[1] then + vis:command(string.format('e "%s"', out)) + else + vis:command(string.format('open "%s"', out)) + end + vis:feedkeys("<vis-redraw>") + end +end, 'fuzzy file search') + +interpreters = { + ["python"] = "!python -i $vis_filename", + ["lua"] = "!lua -i $vis_filename", + ["julia"] = "!julia -i $vis_filename", + ["latex"] = "!tmux new-window -a 'latexmk -pdf -pvc -f $vis_filepath'", +} + +vis:command_register("prev", function(argv, force, cur_win, selection, range) + local file = io.popen('sed -n 2p ~/.mru') + local output = file:read() + local success, msg, status = file:close() + if status == 0 then + vis:feedkeys(string.format(":e '%s'<Enter>", output)) + else + vis:info('error ' .. tostring(status)) + end + vis:feedkeys('<vis-redraw>') + return true; +end, 'edit previous file') + vis.events.subscribe(vis.events.INIT, function() -- global configuration options vis:command('set theme adbasic') @@ -11,53 +45,27 @@ vis.events.subscribe(vis.events.INIT, function() vis:map(vis.modes.NORMAL, leader..'w', ':w<Enter>') vis:map(vis.modes.NORMAL, leader..'q', ':q<Enter>') vis:map(vis.modes.NORMAL, leader..'x', ':wq<Enter>') - vis:map(vis.modes.NORMAL, leader..'e', ':e <Tab>') vis:map(vis.modes.NORMAL, leader..'n', ':set numbers!<Enter>') vis:map(vis.modes.NORMAL, leader..'N', ':set relativenumbers!<Enter>') vis:map(vis.modes.NORMAL, leader..'l', ':set show-newline!<Enter>') vis:map(vis.modes.NORMAL, leader..'m', ':!make<Enter>') + vis:map(vis.modes.NORMAL, '<F7>', ':!sent $vis_filepath &<Enter>') + + vis:map(vis.modes.NORMAL, '<Tab><Tab>', '<vis-window-next>') + vis:map(vis.modes.NORMAL, leader..'<Tab>', ':prev<Enter>') -- fuzzy open - vis:map(vis.modes.NORMAL, leader..'o', - function() - local file = io.popen('fzf') - local output = file:read() - local success, msg, status = file:close() - if status == 0 then - vis:feedkeys(string.format(":e '%s'<Enter>", output)) - else - vis:info('error ' .. tostring(status)) - end - vis:feedkeys('<vis-redraw>') - return true; - end) + vis:map(vis.modes.NORMAL, leader..'e', ':fzf<Enter>') + vis:map(vis.modes.NORMAL, leader..'o', ':fzf true<Enter>') -- fuzzy open recent file - vis:map(vis.modes.NORMAL, leader..',', ':fzfmru<Enter>') - - -- switch to previous file - vis:map(vis.modes.NORMAL, leader..'<Tab>', - function() - local file = io.popen('sed -n 2p ~/.mru') - local output = file:read() - local success, msg, status = file:close() - if status == 0 then - vis:feedkeys(string.format(":e '%s'<Enter>", output)) - else - vis:info('error ' .. tostring(status)) - end - vis:feedkeys('<vis-redraw>') - return true; - end) - + vis:map(vis.modes.NORMAL, leader..'<Tab>', ':fzfmru<Enter>') vis:map(vis.modes.NORMAL, leader..'r', ':< scholarref ') -- mappings to often used files vis:map(vis.modes.NORMAL, leader..'C', ':e ~/.config/vis/visrc.lua<Enter>') vis:map(vis.modes.NORMAL, leader..'T', ':e ~/doc/todo.md<Enter>') vis:map(vis.modes.NORMAL, leader..'B', ':e "$BIB"<Enter>') - - require('snippets') end) vis.events.subscribe(vis.events.WIN_OPEN, function(win) @@ -68,14 +76,11 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) vis:command('set tabwidth 4') vis:command('set colorcolumn 80') - -- run file through external compile script - vis:map(vis.modes.NORMAL, leader..'p', + vis:map(vis.modes.NORMAL, leader..'i', function() - if win.file.name then - cmd = os.execute('compile ' .. win.file.name) - if cmd then vis:info('compile complete') - else vis:info('error: return status ' .. tostring(cmd)) end - vis:feedkeys('<vis-redraw>') + local command = interpreters[vis.win.syntax] + if command then + vis:command(command) end return true; end)