visrc.lua (4116B)
1 require('vis') 2 require('build') 3 require('macros') 4 require('set-title') 5 require('plugins/vis-gpg') 6 require('plugins/vis-spellcheck') 7 8 local lint = require('plugins/vis-lint') 9 local gf = require('goto-ref') 10 local util = require('util') 11 local highlight = require('highlight') 12 highlight.keywords = { 13 NOCOMMIT = 'fore:cyan,underlined,bold,blink', 14 FIXME = 'fore:red,underlined,bold', 15 NOTE = 'fore:green,underlined,bold', 16 TODO = 'fore:magenta,underlined,bold', 17 IMPORTANT = 'fore:yellow,underlined,bold', 18 } 19 20 local tabwidth = 2 21 22 local function min(a, b) if a < b then return a else return b end end 23 24 -- detect matlab with %.m not objective_c 25 vis.ftdetect.filetypes.matlab = { ext = { "%.m$" } } 26 assert(table.remove(vis.ftdetect.filetypes.objective_c.ext, 1) == "%.m$") 27 28 -- use smaller tabs for heavily nested matlab classes and latex 29 vis.ftdetect.filetypes.latex.cmd = {"set tw " .. tostring(min(tabwidth, 4))} 30 vis.ftdetect.filetypes.matlab.cmd = {"set tw " .. tostring(min(tabwidth, 4))} 31 32 vis.ftdetect.filetypes.haskell.cmd = { "set tw 4", "set expandtab true" } 33 lint.fixers["haskell"] = { "hindent --indent-size 4 --sort-imports" } 34 35 lint.fixers["python"] = {} -- {"black -l 80 -q -"} 36 vis.ftdetect.filetypes.python.cmd = {"set tw " .. tostring(min(tabwidth, 4))} 37 38 vis.ftdetect.filetypes.yaml.cmd = { "set tw 2", "set expandtab true" } 39 40 vis.events.subscribe(vis.events.INIT, function() 41 vis:command("set theme term") 42 43 vis.options = { autoindent = true } 44 45 local m, cmd = vis.modes, util.command 46 vis:map(m.NORMAL, " f", "v$:|furigana<Enter><Escape>") 47 vis:map(m.NORMAL, " j", "<vis-window-next>") 48 vis:map(m.NORMAL, " k", "<vis-window-prev>") 49 vis:map(m.NORMAL, "gq", "vip=<Escape>") 50 vis:map(m.VISUAL, " s", cmd("|sort")) 51 52 vis:map(m.NORMAL, "vo", cmd("x/[ \t\r]+$/ d"), 53 "remove whitespace from end of all lines") 54 55 vis:map(m.NORMAL, " l", function() 56 local ui = vis.ui 57 if ui.layout == ui.layouts.HORIZONTAL then 58 ui.layout = ui.layouts.VERTICAL 59 else 60 ui.layout = ui.layouts.HORIZONTAL 61 end 62 end, "swap ui layout") 63 64 vis:map(m.NORMAL, " i", function() 65 local fn = vis.win.file.name 66 vis:message("syntax = " .. tostring(vis.win.syntax)) 67 vis:message("file.name = " .. fn) 68 end, "dump info to message window") 69 70 vis:map(m.VISUAL, "gf", function() 71 local sel = vis.win.selection 72 local data = vis.win.file:content(sel.range) 73 local pairs = gf.generate_line_indices(data) 74 vis.mode = vis.modes.NORMAL 75 if pairs then gf.focus_file_at(table.unpack(pairs[1])) end 76 end, 'Goto selected "file:line:[col:]"') 77 end) 78 79 vis:command_register("ag", function(argv) 80 util.message_clear(vis) 81 local outstr = "" 82 for _, arg in ipairs(argv) do 83 local _, out = vis:pipe("ag -Q --column " .. arg) 84 if out then 85 vis:message(out) 86 outstr = outstr .. out 87 end 88 end 89 gf.setup_iterators_from_text(outstr) 90 end, "Search for each literal in argv with the_silver_searcher") 91 92 vis:command_register("cp", function(argv) 93 local text = vis.win.file:content(vis.win.selection.range) 94 vis:pipe(text, "vis-clipboard --copy") 95 end, "Copy Selection to Clipboard") 96 97 local extra_word_lists = {} 98 extra_word_lists['c'] = { 99 keyword = {'alignof', 'countof', 'force_inline', 'function', 'global', 'local_persist', 100 'no_return', 'read_only', 'typeof'}, 101 -- type = {'Arena', 'str8', ...}, 102 } 103 104 vis.events.subscribe(vis.events.WIN_OPEN, function(win) 105 win.options = { 106 colorcolumn = 100, 107 relativenumbers = true, 108 tabwidth = tabwidth, 109 } 110 111 local m, cmd = vis.modes, util.command 112 -- pass some args to fmt(1) 113 local fmtcmd = ":|fmt -l %d -w 66" 114 local fmt = cmd(fmtcmd:format(win.options.tabwidth)) 115 win:map(m.NORMAL, "=", fmt) 116 win:map(m.VISUAL, "=", fmt) 117 118 if vis.lexers.load and win.syntax and extra_word_lists[win.syntax] then 119 local lexer = vis.lexers.load(win.syntax, nil, true) 120 if lexer then 121 for key, word_list in pairs(extra_word_lists[win.syntax]) do 122 lexer:set_word_list(key, word_list, true) 123 end 124 end 125 end 126 end) 127 128 vis.events.subscribe(vis.events.WIN_CLOSE, function(win) 129 local f, e = util.splitext(win.file.name) 130 if e == '.tex' then 131 vis:command("!texclean " .. f .. e) 132 end 133 end)