visrc.lua (3984B)
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 } 64 65 local m, cmd = vis.modes, util.command 66 vis:map(m.NORMAL, " f", "v$:|furigana<Enter><Escape>") 67 vis:map(m.NORMAL, " j", "<vis-window-next>") 68 vis:map(m.NORMAL, " k", "<vis-window-prev>") 69 vis:map(m.NORMAL, "gq", "vip=<Escape>") 70 vis:map(m.VISUAL, " s", cmd("|sort")) 71 72 vis:map(m.NORMAL, "vo", cmd("x/[ \t\r]+$/ d"), 73 "remove whitespace from end of all lines") 74 75 vis:map(m.NORMAL, " l", function() 76 local ui = vis.ui 77 if ui.layout == ui.layouts.HORIZONTAL then 78 ui.layout = ui.layouts.VERTICAL 79 else 80 ui.layout = ui.layouts.HORIZONTAL 81 end 82 end, "swap ui layout") 83 84 vis:map(m.NORMAL, " i", function() 85 local fn = vis.win.file.name 86 vis:message("syntax = " .. tostring(vis.win.syntax)) 87 vis:message("file.name = " .. (fn and fn or "nil")) 88 end, "dump info to message window") 89 90 vis:map(m.VISUAL, "gf", function() file_search(true) end, 'Goto selected "file:line:[col:]"') 91 vis:map(m.VISUAL, "gr", function() file_search(false) end, 'Generate references for selected') 92 end) 93 94 vis:command_register("ag", function(argv) 95 ag(argv) 96 end, "Search for each literal in argv with the_silver_searcher") 97 98 vis:command_register("cp", function(argv) 99 local text = vis.win.file:content(vis.win.selection.range) 100 vis:pipe(text, "vis-clipboard --copy") 101 end, "Copy Selection to Clipboard") 102 103 local extra_word_lists = {} 104 extra_word_lists['c'] = { 105 keyword = { 106 'alignof', 107 'assert', 108 'assume', 109 'countof', 110 'debugbreak', 111 'force_inline', 112 'function', 113 'global', 114 'likely', 115 'local_persist', 116 'no_return', 117 'read_only', 118 'static_assert', 119 'thread_static', 120 'typeof', 121 'unlikely', 122 }, 123 -- type = {'Arena', 'str8', ...}, 124 } 125 126 vis.events.subscribe(vis.events.WIN_OPEN, function(win) 127 win.options = { 128 colorcolumn = 100, 129 relativenumbers = true, 130 numberwidth = 6, 131 tabwidth = tabwidth, 132 } 133 134 local m, cmd = vis.modes, util.command 135 -- pass some args to fmt(1) 136 local fmtcmd = ":|fmt -l %d -w 66" 137 local fmt = cmd(fmtcmd:format(win.options.tabwidth)) 138 win:map(m.NORMAL, "=", fmt) 139 win:map(m.VISUAL, "=", fmt) 140 141 if vis.lexers.load and win.syntax and extra_word_lists[win.syntax] then 142 local lexer = vis.lexers.load(win.syntax, nil, true) 143 if lexer then 144 for key, word_list in pairs(extra_word_lists[win.syntax]) do 145 lexer:set_word_list(key, word_list, true) 146 end 147 end 148 end 149 end) 150 151 vis.events.subscribe(vis.events.WIN_CLOSE, function(win) 152 local f, e = util.splitext(win.file.name) 153 if e == '.tex' then 154 vis:command("!texclean " .. f .. e) 155 end 156 end)