visrc.lua (4002B)
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.extensions.m = "matlab" 26 27 vis.ftdetect.extensions.odin = "c" 28 vis.ftdetect.extensions.slang = "cpp" 29 30 lint.fixers.python = {} 31 32 local ag = function(argv) 33 util.message_clear(vis) 34 local outstr = "" 35 for _, arg in ipairs(argv) do 36 local _, out = vis:pipe("ag -Q --column " .. arg) 37 if out then 38 vis:message(out) 39 outstr = outstr .. out 40 end 41 end 42 gf.setup_iterators_from_text(outstr) 43 end 44 45 local file_search = function(goto_ref) 46 local sel = vis.win.selection 47 local data = vis.win.file:content(sel.range) 48 vis.mode = vis.modes.NORMAL 49 50 if goto_ref then 51 local pairs = gf.generate_line_indices(data) 52 if pairs and pairs[1] then gf.focus_file_at(table.unpack(pairs[1])) end 53 else 54 ag({data}) 55 end 56 end 57 58 vis.events.subscribe(vis.events.INIT, function() 59 vis:command("set theme term") 60 61 vis.options = { 62 autoindent = true, 63 escdelay = 1, 64 } 65 66 local m, cmd = vis.modes, util.command 67 vis:map(m.NORMAL, " f", "v$:|furigana<Enter><Escape>") 68 vis:map(m.NORMAL, " j", "<vis-window-next>") 69 vis:map(m.NORMAL, " k", "<vis-window-prev>") 70 vis:map(m.NORMAL, "gq", "vip=<Escape>") 71 vis:map(m.VISUAL, " s", cmd("|sort")) 72 73 vis:map(m.NORMAL, "vo", cmd("x/[ \t\r]+$/ d"), 74 "remove whitespace from end of all lines") 75 76 vis:map(m.NORMAL, " l", function() 77 local ui = vis.ui 78 if ui.layout == ui.layouts.HORIZONTAL then 79 ui.layout = ui.layouts.VERTICAL 80 else 81 ui.layout = ui.layouts.HORIZONTAL 82 end 83 end, "swap ui layout") 84 85 vis:map(m.NORMAL, " i", function() 86 local fn = vis.win.file.name 87 vis:message("syntax = " .. tostring(vis.win.syntax)) 88 vis:message("file.name = " .. (fn and fn or "nil")) 89 end, "dump info to message window") 90 91 vis:map(m.VISUAL, "gf", function() file_search(true) end, 'Goto selected "file:line:[col:]"') 92 vis:map(m.VISUAL, "gr", function() file_search(false) end, 'Generate references for selected') 93 end) 94 95 vis:command_register("ag", function(argv) 96 ag(argv) 97 end, "Search for each literal in argv with the_silver_searcher") 98 99 vis:command_register("cp", function(argv) 100 local text = vis.win.file:content(vis.win.selection.range) 101 vis:pipe(text, "vis-clipboard --copy") 102 end, "Copy Selection to Clipboard") 103 104 local extra_word_lists = {} 105 extra_word_lists['c'] = { 106 keyword = { 107 'alignof', 108 'assert', 109 'assume', 110 'countof', 111 'debugbreak', 112 'force_inline', 113 'function', 114 'global', 115 'likely', 116 'local_persist', 117 'no_return', 118 'read_only', 119 'static_assert', 120 'thread_static', 121 'typeof', 122 'unlikely', 123 }, 124 -- type = {'Arena', 'str8', ...}, 125 } 126 127 vis.events.subscribe(vis.events.WIN_OPEN, function(win) 128 win.options = { 129 colorcolumn = 100, 130 relativenumbers = true, 131 numberwidth = 6, 132 tabwidth = tabwidth, 133 } 134 135 local m, cmd = vis.modes, util.command 136 -- pass some args to fmt(1) 137 local fmtcmd = ":|fmt -l %d -w 66" 138 local fmt = cmd(fmtcmd:format(win.options.tabwidth)) 139 win:map(m.NORMAL, "=", fmt) 140 win:map(m.VISUAL, "=", fmt) 141 142 if vis.lexers.load and win.syntax and extra_word_lists[win.syntax] then 143 local lexer = vis.lexers.load(win.syntax, nil, true) 144 if lexer then 145 for key, word_list in pairs(extra_word_lists[win.syntax]) do 146 lexer:set_word_list(key, word_list, true) 147 end 148 end 149 end 150 end) 151 152 vis.events.subscribe(vis.events.WIN_CLOSE, function(win) 153 local f, e = util.splitext(win.file.name) 154 if e == '.tex' then 155 vis:command("!texclean " .. f .. e) 156 end 157 end)