vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit 4738052aed436f48af9122344a654e5f1734177e
parent d68d10b192561c034ae2e2547ab55a2576828564
Author: Randy Palamar <randy@rnpnr.xyz>
Date:   Thu, 14 Sep 2023 07:48:13 -0600

lua: filetype: use alt_name field to alias to other lexers

This obviously draws on the alt_name parameter used in scintillua
but rather then passing it all the way up to the chain to
lexers.load() we will just handle it in set_filetype().

d5ea653 accidently readded detection for the removed git-commit
lexer which somehow went unnoticed until we readded caching for
the new lexers. Instead of just removing it we can alias to the
diff filetype and only set the colorcolumn for commit messages.
This fixes the incorrect behaviour of adding a colorcolumn to diff
and patch files and thus completely reverts a0d31fb.

Diffstat:
Mlua/plugins/filetype.lua | 9+++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua @@ -99,8 +99,7 @@ vis.ftdetect.filetypes = { ext = { "%.desktop$" }, }, diff = { - ext = { "%.diff$", "%.patch$", "%.rej$", "^COMMIT_EDITMSG$" }, - cmd = { "set colorcolumn 72" }, + ext = { "%.diff$", "%.patch$", "%.rej$" }, }, dmd = { ext = { "%.d$", "%.di$" }, @@ -168,6 +167,7 @@ vis.ftdetect.filetypes = { ext = { "%.feature$" }, }, ['git-commit'] = { + alt_name = "diff", ext = { "^COMMIT_EDITMSG$" }, cmd = { "set colorcolumn 72" }, }, @@ -504,9 +504,10 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) end if not vis.lexers.property then return end local path = vis.lexers.property['lexer.lpeg.home']:gsub(';', '/?.lua;') .. '/?.lua' - local lexpath = package.searchpath('lexers/'..syntax, path) + local lexname = filetype.alt_name or syntax + local lexpath = package.searchpath('lexers/'..lexname, path) if lexpath ~= nil then - win:set_syntax(syntax) + win:set_syntax(lexname) else win:set_syntax(nil) end