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