diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-04-29 08:59:31 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-04-29 09:06:08 +0200 |
| commit | 9c573eaf13f882bfb3deb44268bd5bd8947b0260 (patch) | |
| tree | 093966fa8496fdefb005be75fe624f02ebf3431b | |
| parent | c32c4b7b41dcf0e170266f819b6a839fa4eac56d (diff) | |
| download | vis-9c573eaf13f882bfb3deb44268bd5bd8947b0260.tar.gz vis-9c573eaf13f882bfb3deb44268bd5bd8947b0260.tar.xz | |
vis: move non-configuration sections out of visrc.lua into vis.lua
The intention is that vis.lua will provide parts of the Lua API not
implemented in the C core.
Please update your existing visrc.lua configuration file accordingly.
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | vis.lua | 203 | ||||
| -rw-r--r-- | visrc.lua | 205 |
4 files changed, 209 insertions, 202 deletions
@@ -84,7 +84,7 @@ install: vis @chmod 755 ${DESTDIR}${PREFIX}/bin/vis-clipboard @echo installing support files to ${DESTDIR}${SHAREPREFIX}/vis @mkdir -p ${DESTDIR}${SHAREPREFIX}/vis - @cp -r visrc.lua lexers ${DESTDIR}${SHAREPREFIX}/vis + @cp -r visrc.lua vis.lua lexers ${DESTDIR}${SHAREPREFIX}/vis @echo installing manual page to ${DESTDIR}${MANPREFIX}/man1 @mkdir -p ${DESTDIR}${MANPREFIX}/man1 @sed "s/VERSION/${VERSION}/g" < vis.1 > ${DESTDIR}${MANPREFIX}/man1/vis.1 @@ -885,6 +885,7 @@ A quick overview over the code structure to get you started: `vis-operators.c` | vi(m) operator implementation `vis-prompt.c` | `:`, `/` and `?` prompt implemented as a regular file/window with custom key bindings `vis-text-objects.c`| vi(m) text object implementations, uses `text-objects.h` internally + `vis.lua` | Lua library for vis, providing parts of the exposed API `visrc.lua` | Lua startup and configuration script Testing infrastructure for the [low level core data structures] @@ -0,0 +1,203 @@ +-- Vis Lua plugin API standard library + +local ok, msg = pcall(function() + vis.lexers = {} + vis.lexers = require('lexer') +end) + +if not ok then + vis:info('WARNING: could not load lexer module, is lpeg installed?') +end + +vis.events = {} + +vis.motion_new = function(vis, key, motion) + local id = vis:motion_register(motion) + if id < 0 then + return false + end + local binding = function() + vis:motion(id) + end + vis:map(vis.MODE_NORMAL, key, binding) + vis:map(vis.MODE_VISUAL, key, binding) + vis:map(vis.MODE_OPERATOR_PENDING, key, binding) + return true +end + +vis.textobject_new = function(vis, key, textobject) + local id = vis:textobject_register(textobject) + if id < 0 then + return false + end + local binding = function() + vis:textobject(id) + end + vis:map(vis.MODE_VISUAL, key, binding) + vis:map(vis.MODE_OPERATOR_PENDING, key, binding) + return true +end + +vis:textobject_new("ii", function(win, pos) + + if win.syntax == nil then + return pos, pos + end + + local before, after = pos - 4096, pos + 4096 + if before < 0 then + before = 0 + end + -- TODO make sure we start at a line boundary? + + local lexer = vis.lexers.load(win.syntax) + local data = win.file:content(before, after - before) + local tokens = lexer:lex(data) + local cur = before + -- print(before..", "..pos..", ".. after) + + for i = 1, #tokens, 2 do + local name = tokens[i] + local token_next = before + tokens[i+1] - 1 + -- print(name..": ["..cur..", "..token_next.."] pos: "..pos) + if cur <= pos and pos < token_next then + return cur, token_next + end + cur = token_next + end + + return pos, pos +end) + +vis.filetypes = { + [".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man", + [".au3|.a3x"] = "autoit", + [".as|.asc"] = "actionscript", + [".adb|.ads"] = "ada", + [".g|.g4"] = "antlr", + [".ans|.inp|.mac"] = "apdl", + [".apl"] = "apl", + [".applescript"] = "applescript", + [".asm|.ASM|.s|.S"] = "asm", + [".asa|.asp|.hta"] = "asp", + [".awk"] = "awk", + [".bat|.cmd"] = "batch", + [".bib"] = "bibtex", + [".boo"] = "boo", + [".cs"] = "csharp", + [".c|.cc|.C"] = "ansi_c", + [".cpp|.cxx|.c++|.h|.hh|.hpp|.hxx|.h++"] = "cpp", + [".ck"] = "chuck", + [".cmake|.cmake.in|.ctest|.ctest.in"] = "cmake", + [".coffee"] = "coffeescript", + [".css"] = "css", + [".cu|.cuh"] = "cuda", + [".d|.di"] = "dmd", + [".dart"] = "dart", + [".desktop"] = "desktop", + [".diff|.patch"] = "diff", + ["Dockerfile"] = "dockerfile", + [".dot"] = "dot", + [".e|.eif"] = "eiffel", + [".ex|.exs"] = "elixir", + [".erl|.hrl"] = "erlang", + [".dsp"] = "faust", + [".feature"] = "gherkin", + [".fs"] = "fsharp", + [".fish"] = "fish", + [".forth|.frt|.fs"] = "forth", + [".f|.for|.ftn|.fpp|.f77|.f90|.f95|.f03|.f08"] = "fortran", + [".g|.gd|.gi|.gap"] = "gap", + [".po|.pot"] = "gettext", + [".glslf|.glslv"] = "glsl", + [".dem|.plt"] = "gnuplot", + [".go"] = "go", + [".groovy|.gvy"] = "groovy", + [".gtkrc"] = "gtkrc", + [".hs"] = "haskell", + [".htm|.html|.shtm|.shtml|.xhtml"] = "html", + [".icn"] = "icon", + [".idl|.odl"] = "idl", + [".inf|.ni"] = "inform", + [".cfg|.cnf|.inf|.ini|.reg"] = "ini", + [".io"] = "io_lang", + [".bsh|.java"] = "java", + [".js|.jsfl"] = "javascript", + [".json"] = "json", + [".jsp"] = "jsp", + [".bbl|.dtx|.ins|.ltx|.tex|.sty"] = "latex", + [".less"] = "less", + [".lily|.ly"] = "lilypond", + [".ledger|.journal"] = "ledger", + [".cl|.el|.lisp|.lsp"] = "lisp", + [".litcoffee"] = "litcoffee", + [".lua"] = "lua", + ["GNUmakefile|.iface|.mak|.mk|makefile|Makefile"] = "makefile", + [".md|.markdown"] = "markdown", + [".moon"] = "moonscript", + [".n"] = "nemerle", + [".nim"] = "nim", + [".nsh|.nsi|.nsis"] = "nsis", + [".m|.mm|.objc"] = "objective_c", + [".caml|.ml|.mli|.mll|.mly"] = "caml", + [".dpk|.dpr|.p|.pas"] = "pascal", + [".al|.perl|.pl|.pm|.pod"] = "perl", + [".inc|.php|.php3|.php4|.phtml"] = "php", + [".p8"] = "pico8", + [".pike|.pmod"] = "pike", + ["PKGBUILD"] = "pkgbuild", + [".ps1"] = "powershell", + [".eps|.ps"] = "ps", + [".prolog"] = "prolog", + [".props|.properties"] = "props", + [".pure"] = "pure", + [".sc|.py|.pyw"] = "python", + [".R|.Rout|.Rhistory|.Rt|Rout.save|Rout.fail"] = "rstats", + [".r|.reb"] = "rebol", + [".rst"] = "rest", + [".orx|.rex"] = "rexx", + [".erb|.rhtml"] = "rhtml", + [".Rakefile|.rake|.rb|.rbw"] = "ruby", + [".rs"] = "rust", + [".sass|.scss"] = "sass", + [".scala"] = "scala", + [".sch|.scm"] = "scheme", + [".sno|.SNO"] = "snobol4", + [".bash|.bashrc|.bash_profile|.configure|.csh|.sh|.zsh"] = "bash", + [".changes|.st|.sources"] = "smalltalk", + [".ddl|.sql"] = "sql", + [".tcl|.tk"] = "tcl", + [".texi"] = "texinfo", + [".toml"] = "toml", + [".vala"] = "vala", + [".vcf|.vcard"] = "vcard", + [".v|.ver"] = "verilog", + [".vh|.vhd|.vhdl"] = "vhdl", + [".asa|.bas|.cls|.ctl|.dob|.dsm|.dsr|.frm|.pag|.vb|.vba|.vbs"] = "vb", + [".wsf"] = "wsf", + [".dtd|.svg|.xml|.xsd|.xsl|.xslt|.xul"] = "xml", + [".xtend"] = "xtend", + [".yaml"] = "yaml", +} + +vis.filetype_detect = function(win) + local filename = win.file.name + + if filename ~= nil then + -- filename = string.lower(filename) + for patterns, lang in pairs(vis.filetypes) do + for pattern in string.gmatch(patterns, '[^|]+') do + if #filename >= #pattern then + local s, e = string.find(filename, pattern, -#pattern, true) + if s ~= e and e == #filename then + win.syntax = lang + return + end + end + end + end + end + + win.syntax = nil +end + @@ -1,206 +1,9 @@ -local ok, msg = pcall(function() - vis.lexers = {} - vis.lexers = require('lexer') -end) - -if not ok then - vis:info('WARNING: could not load lexer module, is lpeg installed?') -end - -vis.events = {} - -vis.motion_new = function(vis, key, motion) - local id = vis:motion_register(motion) - if id < 0 then - return false - end - local binding = function() - vis:motion(id) - end - vis:map(vis.MODE_NORMAL, key, binding) - vis:map(vis.MODE_VISUAL, key, binding) - vis:map(vis.MODE_OPERATOR_PENDING, key, binding) - return true -end - -vis.textobject_new = function(vis, key, textobject) - local id = vis:textobject_register(textobject) - if id < 0 then - return false - end - local binding = function() - vis:textobject(id) - end - vis:map(vis.MODE_VISUAL, key, binding) - vis:map(vis.MODE_OPERATOR_PENDING, key, binding) - return true -end - -vis:textobject_new("ii", function(win, pos) - - if win.syntax == nil then - return pos, pos - end - - local before, after = pos - 4096, pos + 4096; - if before < 0 then - before = 0 - end - -- TODO make sure we start at a line boundary? - - local lexer = vis.lexers.load(win.syntax) - local data = win.file:content(before, after - before) - local tokens = lexer:lex(data) - local cur = before - -- print(before..", "..pos..", ".. after) - - for i = 1, #tokens, 2 do - local name = tokens[i] - local token_next = before + tokens[i+1] - 1 - -- print(name..": ["..cur..", "..token_next.."] pos: "..pos) - if cur <= pos and pos < token_next then - return cur, token_next - end - cur = token_next - end - - return pos, pos -end) - -local set_filetype = function(win) - local files = { - [".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man", - [".au3|.a3x"] = "autoit", - [".as|.asc"] = "actionscript", - [".adb|.ads"] = "ada", - [".g|.g4"] = "antlr", - [".ans|.inp|.mac"] = "apdl", - [".apl"] = "apl", - [".applescript"] = "applescript", - [".asm|.ASM|.s|.S"] = "asm", - [".asa|.asp|.hta"] = "asp", - [".awk"] = "awk", - [".bat|.cmd"] = "batch", - [".bib"] = "bibtex", - [".boo"] = "boo", - [".cs"] = "csharp", - [".c|.cc|.C"] = "ansi_c", - [".cpp|.cxx|.c++|.h|.hh|.hpp|.hxx|.h++"] = "cpp", - [".ck"] = "chuck", - [".cmake|.cmake.in|.ctest|.ctest.in"] = "cmake", - [".coffee"] = "coffeescript", - [".css"] = "css", - [".cu|.cuh"] = "cuda", - [".d|.di"] = "dmd", - [".dart"] = "dart", - [".desktop"] = "desktop", - [".diff|.patch"] = "diff", - ["Dockerfile"] = "dockerfile", - [".dot"] = "dot", - [".e|.eif"] = "eiffel", - [".ex|.exs"] = "elixir", - [".erl|.hrl"] = "erlang", - [".dsp"] = "faust", - [".feature"] = "gherkin", - [".fs"] = "fsharp", - [".fish"] = "fish", - [".forth|.frt|.fs"] = "forth", - [".f|.for|.ftn|.fpp|.f77|.f90|.f95|.f03|.f08"] = "fortran", - [".g|.gd|.gi|.gap"] = "gap", - [".po|.pot"] = "gettext", - [".glslf|.glslv"] = "glsl", - [".dem|.plt"] = "gnuplot", - [".go"] = "go", - [".groovy|.gvy"] = "groovy", - [".gtkrc"] = "gtkrc", - [".hs"] = "haskell", - [".htm|.html|.shtm|.shtml|.xhtml"] = "html", - [".icn"] = "icon", - [".idl|.odl"] = "idl", - [".inf|.ni"] = "inform", - [".cfg|.cnf|.inf|.ini|.reg"] = "ini", - [".io"] = "io_lang", - [".bsh|.java"] = "java", - [".js|.jsfl"] = "javascript", - [".json"] = "json", - [".jsp"] = "jsp", - [".bbl|.dtx|.ins|.ltx|.tex|.sty"] = "latex", - [".less"] = "less", - [".lily|.ly"] = "lilypond", - [".ledger|.journal"] = "ledger", - [".cl|.el|.lisp|.lsp"] = "lisp", - [".litcoffee"] = "litcoffee", - [".lua"] = "lua", - ["GNUmakefile|.iface|.mak|.mk|makefile|Makefile"] = "makefile", - [".md|.markdown"] = "markdown", - [".moon"] = "moonscript", - [".n"] = "nemerle", - [".nim"] = "nim", - [".nsh|.nsi|.nsis"] = "nsis", - [".m|.mm|.objc"] = "objective_c", - [".caml|.ml|.mli|.mll|.mly"] = "caml", - [".dpk|.dpr|.p|.pas"] = "pascal", - [".al|.perl|.pl|.pm|.pod"] = "perl", - [".inc|.php|.php3|.php4|.phtml"] = "php", - [".p8"] = "pico8", - [".pike|.pmod"] = "pike", - ["PKGBUILD"] = "pkgbuild", - [".ps1"] = "powershell", - [".eps|.ps"] = "ps", - [".prolog"] = "prolog", - [".props|.properties"] = "props", - [".pure"] = "pure", - [".sc|.py|.pyw"] = "python", - [".R|.Rout|.Rhistory|.Rt|Rout.save|Rout.fail"] = "rstats", - [".r|.reb"] = "rebol", - [".rst"] = "rest", - [".orx|.rex"] = "rexx", - [".erb|.rhtml"] = "rhtml", - [".Rakefile|.rake|.rb|.rbw"] = "ruby", - [".rs"] = "rust", - [".sass|.scss"] = "sass", - [".scala"] = "scala", - [".sch|.scm"] = "scheme", - [".sno|.SNO"] = "snobol4", - [".bash|.bashrc|.bash_profile|.configure|.csh|.sh|.zsh"] = "bash", - [".changes|.st|.sources"] = "smalltalk", - [".ddl|.sql"] = "sql", - [".tcl|.tk"] = "tcl", - [".texi"] = "texinfo", - [".toml"] = "toml", - [".vala"] = "vala", - [".vcf|.vcard"] = "vcard", - [".v|.ver"] = "verilog", - [".vh|.vhd|.vhdl"] = "vhdl", - [".asa|.bas|.cls|.ctl|.dob|.dsm|.dsr|.frm|.pag|.vb|.vba|.vbs"] = "vb", - [".wsf"] = "wsf", - [".dtd|.svg|.xml|.xsd|.xsl|.xslt|.xul"] = "xml", - [".xtend"] = "xtend", - [".yaml"] = "yaml", - } - - local filename = win.file.name - - if filename ~= nil then - -- filename = string.lower(filename) - for patterns, lang in pairs(files) do - for pattern in string.gmatch(patterns, '[^|]+') do - if #filename >= #pattern then - local s, e = string.find(filename, pattern, -#pattern, true) - if s ~= e and e == #filename then - win.syntax = lang - return; - end - end - end - end - end - - win.syntax = nil -end +-- load standard vis module, providing parts of the Lua API +require('vis') vis.events.win_open = function(win) - set_filetype(win) + -- enable syntax highlighting for known file types + vis.filetype_detect(win) -- Your local configuration options e.g. -- vis:command('set number') |
