Skip to content

Commit

Permalink
lua: small filetype/style setting cleanup
Browse files Browse the repository at this point in the history
Filetype extension mapping already needs to match regular
expressions so we might as well us it to simplify things.

set_syntax doesn't need to handle pseudo scintilla style
definitions. I couldn't even find any examples of table style
definitions anywhere let alone references to other definitions as
$(style.myvarname) (hint: variables in lua already handle this).
  • Loading branch information
rnpnr committed Apr 29, 2024
1 parent 1fc1756 commit 8be1f68
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
11 changes: 3 additions & 8 deletions lua/plugins/filetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ vis.ftdetect.filetypes = {
ext = { "%.gleam$" },
},
glsl = {
ext = { "%.glslf$", "%.glslv$" },
ext = { "%.glsl[fv]?$" },
},
gnuplot = {
ext = { "%.dem$", "%.plt$" },
Expand All @@ -200,7 +200,7 @@ vis.ftdetect.filetypes = {
mime = { "text/x-haskell" },
},
html = {
ext = { "%.htm$", "%.html$", "%.shtm$", "%.shtml$", "%.xhtml$" },
ext = { "%.[sx]?htm[l]?$" },
mime = { "text/x-html" },
},
icon = {
Expand Down Expand Up @@ -272,12 +272,7 @@ vis.ftdetect.filetypes = {
mime = { "text/x-makefile" },
},
man = {
ext = {
"%.1$", "%.2$", "%.3$", "%.4$", "%.5$", "%.6$", "%.7$",
"%.8$", "%.9$", "%.1x$", "%.2x$", "%.3x$", "%.4x$",
"%.5x$", "%.6x$", "%.7x$", "%.8x$", "%.9x$",
"%.ms$", "%.me$", "%.mom$", "%.mm$", "%.tmac$"
},
ext = { "%.[1-9][xp]?$", "%.ms$", "%.me$", "%.mom$", "%.mm$", "%.tmac$" },
},
markdown = {
ext = { "%.md$", "%.markdown$" },
Expand Down
14 changes: 2 additions & 12 deletions lua/vis.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,15 @@ vis.types.window.set_syntax = function(win, syntax)
local style = lexers['STYLE_' .. token_name:upper():gsub("%.", "_")] or ''
if type(style) == 'table' then
local s = ''
if style.bold then
s = string.format("%s,bold", s)
elseif style.italics then
s = string.format("%s,italics", s)
elseif style.underlined then
s = string.format("%s,underlined", s)
if style.attr then
s = string.format("%s,%s", s, attr)
elseif style.fore then
s = string.format("%s,fore:%s", s, style.fore)
elseif style.back then
s = string.format("%s,back:%s", s, style.back)
end
style = s
end
local pattern = "%$%(style%..*%)"
local prop_name = style:match(pattern)
if prop_name ~= nil then
local real_value = tostring(lexers["STYLE_" .. string.upper(prop_name:sub(9,string.len(prop_name)-1))])
style = string.gsub(style, pattern, real_value)
end
if style ~= nil then win:style_define(id, style) end
end

Expand Down

0 comments on commit 8be1f68

Please sign in to comment.