Skip to content

Commit

Permalink
vis: move file type detection to visrc.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Dec 26, 2015
1 parent 249a885 commit 4cf917a
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ install: vis
@chmod 755 ${DESTDIR}${PREFIX}/bin/vis-open
@echo installing support files to ${DESTDIR}${SHAREPREFIX}
@mkdir -p ${DESTDIR}${SHAREPREFIX}
@cp -r lexers ${DESTDIR}${SHAREPREFIX}
@cp -r visrc.lua lexers ${DESTDIR}${SHAREPREFIX}
@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
119 changes: 0 additions & 119 deletions lexers/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1594,123 +1594,4 @@ function M.get_style(lexer, lang, token_name)
return lexer['STYLE_'..string_upper(token_name)] or lang._EXTRASTYLES[token_name]
end

local files = {
[".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man",
[".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",
[".dot"] = "dot",
[".e|.eif"] = "eiffel",
[".ex|.exs"] = "elixir",
[".erl|.hrl"] = "erlang",
[".dsp"] = "faust",
[".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",
[".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",
[".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",
[".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",
[".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",
}

function M.lexer_name(filename)
-- 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
return lang
end
end
end
end
return nil
end

return M
127 changes: 127 additions & 0 deletions visrc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
vis.lexers = require('lexer')

vis.events = {}

vis.events.win_open = function(win)

local files = {
[".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man",
[".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",
[".dot"] = "dot",
[".e|.eif"] = "eiffel",
[".ex|.exs"] = "elixir",
[".erl|.hrl"] = "erlang",
[".dsp"] = "faust",
[".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",
[".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",
[".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",
[".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",
[".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
vis.command('set syntax '.. lang)
return;
end
end
end
end
end
end

0 comments on commit 4cf917a

Please sign in to comment.