config. vis-editor
This commit is contained in:
parent
8e46846a7e
commit
b44b812894
|
@ -0,0 +1,10 @@
|
|||
-- Paste from system clipboard with vis-clipboard
|
||||
vis:map(vis.modes.NORMAL, '<C-v>', '"+p')
|
||||
-- Put register content after cursor from system clipboard with vis-clipoard
|
||||
-- Change the 'a' to an 'i' if you want it before the cursor
|
||||
vis:map(vis.modes.INSERT, '<C-v>', '<Escape>"+pa')
|
||||
|
||||
-- Put selection content into system clipboard
|
||||
vis:map(vis.modes.VISUAL_LINE, '<C-c>', function() vis:feedkeys(':>vis-clipboard --copy<Enter>') end)
|
||||
-- TODO this doesn't work with multiple cursors, just gets last selection
|
||||
vis:map(vis.modes.VISUAL, '<C-c>', function() vis:feedkeys(':>vis-clipboard --copy<Enter>') end)
|
|
@ -0,0 +1,609 @@
|
|||
vis.ftdetect = {}
|
||||
|
||||
vis.ftdetect.ignoresuffixes = {
|
||||
"~$", "%.orig$", "%.bak$", "%.old$", "%.new$"
|
||||
}
|
||||
|
||||
vis.ftdetect.filetypes = {
|
||||
actionscript = {
|
||||
ext = { "%.as$", "%.asc$" },
|
||||
},
|
||||
ada = {
|
||||
ext = { "%.adb$", "%.ads$" },
|
||||
},
|
||||
ansi_c = {
|
||||
ext = { "%.c$", "%.C$", "%.h$" },
|
||||
mime = { "text/x-c" },
|
||||
},
|
||||
antlr = {
|
||||
ext = { "%.g$", "%.g4$" },
|
||||
},
|
||||
apdl = {
|
||||
ext = { "%.ans$", "%.inp$", "%.mac$" },
|
||||
},
|
||||
apl = {
|
||||
ext = { "%.apl$" }
|
||||
},
|
||||
applescript = {
|
||||
ext = { "%.applescript$" },
|
||||
},
|
||||
asm = {
|
||||
ext = { "%.asm$", "%.ASM$", "%.s$", "%.S$" },
|
||||
},
|
||||
asp = {
|
||||
ext = { "%.asa$", "%.asp$", "%.hta$" },
|
||||
},
|
||||
autoit = {
|
||||
ext = { "%.au3$", "%.a3x$" },
|
||||
},
|
||||
awk = {
|
||||
hashbang = { "^/usr/bin/[mng]awk%s+%-f" },
|
||||
utility = { "^[mgn]?awk$", "^goawk$" },
|
||||
ext = { "%.awk$" },
|
||||
},
|
||||
bash = {
|
||||
utility = { "^[db]ash$", "^sh$","^t?csh$","^zsh$" },
|
||||
ext = { "%.bash$", "%.csh$", "%.sh$", "%.zsh$" ,"^APKBUILD$", "%.ebuild$", "^.bashrc$", "^.bash_profile$" },
|
||||
mime = { "text/x-shellscript", "application/x-shellscript" },
|
||||
},
|
||||
batch = {
|
||||
ext = { "%.bat$", "%.cmd$" },
|
||||
},
|
||||
bibtex = {
|
||||
ext = { "%.bib$" },
|
||||
},
|
||||
boo = {
|
||||
ext = { "%.boo$" },
|
||||
},
|
||||
caml = {
|
||||
ext = { "%.caml$", "%.ml$", "%.mli$", "%.mll$", "%.mly$" },
|
||||
},
|
||||
chuck = {
|
||||
ext = { "%.ck$" },
|
||||
},
|
||||
clojure = {
|
||||
ext = { "%.clj$", "%.cljc$", "%.cljs$", "%.edn$" }
|
||||
},
|
||||
cmake = {
|
||||
ext = { "%.cmake$", "%.cmake.in$", "%.ctest$", "%.ctest.in$" },
|
||||
},
|
||||
coffeescript = {
|
||||
ext = { "%.coffee$" },
|
||||
mime = { "text/x-coffee" },
|
||||
},
|
||||
cpp = {
|
||||
ext = { "%.cpp$", "%.cxx$", "%.c++$", "%.cc$", "%.hh$", "%.hpp$", "%.hxx$", "%.h++$" },
|
||||
mime = { "text/x-c++" },
|
||||
},
|
||||
crontab = {
|
||||
ext = { "^crontab.*$" },
|
||||
cmd = { "set savemethod inplace" },
|
||||
},
|
||||
crystal = {
|
||||
ext = { "%.cr$" },
|
||||
},
|
||||
csharp = {
|
||||
ext = { "%.cs$" },
|
||||
},
|
||||
css = {
|
||||
ext = { "%.css$" },
|
||||
mime = { "text/x-css" },
|
||||
},
|
||||
cuda = {
|
||||
ext = { "%.cu$", "%.cuh$" },
|
||||
},
|
||||
dart = {
|
||||
ext = { "%.dart$" },
|
||||
},
|
||||
desktop = {
|
||||
ext = { "%.desktop$" },
|
||||
},
|
||||
diff = {
|
||||
ext = { "%.diff$", "%.patch$", "%.rej$", "^COMMIT_EDITMSG$" },
|
||||
cmd = { "set colorcolumn 72" },
|
||||
},
|
||||
dmd = {
|
||||
ext = { "%.d$", "%.di$" },
|
||||
},
|
||||
dockerfile = {
|
||||
ext = { "^Dockerfile$", "%.Dockerfile$" },
|
||||
},
|
||||
dot = {
|
||||
ext = { "%.dot$" },
|
||||
},
|
||||
dsv = {
|
||||
ext = { "^group$", "^gshadow$", "^passwd$", "^shadow$" },
|
||||
},
|
||||
eiffel = {
|
||||
ext = { "%.e$", "%.eif$" },
|
||||
},
|
||||
elixir = {
|
||||
ext = { "%.ex$", "%.exs$" },
|
||||
},
|
||||
elm = {
|
||||
ext = { "%.elm$" },
|
||||
},
|
||||
erlang = {
|
||||
ext = { "%.erl$", "%.hrl$" },
|
||||
},
|
||||
fantom = {
|
||||
ext = { "%.fan$" },
|
||||
},
|
||||
faust = {
|
||||
ext = { "%.dsp$" },
|
||||
},
|
||||
fennel = {
|
||||
ext = { "%.fnl$" },
|
||||
},
|
||||
fish = {
|
||||
utility = { "^fish$" },
|
||||
ext = { "%.fish$" },
|
||||
},
|
||||
forth = {
|
||||
ext = { "%.forth$", "%.frt$", "%.fs$", "%.fth$" },
|
||||
},
|
||||
fortran = {
|
||||
ext = { "%.f$", "%.for$", "%.ftn$", "%.fpp$", "%.f77$", "%.f90$", "%.f95$", "%.f03$", "%.f08$" },
|
||||
},
|
||||
fsharp = {
|
||||
ext = { "%.fs$" },
|
||||
},
|
||||
fstab = {
|
||||
ext = { "fstab" },
|
||||
},
|
||||
gap = {
|
||||
ext = { "%.g$", "%.gd$", "%.gi$", "%.gap$" },
|
||||
},
|
||||
gemini = {
|
||||
ext = { "%.gmi" },
|
||||
mime = { "text/gemini" },
|
||||
},
|
||||
gettext = {
|
||||
ext = { "%.po$", "%.pot$" },
|
||||
},
|
||||
gherkin = {
|
||||
ext = { "%.feature$" },
|
||||
},
|
||||
['git-rebase'] = {
|
||||
ext = { "git%-rebase%-todo" },
|
||||
},
|
||||
glsl = {
|
||||
ext = { "%.glslf$", "%.glslv$" },
|
||||
},
|
||||
gnuplot = {
|
||||
ext = { "%.dem$", "%.plt$" },
|
||||
},
|
||||
go = {
|
||||
ext = { "%.go$" },
|
||||
},
|
||||
groovy = {
|
||||
ext = { "%.groovy$", "%.gvy$", "^Jenkinsfile$" },
|
||||
},
|
||||
gtkrc = {
|
||||
ext = { "%.gtkrc$" },
|
||||
},
|
||||
hare = {
|
||||
ext = { "%.ha$" }
|
||||
},
|
||||
haskell = {
|
||||
ext = { "%.hs$" },
|
||||
mime = { "text/x-haskell" },
|
||||
},
|
||||
html = {
|
||||
ext = { "%.htm$", "%.html$", "%.shtm$", "%.shtml$", "%.xhtml$" },
|
||||
mime = { "text/x-html" },
|
||||
},
|
||||
icon = {
|
||||
ext = { "%.icn$" },
|
||||
},
|
||||
idl = {
|
||||
ext = { "%.idl$", "%.odl$" },
|
||||
},
|
||||
inform = {
|
||||
ext = { "%.inf$", "%.ni$" },
|
||||
},
|
||||
ini = {
|
||||
ext = { "%.cfg$", "%.cnf$", "%.conf$", "%.inf$", "%.ini$", "%.reg$" },
|
||||
},
|
||||
io_lang = {
|
||||
ext = { "%.io$" },
|
||||
},
|
||||
java = {
|
||||
ext = { "%.bsh$", "%.java$" },
|
||||
},
|
||||
javascript = {
|
||||
ext = { "%.cjs$", "%.js$", "%.jsfl$", "%.mjs$", "%.ts$", "%.jsx$", "%.tsx$" },
|
||||
},
|
||||
json = {
|
||||
ext = { "%.json$" },
|
||||
mime = { "text/x-json" },
|
||||
},
|
||||
jsp = {
|
||||
ext = { "%.jsp$" },
|
||||
},
|
||||
julia = {
|
||||
ext = { "%.jl$" },
|
||||
},
|
||||
latex = {
|
||||
ext = { "%.bbl$", "%.cls$", "%.dtx$", "%.ins$", "%.ltx$", "%.tex$", "%.sty$" },
|
||||
mime = { "text/x-tex" },
|
||||
},
|
||||
ledger = {
|
||||
ext = { "%.ledger$", "%.journal$" },
|
||||
},
|
||||
less = {
|
||||
ext = { "%.less$" },
|
||||
},
|
||||
lilypond = {
|
||||
ext = { "%.ily$", "%.ly$" },
|
||||
},
|
||||
lisp = {
|
||||
ext = { "%.cl$", "%.el$", "%.lisp$", "%.lsp$" },
|
||||
mime = { "text/x-lisp" },
|
||||
},
|
||||
litcoffee = {
|
||||
ext = { "%.litcoffee$" },
|
||||
},
|
||||
logtalk = {
|
||||
ext = { "%.lgt$" },
|
||||
},
|
||||
lua = {
|
||||
utility = {"^lua%-?5?%d?$", "^lua%-?5%.%d$" },
|
||||
ext = { "%.lua$" },
|
||||
mime = { "text/x-lua" },
|
||||
},
|
||||
makefile = {
|
||||
hashbang = {"^#!/usr/bin/make"},
|
||||
utility = {"^make$"},
|
||||
ext = { "%.iface$", "%.mak$", "%.mk$", "GNUmakefile", "makefile", "Makefile" },
|
||||
mime = { "text/x-makefile" },
|
||||
},
|
||||
man = {
|
||||
ext = {
|
||||
"%.1$", "%.2$", "%.3$", "%.4$", "%.5$", "%.6$", "%.7$",
|
||||
"%.8$", "%.9$", "%.1x$", "%.2x$", "%.3x$", "%.4x$",
|
||||
"%.5x$", "%.6x$", "%.7x$", "%.8x$", "%.9x$"
|
||||
},
|
||||
},
|
||||
markdown = {
|
||||
ext = { "%.md$", "%.markdown$" },
|
||||
mime = { "text/x-markdown" },
|
||||
},
|
||||
meson = {
|
||||
ext = { "^meson%.build$" },
|
||||
},
|
||||
moonscript = {
|
||||
ext = { "%.moon$" },
|
||||
mime = { "text/x-moon" },
|
||||
},
|
||||
myrddin = {
|
||||
ext = { "%.myr$" },
|
||||
},
|
||||
nemerle = {
|
||||
ext = { "%.n$" },
|
||||
},
|
||||
networkd = {
|
||||
ext = { "%.link$", "%.network$", "%.netdev$" },
|
||||
},
|
||||
nim = {
|
||||
ext = { "%.nim$" },
|
||||
},
|
||||
nsis = {
|
||||
ext = { "%.nsh$", "%.nsi$", "%.nsis$" },
|
||||
},
|
||||
objective_c = {
|
||||
ext = { "%.m$", "%.mm$", "%.objc$" },
|
||||
mime = { "text/x-objc" },
|
||||
},
|
||||
pascal = {
|
||||
ext = { "%.dpk$", "%.dpr$", "%.p$", "%.pas$" },
|
||||
},
|
||||
perl = {
|
||||
ext = { "%.al$", "%.perl$", "%.pl$", "%.pm$", "%.pod$" },
|
||||
mime = { "text/x-perl" },
|
||||
},
|
||||
php = {
|
||||
ext = { "%.inc$", "%.php$", "%.php3$", "%.php4$", "%.phtml$" },
|
||||
},
|
||||
pico8 = {
|
||||
ext = { "%.p8$" },
|
||||
},
|
||||
pike = {
|
||||
ext = { "%.pike$", "%.pmod$" },
|
||||
},
|
||||
pkgbuild = {
|
||||
ext = { "^PKGBUILD$", "%.PKGBUILD$" },
|
||||
},
|
||||
pony = {
|
||||
ext = { "%.pony$" },
|
||||
},
|
||||
powershell = {
|
||||
ext = { "%.ps1$" },
|
||||
},
|
||||
prolog = {
|
||||
ext = { "%.pl$", "%.pro$", "%.prolog$" },
|
||||
},
|
||||
props = {
|
||||
ext = { "%.props$", "%.properties$" },
|
||||
},
|
||||
protobuf = {
|
||||
ext = { "%.proto$" },
|
||||
},
|
||||
ps = {
|
||||
ext = { "%.eps$", "%.ps$" },
|
||||
},
|
||||
pure = {
|
||||
ext = { "%.pure$" },
|
||||
},
|
||||
python = {
|
||||
utility = { "^python%d?" },
|
||||
ext = { "%.sc$", "%.py$", "%.pyw$" },
|
||||
mime = { "text/x-python", "text/x-script.python" },
|
||||
},
|
||||
reason = {
|
||||
ext = { "%.re$" },
|
||||
},
|
||||
rc = {
|
||||
utility = {"^rc$"},
|
||||
ext = { "%.rc$", "%.es$" },
|
||||
},
|
||||
rebol = {
|
||||
ext = { "%.r$", "%.reb$" },
|
||||
},
|
||||
rest = {
|
||||
ext = { "%.rst$" },
|
||||
},
|
||||
rexx = {
|
||||
ext = { "%.orx$", "%.rex$" },
|
||||
},
|
||||
rhtml = {
|
||||
ext = { "%.erb$", "%.rhtml$" },
|
||||
},
|
||||
routeros = {
|
||||
ext = { "%.rsc" },
|
||||
detect = function(_, data)
|
||||
return data:match("^#.* by RouterOS")
|
||||
end
|
||||
},
|
||||
rstats = {
|
||||
ext = { "%.R$", "%.Rout$", "%.Rhistory$", "%.Rt$", "Rout.save", "Rout.fail" },
|
||||
},
|
||||
ruby = {
|
||||
ext = { "%.Rakefile$", "%.rake$", "%.rb$", "%.rbw$", "^Vagrantfile$" },
|
||||
mime = { "text/x-ruby" },
|
||||
},
|
||||
rust = {
|
||||
ext = { "%.rs$" },
|
||||
mime = { "text/x-rust" },
|
||||
},
|
||||
sass = {
|
||||
ext = { "%.sass$", "%.scss$" },
|
||||
mime = { "text/x-sass", "text/x-scss" },
|
||||
},
|
||||
scala = {
|
||||
ext = { "%.scala$" },
|
||||
mime = { "text/x-scala" },
|
||||
},
|
||||
scheme = {
|
||||
ext = { "%.rkt$", "%.sch$", "%.scm$", "%.sld$", "%.sls$", "%.ss$" },
|
||||
},
|
||||
smalltalk = {
|
||||
ext = { "%.changes$", "%.st$", "%.sources$" },
|
||||
},
|
||||
sml = {
|
||||
ext = { "%.sml$", "%.fun$", "%.sig$" },
|
||||
},
|
||||
snobol4 = {
|
||||
ext = { "%.sno$", "%.SNO$" },
|
||||
},
|
||||
spin = {
|
||||
ext = { "%.spin$" }
|
||||
},
|
||||
sql= {
|
||||
ext = { "%.ddl$", "%.sql$" },
|
||||
},
|
||||
strace = {
|
||||
detect = function(_, data)
|
||||
return data:match("^execve%(")
|
||||
end
|
||||
},
|
||||
systemd = {
|
||||
ext = {
|
||||
"%.automount$", "%.device$", "%.mount$", "%.path$",
|
||||
"%.scope$", "%.service$", "%.slice$", "%.socket$",
|
||||
"%.swap$", "%.target$", "%.timer$"
|
||||
},
|
||||
},
|
||||
taskpaper = {
|
||||
ext = { "%.taskpaper$" },
|
||||
},
|
||||
tcl = {
|
||||
utility = {"^tclsh$", "^jimsh$" },
|
||||
ext = { "%.tcl$", "%.tk$" },
|
||||
},
|
||||
texinfo = {
|
||||
ext = { "%.texi$" },
|
||||
},
|
||||
text = {
|
||||
ext = { "%.txt$" },
|
||||
-- Do *not* list mime "text/plain" here, it is covered below,
|
||||
-- see 'try text lexer as a last resort'
|
||||
},
|
||||
toml = {
|
||||
ext = { "%.toml$" },
|
||||
},
|
||||
vala = {
|
||||
ext = { "%.vala$" }
|
||||
},
|
||||
vb = {
|
||||
ext = {
|
||||
"%.asa$", "%.bas$", "%.ctl$", "%.dob$",
|
||||
"%.dsm$", "%.dsr$", "%.frm$", "%.pag$", "%.vb$",
|
||||
"%.vba$", "%.vbs$"
|
||||
},
|
||||
},
|
||||
vcard = {
|
||||
ext = { "%.vcf$", "%.vcard$" },
|
||||
},
|
||||
verilog = {
|
||||
ext = { "%.v$", "%.ver$", "%.sv$" },
|
||||
},
|
||||
vhdl = {
|
||||
ext = { "%.vh$", "%.vhd$", "%.vhdl$" },
|
||||
},
|
||||
wsf = {
|
||||
ext = { "%.wsf$" },
|
||||
},
|
||||
xs = {
|
||||
ext = { "%.xs$", "^%.xsin$", "^%.xsrc$" },
|
||||
},
|
||||
xml = {
|
||||
ext = {
|
||||
"%.dtd$", "%.glif$", "%.plist$", "%.svg$", "%.xml$",
|
||||
"%.xsd$", "%.xsl$", "%.xslt$", "%.xul$"
|
||||
},
|
||||
},
|
||||
xtend = {
|
||||
ext = {"%.xtend$" },
|
||||
},
|
||||
yaml = {
|
||||
ext = { "%.yaml$", "%.yml$" },
|
||||
mime = { "text/x-yaml" },
|
||||
},
|
||||
zig = {
|
||||
ext = { "%.zig$" },
|
||||
},
|
||||
}
|
||||
|
||||
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
||||
|
||||
local set_filetype = function(syntax, filetype)
|
||||
for _, cmd in pairs(filetype.cmd or {}) do
|
||||
vis:command(cmd)
|
||||
end
|
||||
win:set_syntax(syntax)
|
||||
end
|
||||
|
||||
local name = win.file.name
|
||||
-- remove ignored suffixes from filename
|
||||
local sanitizedfn = name
|
||||
if sanitizedfn ~= nil then
|
||||
sanitizedfn = sanitizedfn:gsub('^.*/', '')
|
||||
repeat
|
||||
local changed = false
|
||||
for _, pattern in pairs(vis.ftdetect.ignoresuffixes) do
|
||||
local start = sanitizedfn:find(pattern)
|
||||
if start then
|
||||
sanitizedfn = sanitizedfn:sub(1, start-1)
|
||||
changed = true
|
||||
end
|
||||
end
|
||||
until not changed
|
||||
end
|
||||
|
||||
-- detect filetype by filename ending with a configured extension
|
||||
if sanitizedfn ~= nil then
|
||||
for lang, ft in pairs(vis.ftdetect.filetypes) do
|
||||
for _, pattern in pairs(ft.ext or {}) do
|
||||
if sanitizedfn:match(pattern) then
|
||||
set_filetype(lang, ft)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- run file(1) to determine mime type
|
||||
local mime
|
||||
if name ~= nil then
|
||||
local file = io.popen(string.format("file -bL --mime-type -- '%s'", name:gsub("'", "'\\''")))
|
||||
if file then
|
||||
mime = file:read('*all')
|
||||
file:close()
|
||||
if mime then
|
||||
mime = mime:gsub('%s*$', '')
|
||||
end
|
||||
if mime and #mime > 0 then
|
||||
for lang, ft in pairs(vis.ftdetect.filetypes) do
|
||||
for _, ft_mime in pairs(ft.mime or {}) do
|
||||
if mime == ft_mime then
|
||||
set_filetype(lang, ft)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- pass first few bytes of file to custom file type detector functions
|
||||
local file = win.file
|
||||
local data = file:content(0, 256)
|
||||
if data and #data > 0 then
|
||||
for lang, ft in pairs(vis.ftdetect.filetypes) do
|
||||
if type(ft.detect) == 'function' and ft.detect(file, data) then
|
||||
set_filetype(lang, ft)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
--[[ hashbang check
|
||||
hashbangs only have command <SPACE> argument
|
||||
if /env, find utility in args
|
||||
discard first arg if /-[^S]*S/; and all subsequent /=/
|
||||
NOTE: this means you can't have a command with /^-|=/
|
||||
return first field, which should be the utility.
|
||||
NOTE: long-options unsupported
|
||||
--]]
|
||||
local fullhb, utility = data:match"^#![ \t]*(/+[^/\n]+[^\n]*)"
|
||||
if fullhb then
|
||||
local i, field = 1, {}
|
||||
for m in fullhb:gmatch"%g+" do field[i],i = m,i+1 end
|
||||
-- NOTE: executables should not have a space (or =, see below)
|
||||
if field[1]:match"/env$" then
|
||||
table.remove(field,1)
|
||||
-- it is assumed that the first argument are short options, with -S inside
|
||||
if string.match(field[1] or "", "^%-[^S-]*S") then -- -S found
|
||||
table.remove(field,1)
|
||||
-- skip all name=value
|
||||
while string.match(field[1] or "","=") do
|
||||
table.remove(field,1)
|
||||
end
|
||||
-- (hopefully) whatever is left in field[1] should be the utility or nil
|
||||
end
|
||||
end
|
||||
utility = string.match(field[1] or "", "[^/]+$") -- remove filepath
|
||||
end
|
||||
|
||||
local function searcher(tbl, subject)
|
||||
for i, pattern in ipairs(tbl or {}) do
|
||||
if string.match(subject, pattern) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
if utility or fullhb then
|
||||
for lang, ft in pairs(vis.ftdetect.filetypes) do
|
||||
if
|
||||
utility and searcher(ft.utility, utility)
|
||||
or
|
||||
fullhb and searcher(ft.hashbang, fullhb)
|
||||
then
|
||||
set_filetype(lang, ft)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- try text lexer as a last resort
|
||||
if (mime or 'text/plain'):match('^text/.+$') then
|
||||
set_filetype('text', vis.ftdetect.filetypes.text)
|
||||
return
|
||||
end
|
||||
|
||||
win:set_syntax(nil)
|
||||
end)
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
-- Created: 2016-05-13
|
||||
-- Modified: Mon 17 Jul 2017
|
||||
-- Author: Josh Wainwright
|
||||
-- Filename: statusline.lua
|
||||
|
||||
local suffixes = {'B', 'KB', 'MB', 'GB', 'TB'}
|
||||
local human_bytes = function(bytes)
|
||||
if bytes <= 0 then
|
||||
return ''
|
||||
end
|
||||
local n = 1
|
||||
while bytes >= 1024 do
|
||||
n = n + 1
|
||||
bytes = bytes / 1024
|
||||
end
|
||||
return string.format('%.2f', bytes) .. suffixes[n]
|
||||
end
|
||||
|
||||
local modes = {
|
||||
[vis.modes.NORMAL] = '',
|
||||
[vis.modes.OPERATOR_PENDING] = 'OPERATOR',
|
||||
[vis.modes.VISUAL] = 'VISUAL',
|
||||
[vis.modes.VISUAL_LINE] = 'VISUAL-LINE',
|
||||
[vis.modes.INSERT] = 'INSERT',
|
||||
[vis.modes.REPLACE] = 'REPLACE',
|
||||
}
|
||||
|
||||
vis.events.win_status = function(win)
|
||||
local left = {}
|
||||
local right = {}
|
||||
|
||||
local mode = modes[vis.mode]
|
||||
if mode ~= '' and vis.win == win then
|
||||
left[#left+1] = mode
|
||||
end
|
||||
|
||||
local file = win.file
|
||||
left[#left+1] = (file.name or '[No Name]') ..
|
||||
(file.modified and ' [+]' or '') ..
|
||||
(vis.recording and ' @' or '')
|
||||
if win.syntax ~= '' then
|
||||
left[#left+1] = win.syntax
|
||||
end
|
||||
|
||||
if file.newlines ~= "nl" then
|
||||
right[#right+1] = file.newlines
|
||||
end
|
||||
|
||||
local size = file.size
|
||||
local selection = win.selection
|
||||
local pos = selection.pos or 0
|
||||
right[#right+1] = human_bytes(size)
|
||||
right[#right+1] = (size==0 and "0" or math.ceil(pos/size*100)).."%"
|
||||
|
||||
if #win.selections > 1 then
|
||||
right[#right+1] = selection.number .. '/' .. #win.selections
|
||||
end
|
||||
|
||||
if not win.large then
|
||||
local col = selection.col
|
||||
right[#right+1] = selection.line .. ', ' .. col
|
||||
if size > 33554432 or col > 65536 then
|
||||
win.large = true
|
||||
end
|
||||
end
|
||||
|
||||
local left_str = ' ' .. table.concat(left, " | ") .. ' '
|
||||
local right_str = ' ' .. table.concat(right, " | ") .. ' '
|
||||
win:status(left_str, right_str)
|
||||
end
|
|
@ -0,0 +1,162 @@
|
|||
--
|
||||
-- vis-commentary
|
||||
--
|
||||
|
||||
local comment_string = {
|
||||
actionscript='//', ada='--', ansi_c='/*|*/', antlr='//', apdl='!', apl='#',
|
||||
applescript='--', asp='\'', autoit=';', awk='#', b_lang='//', bash='#',
|
||||
batch=':', bibtex='%', boo='#', chuck='//', cmake='#', coffeescript='#',
|
||||
context='%', cpp='//', crystal='#', csharp='//', css='/*|*/', cuda='//',
|
||||
dart='//', desktop='#', django='{#|#}', dmd='//', dockerfile='#', dot='//',
|
||||
eiffel='--', elixir='#', erlang='%', faust='//', fennel=';;', fish='#',
|
||||
forth='|\\', fortran='!', fsharp='//', gap='#', gettext='#', gherkin='#',
|
||||
glsl='//', gnuplot='#', go='//', groovy='//', gtkrc='#', haskell='--',
|
||||
html='<!--|-->', icon='#', idl='//', inform='!', ini='#', Io='#',
|
||||
java='//', javascript='//', json='/*|*/', jsp='//', latex='%', ledger='#',
|
||||
less='//', lilypond='%', lisp=';', logtalk='%', lua='--', makefile='#',
|
||||
markdown='<!--|-->', matlab='#', moonscript='--', myrddin='//',
|
||||
nemerle='//', nsis='#', objective_c='//', pascal='//', perl='#', php='//',
|
||||
pico8='//', pike='//', pkgbuild='#', prolog='%', props='#', protobuf='//',
|
||||
ps='%', pure='//', python='#', rails='#', rc='#', rebol=';', rest='.. ',
|
||||
rexx='--', rhtml='<!--|-->', rstats='#', ruby='#', rust='//', sass='//',
|
||||
scala='//', scheme=';', smalltalk='"|"', sml='(*)', snobol4='#', sql='#',
|
||||
tcl='#', tex='%', text='', toml='#', vala='//', vb='\'', vbscript='\'',
|
||||
verilog='//', vhdl='--', wsf='<!--|-->', xml='<!--|-->', yaml='#', zig='//',
|
||||
nim='#', julia='#', rpmspec='#'
|
||||
}
|
||||
|
||||
-- escape all magic characters with a '%'
|
||||
local function esc(str)
|
||||
if not str then return "" end
|
||||
return (str:gsub('%%', '%%%%')
|
||||
:gsub('^%^', '%%^')
|
||||
:gsub('%$$', '%%$')
|
||||
:gsub('%(', '%%(')
|
||||
:gsub('%)', '%%)')
|
||||
:gsub('%.', '%%.')
|
||||
:gsub('%[', '%%[')
|
||||
:gsub('%]', '%%]')
|
||||
:gsub('%*', '%%*')
|
||||
:gsub('%+', '%%+')
|
||||
:gsub('%-', '%%-')
|
||||
:gsub('%?', '%%?'))
|
||||
end
|
||||
|
||||
-- escape '%'
|
||||
local function pesc(str)
|
||||
if not str then return "" end
|
||||
return str:gsub('%%', '%%%%')
|
||||
end
|
||||
|
||||
function rtrim(s)
|
||||
local n = #s
|
||||
while n > 0 and s:find("^%s", n) do n = n - 1 end
|
||||
return s:sub(1, n)
|
||||
end
|
||||
|
||||
local function comment_line(lines, lnum, prefix, suffix)
|
||||
if suffix ~= "" then suffix = " " .. suffix end
|
||||
lines[lnum] = string.gsub(lines[lnum],
|
||||
"(%s*)(.*)",
|
||||
"%1" .. pesc(prefix) .. " %2" .. pesc(suffix))
|
||||
end
|
||||
|
||||
local function uncomment_line(lines, lnum, prefix, suffix)
|
||||
local match_str = "^(%s*)" .. esc(prefix) .. "%s?(.*)" .. esc(suffix)
|
||||
m = table.pack(lines[lnum]:match(match_str))
|
||||
lines[lnum] = m[1] .. rtrim(m[2])
|
||||
end
|
||||
|
||||
local function is_comment(line, prefix)
|
||||
return (line:match("^%s*(.+)"):sub(0, #prefix) == prefix)
|
||||
end
|
||||
|
||||
local function toggle_line_comment(lines, lnum, prefix, suffix)
|
||||
if not lines or not lines[lnum] then return end
|
||||
if not lines[lnum]:match("^%s*(.+)") then return end -- ignore empty lines
|
||||
if is_comment(lines[lnum], prefix) then
|
||||
uncomment_line(lines, lnum, prefix, suffix)
|
||||
else
|
||||
comment_line(lines, lnum, prefix, suffix)
|
||||
end
|
||||
end
|
||||
|
||||
-- if one line inside the block is not a comment, comment the block.
|
||||
-- only uncomment, if every single line is comment.
|
||||
local function block_comment(lines, a, b, prefix, suffix)
|
||||
local uncomment = true
|
||||
for i=a,b do
|
||||
if lines[i]:match("^%s*(.+)") and not is_comment(lines[i], prefix) then
|
||||
uncomment = false
|
||||
end
|
||||
end
|
||||
|
||||
if uncomment then
|
||||
for i=a,b do
|
||||
if lines[i]:match("^%s*(.+)") then
|
||||
uncomment_line(lines, i, prefix, suffix)
|
||||
end
|
||||
end
|
||||
else
|
||||
for i=a,b do
|
||||
if lines[i]:match("^%s*(.+)") then
|
||||
comment_line(lines, i, prefix, suffix)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vis:map(vis.modes.NORMAL, "gcc", function()
|
||||
local win = vis.win
|
||||
local lines = win.file.lines
|
||||
local comment = comment_string[win.syntax]
|
||||
if not comment then return end
|
||||
local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$')
|
||||
if not prefix then return end
|
||||
|
||||
for sel in win:selections_iterator() do
|
||||
local lnum = sel.line
|
||||
local col = sel.col
|
||||
|
||||
toggle_line_comment(lines, lnum, prefix, suffix)
|
||||
sel:to(lnum, col) -- restore cursor position
|
||||
end
|
||||
|
||||
win:draw()
|
||||
end, "Toggle comment on a the current line")
|
||||
|
||||
local function visual_f(i)
|
||||
return function()
|
||||
local win = vis.win
|
||||
local lines = win.file.lines
|
||||
|
||||
local comment = comment_string[win.syntax]
|
||||
if not comment then return end
|
||||
|
||||
local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$')
|
||||
if not prefix then return end
|
||||
|
||||
for sel in win:selections_iterator() do
|
||||
local r = sel.range
|
||||
local lnum = sel.line -- line number of cursor
|
||||
local col = sel.col -- column of cursor
|
||||
|
||||
if sel.anchored and r then
|
||||
sel.pos = r.start
|
||||
local a = sel.line
|
||||
sel.pos = r.finish
|
||||
local b = sel.line - i
|
||||
|
||||
block_comment(lines, a, b, prefix, suffix)
|
||||
|
||||
sel:to(lnum, col) -- restore cursor position
|
||||
end
|
||||
end
|
||||
|
||||
win:draw()
|
||||
vis.mode = vis.modes.NORMAL -- go to normal mode
|
||||
end
|
||||
end
|
||||
|
||||
vis:map(vis.modes.VISUAL_LINE, "gc", visual_f(1), "Toggle comment on the selected lines")
|
||||
vis:map(vis.modes.VISUAL, "gc", visual_f(0), "Toggle comment on the selected lines")
|
|
@ -0,0 +1,11 @@
|
|||
# http://editorconfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*.lua]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[.gitlab-ci.yml]
|
||||
indent_style = space
|
||||
indent_size = 2
|
|
@ -0,0 +1,23 @@
|
|||
image: imolein/luarocks:5.4
|
||||
|
||||
stages:
|
||||
- check
|
||||
- test
|
||||
|
||||
check-luacheck:
|
||||
stage: check
|
||||
script:
|
||||
- luarocks install luacheck
|
||||
- make check-luacheck
|
||||
|
||||
# check-format:
|
||||
# stage: check
|
||||
# script:
|
||||
# - luarocks install --server=https://luarocks.org/dev luaformatter
|
||||
# - make check-format
|
||||
|
||||
# test:
|
||||
# stage: test
|
||||
# script:
|
||||
# - luarocks install lunatest
|
||||
# - make test
|
|
@ -0,0 +1,27 @@
|
|||
column_limit: 100
|
||||
indent_width: 2
|
||||
use_tab: false
|
||||
spaces_before_call: 1
|
||||
keep_simple_control_block_one_line: false
|
||||
keep_simple_function_one_line: false
|
||||
align_args: true
|
||||
break_after_functioncall_lp: false
|
||||
break_before_functioncall_rp: false
|
||||
spaces_inside_functioncall_parens: false
|
||||
spaces_inside_functiondef_parens: false
|
||||
align_parameter: true
|
||||
chop_down_parameter: false
|
||||
break_after_functiondef_lp: false
|
||||
break_before_functiondef_rp: false
|
||||
align_table_field: true
|
||||
break_after_table_lb: true
|
||||
break_before_table_rb: true
|
||||
chop_down_table: true
|
||||
chop_down_kv_table: true
|
||||
table_sep: ","
|
||||
extra_sep_at_table_end: true
|
||||
column_table_limit: 80
|
||||
spaces_inside_table_braces: false
|
||||
break_after_operator: true
|
||||
double_quote_to_single_quote: true
|
||||
spaces_around_equals_in_field: true
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2016 Florian Fischer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,14 @@
|
|||
.PHONY: check format check-luacheck check-format
|
||||
|
||||
LUA_FILES := $(wildcard *.lua)
|
||||
|
||||
check: check-luacheck check-format
|
||||
|
||||
check-luacheck:
|
||||
luacheck --globals=vis -- $(LUA_FILES)
|
||||
|
||||
check-format:
|
||||
for lf in $(LUA_FILES); do tools/check-format "$${lf}"; done
|
||||
|
||||
format:
|
||||
lua-format -i $(LUA_FILES)
|
|
@ -0,0 +1,45 @@
|
|||
# vis-spellcheck
|
||||
|
||||
A spellchecking lua plugin for the [vis editor](https://github.com/martanne/vis).
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download `spellcheck.lua` or clone this repository into your plugin directory
|
||||
2. Load the plugin in your `visrc.lua` with `require('plugins/vis-spellcheck')`
|
||||
|
||||
## Usage
|
||||
|
||||
+ To enable highlighting of misspelled words press `<Ctrl-w>e` in normal mode.
|
||||
+ To disable highlighting press `<Ctrl-w>d` in normal mode.
|
||||
+ To toggle highlighting press `<F7>` in normal mode.
|
||||
+ To correct the word under the cursor press `<Ctrl+w>w` in normal mode.
|
||||
+ To ignore the word under the cursor press `<Ctrl+w>i` in normal mode.
|
||||
|
||||
## Configuration
|
||||
|
||||
The module table returned from `require(...)` has some configuration options:
|
||||
|
||||
* `cmd`: cmd that is passed to popen() and must return word corrections in Ispell format.
|
||||
* default: `enchant -d %s`
|
||||
* `list_cmd`: cmd that is passed to `popen()` and must output a list of misspelled words.
|
||||
* default: `enchant -l -d %s`
|
||||
* `default_lang`: The name of the used dictionary if the opened file does not specify one. The selected language is inserted in the cmd-strings at `%s`.
|
||||
* default: `$LANG` or `en_US`
|
||||
* `typo_style`: The style string with which misspellings should be highlighted when using the _full viewport_ method
|
||||
* default: `fore:red`
|
||||
* `check_tokens`: A table mapping all token names we consider for spellchecking to true
|
||||
* default: `{[vis.lexers.STRING]=true, [vis.lexers.COMMENT]=true, [vis.lexers.DEFAULT]=true}`
|
||||
* `disable_syntax_awareness`: Disable the syntax aware spellchecking and use always _full viewport_
|
||||
* default: `false`
|
||||
|
||||
A possible configuration could look like this:
|
||||
|
||||
spellcheck = require(...)
|
||||
spellcheck.cmd = "aspell -l %s -a"
|
||||
spellcheck.list_cmd = "aspell list -l %s -a"
|
||||
spellcheck.default_lang = "de_DE"
|
||||
|
||||
Changing language during runtime:
|
||||
|
||||
:set spelllang en_US
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
-- Copyright (c) 2021 Florian Fischer. All rights reserved.
|
||||
-- Use of this source code is governed by a MIT license found in the LICENSE file.
|
||||
local source_str = debug.getinfo(1, 'S').source:sub(2)
|
||||
local script_path = source_str:match('(.*/)')
|
||||
|
||||
return dofile(script_path .. 'spellcheck.lua')
|
|
@ -0,0 +1,445 @@
|
|||
-- Copyright (c) 2017-2019 Florian Fischer. All rights reserved.
|
||||
-- Use of this source code is governed by a MIT license found in the LICENSE file.
|
||||
local spellcheck = {}
|
||||
spellcheck.default_lang = (os.getenv('LANG') or ''):gsub('[.].*', '')
|
||||
if not spellcheck.default_lang:match('^[a-z][a-z]_[A-Z][A-Z]$') then
|
||||
spellcheck.default_lang = 'en_US'
|
||||
end
|
||||
|
||||
spellcheck.get_lang = function()
|
||||
if vis.win.file.spell_language then
|
||||
return vis.win.file.spell_language
|
||||
else
|
||||
return spellcheck.default_lang
|
||||
end
|
||||
end
|
||||
|
||||
local supress_stdout = ' >/dev/null'
|
||||
local supress_stderr = ' 2>/dev/null'
|
||||
local supress_output = supress_stdout .. supress_stderr
|
||||
if os.execute('type enchant' .. supress_output) then
|
||||
spellcheck.cmd = 'enchant -d %s -a'
|
||||
spellcheck.list_cmd = 'enchant -l -d %s'
|
||||
elseif os.execute('type enchant-2' .. supress_output) then
|
||||
spellcheck.cmd = 'enchant-2 -d %s -a'
|
||||
spellcheck.list_cmd = 'enchant-2 -l -d %s'
|
||||
elseif os.execute('type aspell' .. supress_output) then
|
||||
spellcheck.cmd = 'aspell pipe -l %s'
|
||||
spellcheck.list_cmd = 'aspell list -l %s'
|
||||
elseif os.execute('type hunspell' .. supress_output) then
|
||||
spellcheck.cmd = 'hunspell -d %s'
|
||||
spellcheck.list_cmd = 'hunspell -l -d %s'
|
||||
else
|
||||
vis:info('WARNING: vis-spellcheck loaded but no spellchecker found')
|
||||
return nil
|
||||
end
|
||||
|
||||
spellcheck.typo_style_id = 42
|
||||
spellcheck.typo_style = 'fore:red'
|
||||
spellcheck.check_full_viewport = {}
|
||||
spellcheck.disable_syntax_awareness = false
|
||||
|
||||
spellcheck.check_tokens = {
|
||||
[vis.lexers.STRING] = true,
|
||||
[vis.lexers.COMMENT] = true,
|
||||
[vis.lexers.DEFAULT] = true,
|
||||
}
|
||||
|
||||
-- Return nil or a string of misspelled word in a specific file range or text
|
||||
-- by calling the spellchecker's list command.
|
||||
-- If given a range we will use vis:pipe to get our typos from the spellchecker.
|
||||
-- If a string was passed we call the spellchecker ourself and redirect its stdout
|
||||
-- to a temporary file. See http://lua-users.org/lists/lua-l/2007-10/msg00189.html.
|
||||
-- The returned string consists of each misspell followed by a newline.
|
||||
local function get_typos(range_or_text)
|
||||
local cmd = spellcheck.list_cmd:format(spellcheck.get_lang())
|
||||
local typos
|
||||
if type(range_or_text) == 'string' then
|
||||
local text = range_or_text
|
||||
local tmp_name = os.tmpname()
|
||||
local full_cmd = cmd .. '> ' .. tmp_name .. supress_stderr
|
||||
local proc = assert(io.popen(full_cmd, 'w'))
|
||||
proc:write(text)
|
||||
-- this error detection may need lua5.2
|
||||
local success, _, exit_code = proc:close()
|
||||
if not success then
|
||||
vis:info('calling ' .. cmd .. ' failed (' .. exit_code .. ')')
|
||||
return nil
|
||||
end
|
||||
|
||||
local tmp_file = assert(io.open(tmp_name, 'r'))
|
||||
typos = tmp_file:read('*a')
|
||||
tmp_file:close()
|
||||
os.remove(tmp_name)
|
||||
else
|
||||
local range = range_or_text
|
||||
local ret, so, _ = vis:pipe(vis.win.file, range, cmd)
|
||||
|
||||
if ret ~= 0 then
|
||||
vis:info('calling ' .. cmd .. ' failed (' .. ret .. ')')
|
||||
return nil
|
||||
end
|
||||
typos = so
|
||||
end
|
||||
|
||||
return typos
|
||||
end
|
||||
|
||||
-- plugin global list of ignored typos
|
||||
local ignored = {}
|
||||
|
||||
-- Return an iterator over all not ignored typos and their positions in text.
|
||||
-- The returned iterator is a self contained statefull iterator function closure.
|
||||
-- Which will return the next typo and its start and finish in the text, starting by 1.
|
||||
local function typo_iter(text, typos, ignored) -- luacheck: ignore ignored
|
||||
local index = 1
|
||||
local unfiltered_iterator, iter_state = typos:gmatch('(.-)\n')
|
||||
|
||||
-- see https://stackoverflow.com/questions/6705872/how-to-escape-a-variable-in-lua
|
||||
local escape_lua_pattern
|
||||
do
|
||||
local matches = {
|
||||
['^'] = '%^',
|
||||
['$'] = '%$',
|
||||
['('] = '%(',
|
||||
[')'] = '%)',
|
||||
['%'] = '%%',
|
||||
['.'] = '%.',
|
||||
['['] = '%[',
|
||||
[']'] = '%]',
|
||||
['*'] = '%*',
|
||||
['+'] = '%+',
|
||||
['-'] = '%-',
|
||||
['?'] = '%?',
|
||||
}
|
||||
|
||||
escape_lua_pattern = function(s)
|
||||
return (s:gsub('.', matches))
|
||||
end
|
||||
end
|
||||
|
||||
return function()
|
||||
local typo
|
||||
repeat
|
||||
typo = unfiltered_iterator(iter_state)
|
||||
until (not typo or (typo ~= '' and not ignored[typo]))
|
||||
|
||||
if typo then
|
||||
local start, finish
|
||||
-- special case for typos at the beginning of the text
|
||||
-- Leading typos are not found by our used pattern [%A]typo[%A].
|
||||
-- To prevent typos to be skipped if the leading typo accours an
|
||||
-- additional time in the text we need this special case
|
||||
if index == 1 and text:sub(1, #typo) == typo then
|
||||
start = 1
|
||||
finish = #typo
|
||||
else
|
||||
-- to prevent typos from being found in correct words before them
|
||||
-- ("stuff stuf", "broken ok", ...)
|
||||
-- we match typos only when they are enclosed in non-letter characters.
|
||||
local pattern = '[%A]' .. escape_lua_pattern(typo) .. '[%A]'
|
||||
start, finish = text:find(pattern, index)
|
||||
if start then -- our pattern [%A]typo[%A] found it
|
||||
start = start + 1 -- ignore leading non letter char
|
||||
finish = finish - 1 -- ignore trailing non letter char
|
||||
else -- typo was not found by our pattern this means it must be the last word
|
||||
start = #text - #typo + 1
|
||||
finish = start + #typo - 1
|
||||
|
||||
if text:sub(start, finish) ~= typo then
|
||||
vis:info(string.format(
|
||||
'can\'t find typo %s after %d. Please report this bug.',
|
||||
typo, index))
|
||||
end
|
||||
end
|
||||
end
|
||||
index = finish
|
||||
|
||||
return typo, start, finish
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local last_viewport, last_data, last_typos = nil, '', ''
|
||||
|
||||
vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win)
|
||||
if not spellcheck.check_full_viewport[win] or
|
||||
not win:style_define(spellcheck.typo_style_id, spellcheck.typo_style) then
|
||||
return
|
||||
end
|
||||
local viewport = win.viewport
|
||||
local viewport_text = win.file:content(viewport)
|
||||
|
||||
local typos
|
||||
if last_viewport == viewport_text then
|
||||
typos = last_typos
|
||||
else
|
||||
typos = get_typos(viewport) or ''
|
||||
if not typos then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
for _, start, finish in typo_iter(viewport_text, typos, ignored) do
|
||||
win:style(spellcheck.typo_style_id, viewport.start + start - 1,
|
||||
viewport.start + finish - 1)
|
||||
end
|
||||
|
||||
last_viewport = viewport_text
|
||||
last_typos = typos
|
||||
-- TODO: think about returning true here
|
||||
-- http://martanne.github.io/vis/doc/index.html#Events
|
||||
-- The vis documentation states that a no further event handlers are called if one
|
||||
-- returns not nil
|
||||
-- Should we terminate the WIN_HIGHLIGHT event handling if we are ready highltighting
|
||||
-- typos ?
|
||||
return true
|
||||
end)
|
||||
|
||||
local wrapped_lex_funcs = {}
|
||||
|
||||
local wrap_lex_func = function(old_lex_func)
|
||||
local old_new_tokens = {}
|
||||
|
||||
return function(lexer, data, index, redrawtime_max)
|
||||
local tokens, timedout = old_lex_func(lexer, data, index, redrawtime_max)
|
||||
|
||||
-- quit early if the lexer already took to long
|
||||
-- TODO: investigate further if timedout is actually set by the lexer.
|
||||
-- As I understand lpeg.match used by lexer.lex timedout will always be nil
|
||||
if timedout then
|
||||
return tokens, timedout
|
||||
end
|
||||
|
||||
local new_tokens = {}
|
||||
|
||||
local typos
|
||||
if last_data ~= data then
|
||||
typos = get_typos(data)
|
||||
if not typos then
|
||||
return tokens, timedout
|
||||
end
|
||||
last_data = data
|
||||
else
|
||||
return old_new_tokens
|
||||
end
|
||||
|
||||
local i = 1
|
||||
for _, typo_start, typo_end in typo_iter(data, typos, ignored) do
|
||||
repeat
|
||||
-- no tokens left
|
||||
if i > #tokens - 1 then
|
||||
break
|
||||
end
|
||||
|
||||
local token_type = tokens[i]
|
||||
local token_start = (tokens[i - 1] or 1) - 1
|
||||
local token_end = tokens[i + 1]
|
||||
|
||||
-- the current token ends before our typo -> append to new stream
|
||||
-- or is not spellchecked
|
||||
if token_end < typo_start or not spellcheck.check_tokens[token_type] then
|
||||
table.insert(new_tokens, token_type)
|
||||
table.insert(new_tokens, token_end)
|
||||
|
||||
-- done with this token -> advance token stream
|
||||
i = i + 2
|
||||
-- typo and checked token overlap
|
||||
else
|
||||
local pre_typo_end = typo_start - 1
|
||||
-- unchanged token part before typo
|
||||
if pre_typo_end > token_start then
|
||||
table.insert(new_tokens, token_type)
|
||||
table.insert(new_tokens, pre_typo_end + 1)
|
||||
end
|
||||
|
||||
-- highlight typo
|
||||
table.insert(new_tokens, vis.lexers.ERROR)
|
||||
-- the typo spans multiple tokens
|
||||
if token_end < typo_end then
|
||||
table.insert(new_tokens, token_end + 1)
|
||||
i = i + 2
|
||||
else
|
||||
table.insert(new_tokens, typo_end + 1)
|
||||
end
|
||||
end
|
||||
until (not token_end or token_end >= typo_end)
|
||||
end
|
||||
|
||||
-- add tokens left after we handled all typos
|
||||
for i = i, #tokens, 1 do -- luacheck: ignore i
|
||||
table.insert(new_tokens, tokens[i])
|
||||
end
|
||||
|
||||
old_new_tokens = new_tokens
|
||||
return new_tokens, timedout
|
||||
end
|
||||
end
|
||||
|
||||
local enable_spellcheck = function()
|
||||
-- prevent wrapping the lex function multiple times
|
||||
if wrapped_lex_funcs[vis.win] then
|
||||
return
|
||||
end
|
||||
|
||||
if not spellcheck.disable_syntax_awareness and vis.win.syntax and
|
||||
vis.lexers.load then
|
||||
local lexer = vis.lexers.load(vis.win.syntax, nil, true)
|
||||
if lexer and lexer.lex then
|
||||
local old_lex_func = lexer.lex
|
||||
wrapped_lex_funcs[vis.win] = old_lex_func
|
||||
lexer.lex = wrap_lex_func(old_lex_func)
|
||||
-- reset last data to enforce new highlighting
|
||||
last_data = ''
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- fallback check spellcheck the full viewport
|
||||
spellcheck.check_full_viewport[vis.win] = true
|
||||
end
|
||||
|
||||
local is_spellcheck_enabled = function()
|
||||
return spellcheck.check_full_viewport[vis.win] or wrapped_lex_funcs[vis.win]
|
||||
end
|
||||
|
||||
vis:map(vis.modes.NORMAL, '<C-w>e', function()
|
||||
enable_spellcheck()
|
||||
end, 'Enable spellchecking in the current window')
|
||||
|
||||
local disable_spellcheck = function()
|
||||
local old_lex_func = wrapped_lex_funcs[vis.win]
|
||||
if old_lex_func then
|
||||
local lexer = vis.lexers.load(vis.win.syntax, nil, true)
|
||||
lexer.lex = old_lex_func
|
||||
wrapped_lex_funcs[vis.win] = nil
|
||||
else
|
||||
spellcheck.check_full_viewport[vis.win] = nil
|
||||
end
|
||||
end
|
||||
|
||||
vis:map(vis.modes.NORMAL, '<C-w>d', function()
|
||||
disable_spellcheck()
|
||||
-- force new highlight
|
||||
vis.win:draw()
|
||||
end, 'Disable spellchecking in the current window')
|
||||
|
||||
-- toggle spellchecking on <F7>
|
||||
-- <F7> is used by some word processors (LibreOffice) for spellchecking
|
||||
-- Thanks to @leorosa for the hint.
|
||||
vis:map(vis.modes.NORMAL, '<F7>', function()
|
||||
if not is_spellcheck_enabled() then
|
||||
enable_spellcheck()
|
||||
else
|
||||
disable_spellcheck()
|
||||
vis.win:draw()
|
||||
end
|
||||
return 0
|
||||
end, 'Toggle spellchecking in the current window')
|
||||
|
||||
vis:map(vis.modes.NORMAL, '<C-w>w', function()
|
||||
local win = vis.win
|
||||
local file = win.file
|
||||
local pos = win.selection.pos
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
local range = file:text_object_word(pos);
|
||||
if not range then
|
||||
return
|
||||
end
|
||||
if range.start == range.finish then
|
||||
return
|
||||
end
|
||||
|
||||
local cmd = spellcheck.cmd:format(spellcheck.get_lang())
|
||||
local ret, so, se = vis:pipe(win.file, range, cmd)
|
||||
if ret ~= 0 then
|
||||
vis:message('calling ' .. cmd .. ' failed (' .. se .. ')')
|
||||
return false
|
||||
end
|
||||
|
||||
local answer_line = so:match('.-\n(.-)\n.*')
|
||||
if not answer_line then
|
||||
return false
|
||||
end
|
||||
|
||||
local suggestions
|
||||
local first_char = answer_line:sub(0, 1)
|
||||
if first_char == '*' then
|
||||
vis:info(file:content(range) .. ' is correctly spelled')
|
||||
return true
|
||||
elseif first_char == '#' then
|
||||
vis:info('No corrections available for ' .. file:content(range))
|
||||
return false
|
||||
elseif first_char == '&' then
|
||||
suggestions = answer_line:match('& %S+ %d+ %d+: (.*)')
|
||||
else
|
||||
vis:info('Unknown answer: ' .. answer_line)
|
||||
return false
|
||||
end
|
||||
|
||||
-- select a correction
|
||||
cmd = 'printf "' .. suggestions:gsub(', ', '\\n') .. '\\n" | vis-menu'
|
||||
local status, correction = vis:pipe(file, {start = 0, finish = 0}, cmd)
|
||||
if status == 0 then
|
||||
-- trim correction
|
||||
correction = correction:match('^%s*(.-)%s*$')
|
||||
win.file:delete(range)
|
||||
win.file:insert(range.start, correction)
|
||||
end
|
||||
|
||||
win.selection.pos = pos
|
||||
|
||||
win:draw()
|
||||
|
||||
return 0
|
||||
end, 'Correct misspelled word')
|
||||
|
||||
vis:map(vis.modes.NORMAL, '<C-w>i', function()
|
||||
local win = vis.win
|
||||
local file = win.file
|
||||
local pos = win.selection.pos
|
||||
if not pos then
|
||||
return
|
||||
end
|
||||
local range = file:text_object_word(pos);
|
||||
if not range then
|
||||
return
|
||||
end
|
||||
if range.start == range.finish then
|
||||
return
|
||||
end
|
||||
|
||||
ignored[file:content(range)] = true
|
||||
|
||||
-- Check if we use our syntax aware spellcheck lex-closure
|
||||
-- We must rebuild the closure because it captures ignored
|
||||
-- to include the new addition
|
||||
local old_lex_func = wrapped_lex_funcs[vis.win]
|
||||
if old_lex_func then
|
||||
local lexer = vis.lexers.load(vis.win.syntax, nil, true)
|
||||
lexer.lex = wrap_lex_func(old_lex_func)
|
||||
-- reset last data to enforce new highlighting
|
||||
last_data = ''
|
||||
end
|
||||
|
||||
win:draw()
|
||||
return 0
|
||||
end, 'Ignore misspelled word')
|
||||
|
||||
vis:option_register('spelllang', 'string', function(value)
|
||||
vis.win.file.spell_language = value
|
||||
vis:info('Spellchecking language is now ' .. value)
|
||||
-- force new highlight for full viewport
|
||||
last_viewport = nil
|
||||
-- force new highlight for syntax aware
|
||||
last_data = nil
|
||||
return true
|
||||
end, 'The language used for spellchecking')
|
||||
|
||||
vis:command_register('spelllang', function()
|
||||
vis:info('The spellchecking language is ' .. spellcheck.get_lang())
|
||||
end, 'Print the language used for spellchecking')
|
||||
|
||||
return spellcheck
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/sh
|
||||
|
||||
LUA_FILE=$1
|
||||
lua-format "${LUA_FILE}" > "${LUA_FILE}.fmt"
|
||||
diff "${LUA_FILE}" "${LUA_FILE}.fmt"
|
||||
RET=$?
|
||||
rm "${LUA_FILE}.fmt"
|
||||
exit ${RET}
|
|
@ -0,0 +1,11 @@
|
|||
function set_title(title)
|
||||
vis:command(string.format(":!echo -ne '\\033]0;%s\\007'", title))
|
||||
end
|
||||
|
||||
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
|
||||
set_title(win.file.name or '[No Name]')
|
||||
end)
|
||||
|
||||
vis.events.subscribe(vis.events.FILE_SAVE_POST, function(file, path)
|
||||
set_title(file.name)
|
||||
end)
|
|
@ -0,0 +1,63 @@
|
|||
-- base16-vis (https://github.com/pshevtsov/base16-vis)
|
||||
-- by Petr Shevtsov
|
||||
-- IR Black scheme by Timothée Poisot (http://timotheepoisot.fr)
|
||||
|
||||
local lexers = vis.lexers
|
||||
|
||||
local colors = {
|
||||
['base00'] = '#000000',
|
||||
['base01'] = '#242422',
|
||||
['base02'] = '#484844',
|
||||
['base03'] = '#6c6c66',
|
||||
['base04'] = '#918f88',
|
||||
['base05'] = '#b5b3aa',
|
||||
['base06'] = '#d9d7cc',
|
||||
['base07'] = '#fdfbee',
|
||||
['base08'] = '#ff6c60',
|
||||
['base09'] = '#e9c062',
|
||||
['base0A'] = '#ffffb6',
|
||||
['base0B'] = '#a8ff60',
|
||||
['base0C'] = '#c6c5fe',
|
||||
['base0D'] = '#96cbfe',
|
||||
['base0E'] = '#ff73fd',
|
||||
['base0F'] = '#b18a3d',
|
||||
}
|
||||
|
||||
lexers.colors = colors
|
||||
|
||||
local fg = ',fore:'..colors.base05..','
|
||||
local bg = ',back:'..colors.base00..','
|
||||
|
||||
lexers.STYLE_DEFAULT = bg..fg
|
||||
lexers.STYLE_NOTHING = bg
|
||||
lexers.STYLE_CLASS = 'fore:'..colors.base0A
|
||||
lexers.STYLE_COMMENT = 'fore:'..colors.base03..',italics'
|
||||
lexers.STYLE_CONSTANT = 'fore:'..colors.base09
|
||||
lexers.STYLE_DEFINITION = 'fore:'..colors.base0E
|
||||
lexers.STYLE_ERROR = 'fore:'..colors.base08..',italics'
|
||||
lexers.STYLE_FUNCTION = 'fore:'..colors.base0D
|
||||
lexers.STYLE_KEYWORD = 'fore:'..colors.base0E
|
||||
lexers.STYLE_LABEL = 'fore:'..colors.base0A
|
||||
lexers.STYLE_NUMBER = 'fore:'..colors.base09
|
||||
lexers.STYLE_OPERATOR = 'fore:'..colors.base05
|
||||
lexers.STYLE_REGEX = 'fore:'..colors.base0C
|
||||
lexers.STYLE_STRING = 'fore:'..colors.base0B
|
||||
lexers.STYLE_PREPROCESSOR = 'fore:'..colors.base0A
|
||||
lexers.STYLE_TAG = 'fore:'..colors.base0A
|
||||
lexers.STYLE_TYPE = 'fore:'..colors.base0A
|
||||
lexers.STYLE_VARIABLE = 'fore:'..colors.base0D
|
||||
lexers.STYLE_WHITESPACE = 'fore:'..colors.base02
|
||||
lexers.STYLE_EMBEDDED = 'fore:'..colors.base0F
|
||||
lexers.STYLE_IDENTIFIER = 'fore:'..colors.base08
|
||||
|
||||
lexers.STYLE_LINENUMBER = 'fore:'..colors.base02..',back:'..colors.base00
|
||||
lexers.STYLE_CURSOR = 'fore:'..colors.base00..',back:'..colors.base05
|
||||
lexers.STYLE_CURSOR_PRIMARY = 'fore:'..colors.base00..',back:'..colors.base05
|
||||
lexers.STYLE_CURSOR_LINE = 'back:'..colors.base01
|
||||
lexers.STYLE_COLOR_COLUMN = 'back:'..colors.base01
|
||||
lexers.STYLE_SELECTION = 'back:'..colors.base02
|
||||
lexers.STYLE_STATUS = 'fore:'..colors.base04..',back:'..colors.base01
|
||||
lexers.STYLE_STATUS_FOCUSED = 'fore:'..colors.base09..',back:'..colors.base01
|
||||
lexers.STYLE_SEPARATOR = lexers.STYLE_DEFAULT
|
||||
lexers.STYLE_INFO = 'fore:default,back:default,bold'
|
||||
lexers.STYLE_EOF = ''
|
|
@ -0,0 +1,37 @@
|
|||
--Eight-color scheme
|
||||
local lexers = vis.lexers
|
||||
-- dark
|
||||
lexers.STYLE_DEFAULT ='back:black,fore:white'
|
||||
lexers.STYLE_NOTHING = 'back:black'
|
||||
lexers.STYLE_CLASS = 'fore:yellow,bold'
|
||||
lexers.STYLE_COMMENT = 'fore:#545b67,italics'
|
||||
lexers.STYLE_CONSTANT = 'fore:magenta,bold'
|
||||
lexers.STYLE_DEFINITION = 'fore:blue,bold'
|
||||
lexers.STYLE_ERROR = 'fore:red,italics'
|
||||
lexers.STYLE_FUNCTION = 'fore:magenta,bold'
|
||||
lexers.STYLE_KEYWORD = 'fore:blue,bold'
|
||||
lexers.STYLE_LABEL = 'fore:green,bold'
|
||||
lexers.STYLE_NUMBER = 'fore:yellow'
|
||||
lexers.STYLE_OPERATOR = 'fore:white'
|
||||
lexers.STYLE_REGEX = 'fore:green'
|
||||
lexers.STYLE_STRING = 'fore:green'
|
||||
lexers.STYLE_PREPROCESSOR = 'fore:magenta,bold'
|
||||
lexers.STYLE_TAG = 'fore:red,bold'
|
||||
lexers.STYLE_TYPE = 'fore:red,bold'
|
||||
lexers.STYLE_VARIABLE = 'fore:magenta,bold'
|
||||
lexers.STYLE_WHITESPACE = ''
|
||||
lexers.STYLE_EMBEDDED = 'fore:green'
|
||||
lexers.STYLE_IDENTIFIER = ''
|
||||
lexers.STYLE_LINENUMBER = 'fore:white'
|
||||
lexers.STYLE_LINENUMBER_CURSOR = lexers.STYLE_LINENUMBER
|
||||
lexers.STYLE_CURSOR = 'back:white,fore:black'
|
||||
lexers.STYLE_CURSOR_PRIMARY = 'back:yellow,fore:black'
|
||||
lexers.STYLE_CURSOR_LINE = 'back:magenta'
|
||||
--lexers.STYLE_CURSOR_LINE = 'underlined'
|
||||
lexers.STYLE_COLOR_COLUMN = 'back:red'
|
||||
lexers.STYLE_SELECTION = 'back:white'
|
||||
lexers.STYLE_STATUS = 'reverse'
|
||||
lexers.STYLE_STATUS_FOCUSED = 'reverse,bold'
|
||||
lexers.STYLE_SEPARATOR = lexers.STYLE_DEFAULT
|
||||
lexers.STYLE_INFO = 'fore:default,back:default,bold'
|
||||
lexers.STYLE_EOF = ''
|
|
@ -0,0 +1,114 @@
|
|||
local lexers = vis.lexers
|
||||
local peaksea={
|
||||
bgdark='#1c1c1c',--black
|
||||
bglight='#e4e4e4',--white
|
||||
annotationdark='#5fff87',--green
|
||||
annotationlight='#00875f',--tuerkis
|
||||
functiondark='#e8a0e8',--violett
|
||||
functionlight='#af5faf',--pink
|
||||
normalfontdark='#d0d0d0',--dark grey
|
||||
normalfontlight='#000000',--grey
|
||||
stringdark='#afd7ff',--light grey
|
||||
stringlight='#005f5f',--cyan
|
||||
numberdark='#e0c060',--dark yellow
|
||||
numberlight='#875f00',--dark yellow little brown
|
||||
commentdark='#d0d090',--dark golden dirty
|
||||
commentlight='#5f5f00',--light golden dirty
|
||||
bgerrordark='#aa0000',--red
|
||||
bgerrorlight='#80c0e0',--red
|
||||
fglinenumberdark='#b0b0b0',--white
|
||||
fglinenumberlight='#6c6c6c',--grey
|
||||
constantdark='#80c0e0',--cyan
|
||||
constantlight='#000000',
|
||||
identifierdark='#d0d0d0',--white
|
||||
identifierlight='#000000',
|
||||
bgstatusdark='#d7ff00',--dark yellow
|
||||
bgstatuslight='#000000',
|
||||
bgcursordark='#262626',
|
||||
bgcursorlight='#add8e6',--cyan
|
||||
fgoperatorlight='#005faf',--blue
|
||||
fgdark='#d0d0d0',
|
||||
fglight='#1b1b1b',
|
||||
embeddedlight='#875f00',
|
||||
fgstatusbarlight='#5fffaf'
|
||||
}
|
||||
if background==nil
|
||||
then
|
||||
background="dark"
|
||||
end
|
||||
|
||||
if background=="dark"
|
||||
then
|
||||
lexers.STYLE_DEFAULT='fore:'..peaksea.fgdark..', back:'..peaksea.bgdark
|
||||
lexers.STYLE_CLASS='fore:'..peaksea.normalfontdark
|
||||
lexers.STYLE_COMMENT='fore:'..peaksea.commentdark
|
||||
lexers.STYLE_CONSTANT='fore:'..peaksea.constantdark
|
||||
lexers.STYLE_DEFINITION='fore:'..peaksea.bgerrordark--TODO
|
||||
lexers.STYLE_ERROR='fore:'..peaksea.commentdark..',back:'..peaksea.bgerrordark
|
||||
lexers.STYLE_FUNCTION='fore:'..peaksea.functiondark
|
||||
lexers.STYLE_KEYWORD = 'fore:'..peaksea.stringdark--if other logical operators
|
||||
lexers.STYLE_LABEL = 'fore:'..peaksea.functiondark
|
||||
lexers.STYLE_NUMBER = 'fore:'..peaksea.numberdark
|
||||
vis.lexers.STYLE_OPERATOR = vis.lexers.STYLE_DEFAULT--for the brackets
|
||||
lexers.STYLE_REGEX = 'fore:'..peaksea.bgerrordark
|
||||
lexers.STYLE_STRING = 'fore:'..peaksea.stringdark
|
||||
lexers.STYLE_PREPROCESSOR = 'fore:'..peaksea.annotationdark--annotations
|
||||
lexers.STYLE_TAG = 'fore:'..peaksea.bgerrordark
|
||||
lexers.STYLE_TYPE = 'fore:'..peaksea.functiondark
|
||||
lexers.STYLE_VARIABLE = 'fore:'..peaksea.functiondark
|
||||
lexers.STYLE_WHITESPACE = ''
|
||||
lexers.STYLE_EMBEDDED = 'fore:'..peaksea.commentdark
|
||||
lexers.STYLE_IDENTIFIER = 'fore:'..peaksea.identifierdark --imports and co
|
||||
|
||||
lexers.STYLE_LINENUMBER='fore:'..peaksea.fglinenumberdark..',back:'..peaksea.bgdark
|
||||
lexers.STYLE_LINENUMBER_CURSOR = 'fore:'..peaksea.fglinenumberdark..',back:'..peaksea.bgdark
|
||||
lexers.STYLE_CURSOR='fore:'..peaksea.bgdark..',back:'..peaksea.annotationdark
|
||||
|
||||
lexers.STYLE_CURSOR_PRIMARY = 'fore:'..peaksea.bgdark..',back:'..peaksea.stringdark--cursor in normal mode
|
||||
lexers.STYLE_CURSOR_LINE = 'back:'..peaksea.bgcursordark
|
||||
|
||||
lexers.STYLE_COLOR_COLUMN = 'back:'..peaksea.normalfontdark
|
||||
lexers.STYLE_SELECTION = 'fore:'..peaksea.bgdark..',back:'..peaksea.stringdark
|
||||
lexers.STYLE_STATUS = 'fore:'..peaksea.bgdark..',back:'..peaksea.bgstatusdark
|
||||
lexers.STYLE_STATUS_FOCUSED = 'fore:'..peaksea.bgdark..',back:'..peaksea.bgstatusdark
|
||||
lexers.STYLE_SEPARATOR = 'back:'..peaksea.bgstatusdark
|
||||
lexers.STYLE_INFO = 'fore:'..peaksea.bgerrordark
|
||||
lexers.STYLE_EOF = 'fore:'..peaksea.fglinenumberdark..',back:'..peaksea.bgdark
|
||||
elseif background=="light"
|
||||
then
|
||||
lexers.STYLE_DEFAULT='fore:'..peaksea.fglight..',back:'..peaksea.bglight
|
||||
lexers.STYLE_CLASS='fore:'..peaksea.normalfontlight
|
||||
lexers.STYLE_COMMENT='fore:'..peaksea.commentlight
|
||||
lexers.STYLE_CONSTANT='fore:'..peaksea.constantlight
|
||||
lexers.STYLE_DEFINITION='fore:'..peaksea.bgerrorlight--TODO
|
||||
lexers.STYLE_ERROR='fore:'..peaksea.commentlight..',back:'..peaksea.bgerrorlight
|
||||
lexers.STYLE_FUNCTION='fore:'..peaksea.functionlight
|
||||
lexers.STYLE_KEYWORD = 'fore:'..peaksea.fgoperatorlight..',bold'--if other logical operators
|
||||
lexers.STYLE_LABEL = 'fore:'..peaksea.functionlight
|
||||
lexers.STYLE_NUMBER = 'fore:'..peaksea.numberlight
|
||||
vis.lexers.STYLE_OPERATOR = 'fore:'..peaksea.fgoperatorlight
|
||||
lexers.STYLE_REGEX = 'fore:'..peaksea.bgerrorlight
|
||||
lexers.STYLE_STRING = 'fore:'..peaksea.stringlight
|
||||
lexers.STYLE_PREPROCESSOR = 'fore:'..peaksea.annotationlight--annotations
|
||||
lexers.STYLE_TAG = 'fore:'..peaksea.bgerrorlight
|
||||
lexers.STYLE_TYPE = 'fore:'..peaksea.functionlight
|
||||
lexers.STYLE_VARIABLE = 'fore:'..peaksea.functionlight
|
||||
lexers.STYLE_WHITESPACE = ''
|
||||
lexers.STYLE_EMBEDDED = 'fore:'..peaksea.embeddedlight
|
||||
lexers.STYLE_IDENTIFIER = 'fore:'..peaksea.identifierlight --imports and co
|
||||
|
||||
lexers.STYLE_LINENUMBER='fore:'..peaksea.fglinenumberlight..',back:'..peaksea.bglight
|
||||
lexers.STYLE_LINENUMBER_CURSOR = 'fore:'..peaksea.fglinenumberlight..',back:'..peaksea.bglight
|
||||
lexers.STYLE_CURSOR='fore:'..peaksea.bglight..',back:'..peaksea.bgdark--bgcursorlight
|
||||
|
||||
lexers.STYLE_CURSOR_PRIMARY = 'fore:'..peaksea.bgdark..',back:'..peaksea.bgcursorlight--cursor in normal mode
|
||||
lexers.STYLE_CURSOR_LINE = 'back:'..peaksea.bglight
|
||||
|
||||
lexers.STYLE_COLOR_COLUMN = 'back:'..peaksea.normalfontlight
|
||||
lexers.STYLE_SELECTION = 'fore:'..peaksea.bglight..',back:'..peaksea.bgcursorlight..',bold'
|
||||
lexers.STYLE_STATUS = 'fore:'..peaksea.bglight..',back:'..peaksea.bgstatuslight
|
||||
lexers.STYLE_STATUS_FOCUSED = 'fore:'..peaksea.fgstatusbarlight..',back:'..peaksea.bgstatuslight
|
||||
lexers.STYLE_SEPARATOR = 'back:'..peaksea.bgstatuslight
|
||||
lexers.STYLE_INFO = 'fore:'..peaksea.bgerrorlight
|
||||
lexers.STYLE_EOF = 'fore:'..peaksea.fglinenumberlight..',back:'..peaksea.bglight
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
-- Author: rob
|
||||
-- Filename: primary.lua
|
||||
|
||||
local lexers = vis.lexers
|
||||
|
||||
local fg = ',fore:default,'
|
||||
local bg = ',back:default,'
|
||||
|
||||
-- 0 = light
|
||||
-- 1 = dark
|
||||
local c = {
|
||||
blue0 = '#5fd7ff', -- 081
|
||||
blue1 = '#00ffff', -- 045
|
||||
blue2 = '#000b1e', -- 002
|
||||
purple0 = '#8086e8', -- 089
|
||||
purple1 = '#af87ff', -- 141
|
||||
brown1 = '#87875f', -- 101
|
||||
green0 = '#87ffaf', -- 112
|
||||
yellow0 = '#e0c060', -- 185
|
||||
orange1 = '#ffaf00', -- 173
|
||||
orange0 = '#f25030', -- 214
|
||||
red0 = '#D32213', -- 197
|
||||
black0 = '#000000', -- 235
|
||||
grey0 = '#4e4e4e', -- 239
|
||||
grey1 = '#2c303b', -- 237
|
||||
grey2 = '#bcbcbc', -- 250
|
||||
white1 = '#ffffff', -- 230
|
||||
}
|
||||
|
||||
lexers.STYLE_DEFAULT = bg..fg
|
||||
lexers.STYLE_NOTHING = bg
|
||||
lexers.STYLE_CLASS = 'fore:' .. c.orange1
|
||||
lexers.STYLE_COMMENT = 'fore:' .. c.brown1
|
||||
lexers.STYLE_CONSTANT = 'fore:' .. c.purple1
|
||||
lexers.STYLE_DEFINITION = 'fore:' .. c.blue1
|
||||
lexers.STYLE_ERROR = 'fore:' .. c.red0 .. ',italics,back:'..c.purple0
|
||||
lexers.STYLE_FUNCTION = 'fore:' .. c.red0
|
||||
lexers.STYLE_KEYWORD = 'fore:' .. c.orange1
|
||||
lexers.STYLE_LABEL = 'fore:' .. c.orange0
|
||||
lexers.STYLE_NUMBER = 'fore:' .. c.purple0
|
||||
lexers.STYLE_OPERATOR = 'fore:' .. c.green0
|
||||
lexers.STYLE_REGEX = 'fore:' .. c.red0
|
||||
lexers.STYLE_STRING = 'fore:' .. c.purple0
|
||||
lexers.STYLE_PREPROCESSOR = 'fore:' .. c.red0
|
||||
lexers.STYLE_TAG = 'fore:' .. c.green0
|
||||
lexers.STYLE_TYPE = 'fore:' .. c.blue1
|
||||
lexers.STYLE_VARIABLE = 'fore:' .. c.blue1
|
||||
lexers.STYLE_WHITESPACE = 'fore:' .. c.grey2
|
||||
lexers.STYLE_EMBEDDED = 'back:' .. c.blue1
|
||||
lexers.STYLE_IDENTIFIER = fg
|
||||
lexers.STYLE_LINENUMBER = 'fore:' .. c.grey2 .. ',fore:' .. c.grey1
|
||||
lexers.STYLE_LINENUMBER_CURSOR = 'fore:'.. c.purple0 ..',back:'.. c.blue2
|
||||
lexers.STYLE_CURSOR = 'fore:' .. c.black0 .. ',back:' .. c.white1
|
||||
lexers.STYLE_CURSOR_PRIMARY = 'fore:' .. c.black0 .. ',back:' .. c.blue1
|
||||
--lexers.STYLE_CURSOR_LINE = 'underlined'
|
||||
lexers.STYLE_CURSOR_LINE = 'back:' .. c.grey1
|
||||
lexers.STYLE_COLOR_COLUMN = lexers.STYLE_CURSOR_LINE
|
||||
lexers.STYLE_SELECTION = 'back:' .. c.grey0 .. ',fore:' .. c.red0
|
||||
lexers.STYLE_STATUS = 'fore:' .. c.blue2 .. ',fore:' .. c.green0
|
||||
lexers.STYLE_STATUS_FOCUSED = lexers.STYLE_STATUS .. ',bold'
|
||||
lexers.STYLE_SEPARATOR = lexers.STYLE_DEFAULT
|
||||
lexers.STYLE_INFO = 'fore:' ..c.purple1
|
||||
--lexers.STYLE_INFO = 'fore:default,back:default,bold'
|
||||
lexers.STYLE_EOF = lexers.STYLE_COMMENT
|
|
@ -0,0 +1,112 @@
|
|||
-- ___ ___ ___ ________
|
||||
-- |\ \|\ \\ \|\ ____\
|
||||
-- \ \ \|\ \\ \\\ \___|\
|
||||
-- \ \ \|\ \\ \\\_____ \
|
||||
-- \ \ \|\ \\ \\|____|\ \
|
||||
-- \ \ \| \\ \ ____\_\ \
|
||||
-- \ \_______\\__\|\_______\
|
||||
-- \|_______||__|\|_______|
|
||||
--
|
||||
-- Author: rob
|
||||
-- Filename: visrc.lua
|
||||
|
||||
|
||||
require('vis')
|
||||
|
||||
-- plugins
|
||||
require('plugins/vis-title')
|
||||
require('plugins/filetype')
|
||||
require('plugins/vis-commentary')
|
||||
require('plugins/vis-spellcheck')
|
||||
require('plugins/statusline')
|
||||
require('plugins/copypasta')
|
||||
|
||||
-- configuración global
|
||||
vis.events.subscribe(vis.events.INIT,
|
||||
function()
|
||||
vis:command('set theme primary')
|
||||
vis:command('set autoindent')
|
||||
|
||||
--* deshacer - / rehacer + / remplazar / escapar
|
||||
vis:map(vis.modes.NORMAL, "<C-d>", ':earlier<Enter>')
|
||||
vis:map(vis.modes.NORMAL, "<M-r>", ':later<Enter>')
|
||||
vis:map(vis.modes.NORMAL, "<F9>", ':x/foo/ c/foo/')
|
||||
vis:map(vis.modes.INSERT, "<S-Tab>", '<Escape>')
|
||||
|
||||
-- configuración de copy / paste
|
||||
vis:map(vis.modes.VISUAL, "<C-c>", ':> vis-clipboard --copy<Enter>')
|
||||
vis:map(vis.modes.NORMAL, "<C-v>", ':< vis-clipboard --paste<Enter>')
|
||||
|
||||
-- apertura de nuevo editor (horizontal) / apertura de directorio
|
||||
vis:map(vis.modes.NORMAL, "<F1>", ':new<Enter>')
|
||||
vis:map(vis.modes.NORMAL, "<F2>", ':!nnn ~/git_pk/Latex-RR<Enter>')
|
||||
end)
|
||||
|
||||
-- configuración por ventana
|
||||
vis.events.subscribe(vis.events.WIN_OPEN,
|
||||
function(win)
|
||||
vis:command('set relativenumbers')
|
||||
vis:command('set cursorline')
|
||||
vis:command('set show-eof off')
|
||||
vis:command('set show-tabs')
|
||||
vis:command('set ignorecase')
|
||||
vis:command('set tabwidth 4')
|
||||
vis:command('set autoindent')
|
||||
vis:command('set colorcolumn 89')
|
||||
|
||||
-- configuración para latex
|
||||
-- plantilla de prueba
|
||||
vis:map(vis.modes.NORMAL, "<F8>",
|
||||
':e ~/git_pk/Latex-RR/pruebax/art_prueba.tex<Enter>')
|
||||
|
||||
-- macros
|
||||
-- insertar bloque de definición
|
||||
vis:map(vis.modes.INSERT, "<M-d>",
|
||||
[[\begin{description}<Enter> \item[Foo]<Enter>\end{description}]])
|
||||
|
||||
-- insertar bloque de viñetas
|
||||
vis:map(vis.modes.INSERT, "<M-i>",
|
||||
[[\begin{itemize}<Enter> \item<Enter>\end{itemize}]])
|
||||
|
||||
-- insertar bloque de numeración
|
||||
vis:map(vis.modes.INSERT, "<M-e>",
|
||||
[[\begin{enumerate}<Enter> \item<Enter>\end{enumerate}]])
|
||||
end)
|
||||
|
||||
-- diccionario
|
||||
vis:map(vis.modes.NORMAL, "<F3>",
|
||||
function()
|
||||
vis:command('!hunspell -t $vis_filepath')
|
||||
end)
|
||||
|
||||
-- compilar .tex
|
||||
vis:map(vis.modes.NORMAL, "<F4>",
|
||||
function()
|
||||
vis:command(':w') -- guardar
|
||||
vis:command('!lualatex $vis_filepath') -- compilar
|
||||
vis:info("file .tex guardado y compilado") -- mensaje de salida
|
||||
end)
|
||||
|
||||
-- compilar .tex -- makefile
|
||||
vis:map(vis.modes.NORMAL, "<F5>",
|
||||
function()
|
||||
vis:command(':w') -- guardar
|
||||
vis:command('!make') -- compilar
|
||||
vis:info("file .tex guardado y compilado") -- mensaje de salida
|
||||
end)
|
||||
|
||||
-- visualizar .pdf
|
||||
vis:map(vis.modes.NORMAL, "<F6>",
|
||||
function()
|
||||
vis:command('!vis-open -p seleccionar: *.pdf | xargs -r zathura &')
|
||||
end)
|
||||
|
||||
-- salida file modificado
|
||||
vis:map(vis.modes.NORMAL, "ZZ",
|
||||
function()
|
||||
if vis.win.file.modified then
|
||||
vis:command(':wq')
|
||||
else
|
||||
vis:command(':q!')
|
||||
end
|
||||
end)
|
Loading…
Reference in New Issue