dotfiles

personal dotfiles
git clone anongit@rnpnr.xyz:dotfiles.git
Log | Files | Refs | Feed | Submodules

visrc.lua (2998B)


      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 mww = 72 -- Min Window Width
     21 
     22 -- detect matlab with %.m not objective_c
     23 vis.ftdetect.filetypes.matlab = { ext = { "%.m$" } }
     24 assert(table.remove(vis.ftdetect.filetypes.objective_c.ext, 1) == "%.m$")
     25 
     26 -- use smaller tabs for heavily nested matlab classes and latex
     27 vis.ftdetect.filetypes.latex.cmd  = { "set tw 4" }
     28 vis.ftdetect.filetypes.matlab.cmd = { "set tw 4" }
     29 
     30 vis.ftdetect.filetypes.haskell.cmd = { "set tw 4", "set expandtab true" }
     31 lint.fixers["haskell"] = { "hindent --indent-size 4 --sort-imports" }
     32 
     33 lint.fixers["python"] = {} -- {"black -l 80 -q -"}
     34 vis.ftdetect.filetypes.python.cmd = { "set tw 4", "set expandtab true" }
     35 
     36 vis.ftdetect.filetypes.yaml.cmd = { "set tw 2", "set expandtab true" }
     37 
     38 vis.events.subscribe(vis.events.INIT, function()
     39 	vis:command("set theme term")
     40 
     41 	vis.options = { autoindent = true }
     42 
     43 	local m, cmd = vis.modes, util.command
     44 	vis:map(m.NORMAL, " f", "v$:|furigana<Enter><Escape>")
     45 	vis:map(m.NORMAL, " j", "<vis-window-next>")
     46 	vis:map(m.NORMAL, " k", "<vis-window-prev>")
     47 	vis:map(m.NORMAL, "gq", "vip=<Escape>")
     48 	vis:map(m.VISUAL, " s", cmd("|sort"))
     49 
     50 	vis:map(m.NORMAL, "vo", cmd("x/[ \t\r]+$/ d"),
     51 	        "remove whitespace from end of all lines")
     52 
     53 	vis:map(m.NORMAL, " l", function()
     54 		local ui = vis.ui
     55 		if ui.layout == ui.layouts.HORIZONTAL then
     56 			ui.layout = ui.layouts.VERTICAL
     57 		else
     58 			ui.layout = ui.layouts.HORIZONTAL
     59 		end
     60 	end, "swap ui layout")
     61 
     62 	vis:map(m.NORMAL, " i", function()
     63 		local fn = vis.win.file.name
     64 		vis:message("syntax = " .. tostring(vis.win.syntax))
     65 		vis:message("file.name = " .. fn)
     66 	end, "dump info to message window")
     67 end)
     68 
     69 vis:command_register("ag", function(argv)
     70 	util.message_clear(vis)
     71 	local outstr = ""
     72 	for _, arg in ipairs(argv) do
     73 		local _, out = vis:pipe("ag -Q --column " .. arg)
     74 		if out then
     75 			vis:message(out)
     76 			outstr = outstr .. out
     77 		end
     78 	end
     79 	gf.setup_iterators_from_text(outstr)
     80 end, "Search for each literal in argv with the_silver_searcher")
     81 
     82 vis.events.subscribe(vis.events.WIN_OPEN, function(win)
     83 	win.options = {
     84 		colorcolumn = 100,
     85 		relativenumbers = true,
     86 	}
     87 
     88 	local m, cmd = vis.modes, util.command
     89 	-- pass some args to fmt(1)
     90 	local fmtcmd = ":|fmt -l %d -w 66"
     91 	local fmt = cmd(fmtcmd:format(win.options.tabwidth))
     92 	win:map(m.NORMAL, "=", fmt)
     93 	win:map(m.VISUAL, "=", fmt)
     94 end)
     95 
     96 vis.events.subscribe(vis.events.WIN_CLOSE, function(win)
     97 	local f, e = util.splitext(win.file.name)
     98 	if e == '.tex' then
     99 		vis:command("!texclean " .. f .. e)
    100 	end
    101 end)