Skip to content

Commit

Permalink
vis: move non-configuration sections out of visrc.lua into vis.lua
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
martanne committed Apr 29, 2016
1 parent c32c4b7 commit 9c573ea
Show file tree
Hide file tree
Showing 4 changed files with 209 additions and 202 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
203 changes: 203 additions & 0 deletions vis.lua
Original file line number Diff line number Diff line change
@@ -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

Loading

0 comments on commit 9c573ea

Please sign in to comment.