clp

command line syntax highlighter
git clone git://jeskin.net/clp.git
README | Log | Files | Refs | LICENSE

commit 193ed74d445b47aad6d8ba6f7e9eabdf9f04e726
parent 1318913ff4e5084a30d33d22f0c87f61dabf59de
Author: khwerz <khwerz@gmail.com>
Date:   Thu, 21 Jul 2022 21:01:22 -0400

ignored suffixes simplification

Diffstat:
Mlua/ftdetect.lua | 19+++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)

diff --git a/lua/ftdetect.lua b/lua/ftdetect.lua @@ -1,7 +1,7 @@ ftdetect = {} ftdetect.ignoresuffixes = { - "~$", "%.orig$", "%.bak$", "%.old$", "%.new$" + "~+$", "%.orig$", "%.bak$", "%.old$", "%.new$" } ftdetect.filetypes = { @@ -487,19 +487,14 @@ ftdetect.filetypes = { ftdetect.lookup_lexer = function(filename) -- remove ignored suffixes from filename - local sanitizedfn = filename - if sanitizedfn ~= nil then - sanitizedfn = sanitizedfn:gsub('^.*/', '') + local sanitizedfn = filename and filename:match"[^/]-$" + if sanitizedfn then repeat - local changed = false - for _, pattern in pairs(ftdetect.ignoresuffixes) do - local start = sanitizedfn:find(pattern) - if start then - sanitizedfn = sanitizedfn:sub(1, start - 1) - changed = true - end + local changed = sanitizedfn + for _, pattern in ipairs(ftdetect.ignoresuffixes) do + sanitizedfn = sanitizedfn:gsub(pattern,"") end - until not changed + until #sanitizedfn==0 or sanitizedfn == changed end -- detect filetype by filename ending with a configured extension