1 local ok
, msg
= pcall(function()
3 vis
.lexers
= require('lexer')
7 vis
:info('WARNING: could not load lexer module, is lpeg installed?')
12 vis
.motion_new
= function(vis
, key
, motion
)
13 local id
= vis
:motion_register(motion
)
17 local binding
= function()
20 vis
:map(vis
.MODE_NORMAL
, key
, binding
)
21 vis
:map(vis
.MODE_VISUAL
, key
, binding
)
22 vis
:map(vis
.MODE_OPERATOR_PENDING
, key
, binding
)
26 vis
.textobject_new
= function(vis
, key
, textobject
)
27 local id
= vis
:textobject_register(textobject
)
31 local binding
= function()
34 vis
:map(vis
.MODE_VISUAL
, key
, binding
)
35 vis
:map(vis
.MODE_OPERATOR_PENDING
, key
, binding
)
39 vis
:textobject_new("ii", function(win
, pos
)
41 if win
.syntax
== nil then
45 local before
, after
= pos
- 4096, pos
+ 4096;
49 -- TODO make sure we start at a line boundary?
51 local lexer
= vis
.lexers
.load(win
.syntax
)
52 local data
= win
.file
:content(before
, after
- before
)
53 local tokens
= lexer
:lex(data
)
55 -- print(before..", "..pos..", ".. after)
57 for i
= 1, #tokens
, 2 do
58 local name
= tokens
[i
]
59 local token_next
= before
+ tokens
[i
+1] - 1
60 -- print(name..": ["..cur..", "..token_next.."] pos: "..pos)
61 if cur
<= pos
and pos
< token_next
then
62 return cur
, token_next
70 vis
.events
.win_open
= function(win
)
73 [".1|.2|.3|.4|.5|.6|.7|.8|.9|.1x|.2x|.3x|.4x|.5x|.6x|.7x|.8x|.9x"] = "man",
74 [".au3|.a3x"] = "autoit",
75 [".as|.asc"] = "actionscript",
76 [".adb|.ads"] = "ada",
78 [".ans|.inp|.mac"] = "apdl",
80 [".applescript"] = "applescript",
81 [".asm|.ASM|.s|.S"] = "asm",
82 [".asa|.asp|.hta"] = "asp",
84 [".bat|.cmd"] = "batch",
88 [".c|.cc|.C"] = "ansi_c",
89 [".cpp|.cxx|.c++|.h|.hh|.hpp|.hxx|.h++"] = "cpp",
91 [".cmake|.cmake.in|.ctest|.ctest.in"] = "cmake",
92 [".coffee"] = "coffeescript",
94 [".cu|.cuh"] = "cuda",
97 [".desktop"] = "desktop",
98 [".diff|.patch"] = "diff",
99 ["Dockerfile"] = "dockerfile",
101 [".e|.eif"] = "eiffel",
102 [".ex|.exs"] = "elixir",
103 [".erl|.hrl"] = "erlang",
105 [".feature"] = "gherkin",
108 [".forth|.frt|.fs"] = "forth",
109 [".f|.for|.ftn|.fpp|.f77|.f90|.f95|.f03|.f08"] = "fortran",
110 [".g|.gd|.gi|.gap"] = "gap",
111 [".po|.pot"] = "gettext",
112 [".glslf|.glslv"] = "glsl",
113 [".dem|.plt"] = "gnuplot",
115 [".groovy|.gvy"] = "groovy",
116 [".gtkrc"] = "gtkrc",
118 [".htm|.html|.shtm|.shtml|.xhtml"] = "html",
120 [".idl|.odl"] = "idl",
121 [".inf|.ni"] = "inform",
122 [".cfg|.cnf|.inf|.ini|.reg"] = "ini",
124 [".bsh|.java"] = "java",
125 [".js|.jsfl"] = "javascript",
128 [".bbl|.dtx|.ins|.ltx|.tex|.sty"] = "latex",
130 [".lily|.ly"] = "lilypond",
131 [".ledger|.journal"] = "ledger",
132 [".cl|.el|.lisp|.lsp"] = "lisp",
133 [".litcoffee"] = "litcoffee",
135 ["GNUmakefile|.iface|.mak|.mk|makefile|Makefile"] = "makefile",
136 [".md"] = "markdown",
137 [".moon"] = "moonscript",
140 [".nsh|.nsi|.nsis"] = "nsis",
141 [".m|.mm|.objc"] = "objective_c",
142 [".caml|.ml|.mli|.mll|.mly"] = "caml",
143 [".dpk|.dpr|.p|.pas"] = "pascal",
144 [".al|.perl|.pl|.pm|.pod"] = "perl",
145 [".inc|.php|.php3|.php4|.phtml"] = "php",
147 [".pike|.pmod"] = "pike",
148 ["PKGBUILD"] = "pkgbuild",
149 [".ps1"] = "powershell",
151 [".prolog"] = "prolog",
152 [".props|.properties"] = "props",
154 [".sc|.py|.pyw"] = "python",
155 [".R|.Rout|.Rhistory|.Rt|Rout.save|Rout.fail"] = "rstats",
156 [".r|.reb"] = "rebol",
158 [".orx|.rex"] = "rexx",
159 [".erb|.rhtml"] = "rhtml",
160 [".Rakefile|.rake|.rb|.rbw"] = "ruby",
162 [".sass|.scss"] = "sass",
163 [".scala"] = "scala",
164 [".sch|.scm"] = "scheme",
165 [".sno|.SNO"] = "snobol4",
166 [".bash|.bashrc|.bash_profile|.configure|.csh|.sh|.zsh"] = "bash",
167 [".changes|.st|.sources"] = "smalltalk",
168 [".ddl|.sql"] = "sql",
169 [".tcl|.tk"] = "tcl",
170 [".texi"] = "texinfo",
173 [".vcf|.vcard"] = "vcard",
174 [".v|.ver"] = "verilog",
175 [".vh|.vhd|.vhdl"] = "vhdl",
176 [".asa|.bas|.cls|.ctl|.dob|.dsm|.dsr|.frm|.pag|.vb|.vba|.vbs"] = "vb",
178 [".dtd|.svg|.xml|.xsd|.xsl|.xslt|.xul"] = "xml",
179 [".xtend"] = "xtend",
183 local filename
= win
.file
.name
185 if filename
~= nil then
186 -- filename = string.lower(filename)
187 for patterns
, lang
in pairs(files
) do
188 for pattern
in string.gmatch(patterns
, '[^|]+') do
189 if #filename
>= #pattern
then
190 local s
, e
= string.find(filename
, pattern
, -#pattern
, true)
191 if s
~= e
and e
== #filename
then