1 -- standard vis event handlers
3 vis
.events
.subscribe(vis
.events
.INIT
, function()
4 if os
.getenv("TERM_PROGRAM") == "Apple_Terminal" then
5 vis
:command("set change-256colors false");
7 vis
:command("set theme ".. (vis
.ui
.colors
<= 16 and "default-16" or "default-256"))
10 vis
:option_register("theme", "string", function(name
)
12 local theme
= 'themes/'..name
13 package
.loaded
[theme
] = nil
17 vis
.lexers
.lexers
= {}
19 for win
in vis
:windows() do
20 win
:set_syntax(win
.syntax
)
23 end, "Color theme to use, filename without extension")
25 vis
:option_register("syntax", "string", function(name
)
26 if not vis
.win
then return false end
27 if not vis
.win
:set_syntax(name
) then
28 vis
:info(string.format("Unknown syntax definition: `%s'", name
))
32 end, "Syntax highlighting lexer to use")
34 vis
:option_register("horizon", "number", function(horizon
)
35 if not vis
.win
then return false end
36 vis
.win
.horizon
= horizon
38 end, "Number of bytes to consider for syntax highlighting")
40 vis
:option_register("redrawtime", "string", function(redrawtime
)
41 if not vis
.win
then return false end
42 local value
= tonumber(redrawtime
)
43 if not value
or value
<= 0 then
44 vis
:info("A positive real number expected")
47 vis
.win
.redrawtime
= value
49 end, "Seconds to wait for syntax highlighting before aborting it")
51 vis
.events
.subscribe(vis
.events
.WIN_HIGHLIGHT
, function(win
)
52 if not win
.syntax
or not vis
.lexers
.load
then return end
53 local lexer
= vis
.lexers
.load(win
.syntax
, nil, true)
54 if not lexer
then return end
56 -- TODO: improve heuristic for initial style
57 local viewport
= win
.viewport
58 if not viewport
then return end
59 local redrawtime_max
= win
.redrawtime
or 1.0
60 local horizon_max
= win
.horizon
or 32768
61 local horizon
= viewport
.start
< horizon_max
and viewport
.start
or horizon_max
62 local view_start
= viewport
.start
63 local lex_start
= viewport
.start
- horizon
64 viewport
.start
= lex_start
65 local data
= win
.file
:content(viewport
)
66 local token_styles
= lexer
._TOKENSTYLES
67 local tokens
, timedout
= lexer
:lex(data
, 1, redrawtime_max
)
68 local token_end
= lex_start
+ (tokens
[#tokens
] or 1) - 1
70 if timedout
then return end
72 for i
= #tokens
- 1, 1, -2 do
73 local token_start
= lex_start
+ (tokens
[i
-1] or 1) - 1
74 if token_end
< view_start
then
77 local name
= tokens
[i
]
78 local style
= token_styles
[name
]
80 win
:style(style
, token_start
, token_end
)
82 token_end
= token_start
- 1
87 [vis
.modes
.NORMAL
] = '',
88 [vis
.modes
.OPERATOR_PENDING
] = '',
89 [vis
.modes
.VISUAL
] = 'VISUAL',
90 [vis
.modes
.VISUAL_LINE
] = 'VISUAL-LINE',
91 [vis
.modes
.INSERT
] = 'INSERT',
92 [vis
.modes
.REPLACE
] = 'REPLACE',
95 vis
.events
.subscribe(vis
.events
.WIN_STATUS
, function(win
)
97 local right_parts
= {}
99 local selection
= win
.selection
101 local mode
= modes
[vis
.mode
]
102 if mode
~= '' and vis
.win
== win
then
103 table.insert(left_parts
, mode
)
106 table.insert(left_parts
, (file
.name
or '[No Name]') ..
107 (file
.modified
and ' [+]' or '') .. (vis
.recording
and ' @' or ''))
109 local count
= vis
.count
110 local keys
= vis
.input_queue
112 table.insert(right_parts
, keys
)
114 table.insert(right_parts
, count
)
117 if #win
.selections
> 1 then
118 table.insert(right_parts
, selection
.number..'/'..#win
.selections
)
121 local size
= file
.size
122 local pos
= selection
.pos
123 if not pos
then pos
= 0 end
124 table.insert(right_parts
, (size
== 0 and "0" or math
.ceil(pos
/size
*100)).."%")
126 if not win
.large
then
127 local col
= selection
.col
128 table.insert(right_parts
, selection
.line
..', '..col
)
129 if size
> 33554432 or col
> 65536 then
134 local left
= ' ' .. table.concat(left_parts
, " » ") .. ' '
135 local right
= ' ' .. table.concat(right_parts
, " « ") .. ' '
136 win
:status(left
, right
);
141 require('plugins/filetype')
142 require('plugins/textobject-lexer')
143 require('plugins/digraph')
144 require('plugins/number-inc-dec')
145 require('plugins/complete-word')
146 require('plugins/complete-filename')