Last active
November 6, 2020 15:23
-
-
Save liquidev/3021d27a038fe701539523042a5f65e5 to your computer and use it in GitHub Desktop.
my lite plugins
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local syntax = require "core.syntax" | |
local patterns = {} | |
local symbols = { | |
["nil"] = "literal", | |
["true"] = "literal", | |
["false"] = "literal", | |
} | |
local number_patterns = { | |
"0[bB][01][01_]*", | |
"0o[0-7][0-7_]*", | |
"0[xX]%x[%x_]*", | |
"%d[%d_]*%.%d[%d_]*[eE][-+]?%d[%d_]*", | |
"%d[%d_]*%.%d[%d_]*", | |
"%d[%d_]*", | |
} | |
local type_suffix_patterns = {} | |
for _, size in ipairs({"", "8", "16", "32", "64"}) do | |
table.insert(type_suffix_patterns, "'?[fuiFUI]"..size) | |
end | |
for _, pattern in ipairs(number_patterns) do | |
for _, suffix in ipairs(type_suffix_patterns) do | |
table.insert(patterns, { pattern = pattern..suffix, type = "literal" }) | |
end | |
table.insert(patterns, { pattern = pattern, type = "literal" }) | |
end | |
local keywords = { | |
"addr", "and", "as", "asm", | |
"bind", "block", "break", | |
"case", "cast", "concept", "const", "continue", "converter", | |
"defer", "discard", "distinct", "div", "do", | |
"elif", "else", "end", "enum", "except", "export", | |
"finally", "for", "from", "func", | |
"if", "import", "in", "include", "interface", "is", "isnot", "iterator", | |
"let", | |
"macro", "method", "mixin", "mod", | |
"not", "notin", | |
"object", "of", "or", "out", | |
"proc", "ptr", | |
"raise", "ref", "return", | |
"shl", "shr", "static", | |
"template", "try", "tuple", "type", | |
"using", | |
"var", | |
"when", "while", | |
"xor", | |
"yield", | |
} | |
for _, keyword in ipairs(keywords) do | |
symbols[keyword] = "keyword" | |
end | |
local standard_types = { | |
"bool", "byte", | |
"int", "int8", "int16", "int32", "int64", | |
"uint", "uint8", "uint16", "uint32", "uint64", | |
"float", "float32", "float64", | |
"char", "string", "cstring", | |
"pointer", | |
"typedesc", | |
"void", "auto", "any", | |
"untyped", "typed", | |
"clong", "culong", "cchar", "cschar", "cshort", "cint", "csize", "csize_t", | |
"clonglong", "cfloat", "cdouble", "clongdouble", "cuchar", "cushort", | |
"cuint", "culonglong", "cstringArray", | |
} | |
for _, type in ipairs(standard_types) do | |
symbols[type] = "keyword2" | |
end | |
local standard_generic_types = { | |
"range", | |
"array", "open[aA]rray", "varargs", "seq", "set", | |
"sink", "lent", "owned", | |
} | |
for _, type in ipairs(standard_generic_types) do | |
table.insert(patterns, { pattern = type.."%f[%[]", type = "keyword2" }) | |
table.insert(patterns, { pattern = type.." +%f[%w]", type = "keyword2" }) | |
end | |
local user_patterns = { | |
-- comments | |
{ pattern = { "##?%[", "]##?" }, type = "comment" }, | |
{ pattern = "##?.-\n", type = "comment" }, | |
-- strings and chars | |
{ pattern = { '"', '"', '\\' }, type = "string" }, | |
{ pattern = { '"""', '"""[^"]' }, type = "string" }, | |
{ pattern = { "'", "'", '\\' }, type = "literal" }, | |
-- function calls | |
{ pattern = "[a-zA-Z][a-zA-Z0-9_]*%f[(]", type = "function" }, | |
-- identifiers | |
{ pattern = "[A-Z][a-zA-Z0-9_]*", type = "keyword2" }, | |
{ pattern = "[a-zA-Z][a-zA-Z0-9_]*", type = "symbol" }, | |
-- operators | |
{ pattern = "%.%f[^.]", type = "normal" }, | |
{ pattern = ":%f[ ]", type = "normal" }, | |
{ pattern = "[=+%-*/<>@$~&%%|!?%^&.:\\]+", type = "operator" }, | |
} | |
for _, pattern in ipairs(user_patterns) do | |
table.insert(patterns, pattern) | |
end | |
local nim = { | |
files = { "%.nim$", "%.nims$", "%.nimble$" }, | |
comment = "#", | |
patterns = patterns, | |
symbols = symbols, | |
} | |
syntax.add(nim) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local style = require "core.style" | |
local common = require "core.common" | |
style.background = { common.color "#212121" } | |
style.background2 = { common.color "#1a1a1a" } | |
style.background3 = { common.color "#1a1a1a" } | |
style.text = { common.color "#eeffff" } | |
style.caret = { common.color "#dae8e8" } | |
style.accent = { common.color "#89ddff" } | |
style.dim = { common.color "#424242" } | |
style.divider = { common.color "#1a1a1a" } | |
style.selection = { common.color "#2f2f2f" } | |
style.line_number = { common.color "#424242" } | |
style.line_number2 = { common.color "#5a5a5a" } | |
style.line_highlight = { common.color "#2a2a2a" } | |
style.scrollbar = { common.color "#424242" } | |
style.scrollbar2 = { common.color "#424242" } | |
style.syntax["normal"] = { common.color "#eeffff" } | |
style.syntax["symbol"] = { common.color "#eeffff" } | |
style.syntax["comment"] = { common.color "#545454" } | |
style.syntax["keyword"] = { common.color "#c792ea" } | |
style.syntax["keyword2"] = { common.color "#ffcb6b" } | |
style.syntax["number"] = { common.color "#f07178" } | |
style.syntax["literal"] = { common.color "#f07178" } | |
style.syntax["string"] = { common.color "#c3e88d" } | |
style.syntax["operator"] = { common.color "#82aaff" } | |
style.syntax["function"] = { common.color "#82aaff" } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local config = require "core.config" | |
local RootView = require "core.rootview" | |
-- WARNING! by default, this uses a module user.colors.default which is NOT | |
-- preinstalled with lite. creating this module is as simple as adapting | |
-- the colors defined in core.style | |
config.day_theme = "user.colors.summer" | |
config.night_theme = "user.colors.default" | |
config.day_hours = { start = 9, fin = 16.5 } | |
local function get_time_of_day() | |
local time = os.date("*t") | |
return time.hour + time.min / 60 + time.sec / 3600 | |
end | |
local current_theme | |
local update = RootView.update | |
function RootView:update(...) | |
update(self, ...) | |
local hour = get_time_of_day() | |
print(hour) | |
if hour >= config.day_hours.start and hour <= config.day_hours.fin then | |
if current_theme ~= "day" then | |
package.loaded[config.day_theme] = nil | |
require(config.day_theme) | |
current_theme = "day" | |
end | |
else | |
if current_theme ~= "night" then | |
package.loaded[config.night_theme] = nil | |
require(config.night_theme) | |
current_theme = "night" | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local config = require "core.config" | |
local style = require "core.style" | |
local DocView = require "core.docview" | |
local draw_line_text = DocView.draw_line_text | |
config.trailing_whitespace_repr = '•' | |
function DocView:draw_line_text(idx, x, y) | |
draw_line_text(self, idx, x, y) | |
local text = self.doc.lines[idx] | |
local start, fin = text:find("%s+$") | |
if start - fin == 0 then return end | |
local start_x = x + self:get_col_x_offset(idx, start) | |
local fin_x = x + self:get_col_x_offset(idx, fin) | |
local y_offset = self:get_line_text_y_offset() | |
local background_color = style.background | |
local text_color = style.trailing_whitespace or style.syntax["comment"] | |
local start_line, _, fin_line, _ = self.doc:get_selection(true) | |
local text = config.trailing_whitespace_repr:rep(fin - start) | |
renderer.draw_text(self:get_font(), text, start_x, y + y_offset, text_color) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment