diff --git a/data/apps/red.lua b/data/apps/red.lua index 44b7142..5a788b6 100644 --- a/data/apps/red.lua +++ b/data/apps/red.lua @@ -441,12 +441,12 @@ function frame:file(f) b = win:new(fn) b.menu = self:menu().buf:gettext() -- clone menu + b.conf = presets.get(fn) or {} if dir then b:set "" b:readdir(fn) b:cur(1) elseif not fn:startswith '+' then - b.conf = presets.get(fn) or {} b:file(fn) if nr == 0 and b:histfile_get() then self:push_win(b) diff --git a/data/lib/red/presets.lua b/data/lib/red/presets.lua index 729a8cb..ed70d0c 100644 --- a/data/lib/red/presets.lua +++ b/data/lib/red/presets.lua @@ -53,4 +53,10 @@ return { syntax = "diff" } }, + {"/$", { ts = 8, + spaces_tab = false, + trim_spaces = false, + syntax = "dir" + } + }, } diff --git a/data/lib/red/syntax/dir.lua b/data/lib/red/syntax/dir.lua new file mode 100644 index 0000000..1f78254 --- /dev/null +++ b/data/lib/red/syntax/dir.lua @@ -0,0 +1,53 @@ +local scheme = require "red/syntax/scheme" + +local function match(ext) + if type(ext) ~= 'table' then + ext = { ext } + end + return function(ctx, txt, i) + local d = 0 + local n = {} + while txt[i] ~= '\n' and txt[i] do + table.insert(n, txt[i]) + i = i + 1 + end + local t = table.concat(n, '') + for _, v in ipairs(ext) do + if (t:lower()):find(v, 1) then + return #n + end + end + end +end + +local col = { + col = scheme.default, + { + start = match("/$"), + stop = '\n', + col = scheme.number, + }, + { + start = match { "%.pdf$", "%.docx?$", "%.rtf$" }, + stop = '\n', + col = scheme.keyword, + }, + { + start = match { "%.log$", "%.txt$", "%.md$" }, + stop = '\n', + col = scheme.string, + }, + { + start = match { "%.jpe?g$", "%.gif$", "%.tiff$", "%.png", "%.xmp", + "%.mp[34]$", "%.avi$", "%.mpeg$", "%.mkv$", "%.webm" }, + stop = '\n', + col = scheme.operator, + }, + { + start = match { "%.zip$", "%.gz$", "%.rar$", "%.arj", "%.tar$" }, + stop = '\n', + col = scheme.lib, + }, +} + +return col diff --git a/data/lib/red/win.lua b/data/lib/red/win.lua index ab69fa4..0082ec6 100644 --- a/data/lib/red/win.lua +++ b/data/lib/red/win.lua @@ -822,6 +822,7 @@ end function win:set(text) self.buf:set(text) self:cur(self:cur()) + self.colorizer = nil end function win:gettext(...)