clp

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

commit 1868ed3014ef51310970452dbd51ce04eae0fc91
parent 93eabba5bde17dffe489c7c65c34566551b43fe6
Author: Jon Eskin <eskinjp@gmail.com>
Date:   Fri, 22 Jul 2022 04:14:51 -0400

Merge pull request #4 from Nomarian/filetype_ignore

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