New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose filetype matching from filetype.lua #18241
Comments
Hi, Has anyone started on this already? |
I propose a new file To expand further, I agree that callback = function(args)
vim.api.nvim_buf_set_option(args.buf, "filetype", vim.filetype.match(args.buf))
end |
Not yet -- go for it! As @gpanders wrote, create a new file and translate the functions one-by-one; you can call them from foo = function(path, bufnr)
return require'filetype.detect'.foo()
end (which is the Lua version of "autoloading"). Best start with the simplest ones; one commit per function. There are already some simple functions in |
Awesome, thanks for the guidance! |
Also write a lua version of dist#ft#FTtf and use it in filetype.lua Work on neovim#18241
Hi, I could use a hand with the
regex has proven a bit tricky, so I'm wondering if I should use another pattern or just do:
and use |
This almost works: local line = getline(n)
if line:find("{%%%s*extends") or line:find("{%%%s*block") or line:find("{%%%s*load") or line:find("{#%s+") then But AFAIK Lua patterns don't have any equivalent to Vim's I'll have to think about whether or not we want to use |
Also write a lua version of dist#ft#FTtf and use it in filetype.lua Work on neovim#18241
Also write a lua version of dist#ft#FTtf and use it in filetype.lua Work on neovim#18241
Looks like someone did beat you to it (sorry!): #18247 That PR is still missing the As an alternative, you could focus your attention on |
No worries! Thanks, I'll try again on the weekend so I don't get swept away by work, cheers! |
Superseded by #18604 |
Currently,
filetype.lua
reproduces the behavior offiletype.vim
in that thevim.filetype.match()
function directly sets the filetype of a buffer as soon as a match for the file is found. However, there are situations when it is useful to just know the filetype without setting it (e.g., for getting the right treesitter parser, or for previewing a file with syntax highlighting without firing all ftplugins for it).Ideally,
vim.filetype.match()
should be refactored to return the found filetype as a string (which is then used in theBufRead
autocommand to set the filetype). The difficulty here is thatfiletype.lua
still relies on the legacydist#ft
functions for more complicated content checks -- which set the filetype directly. (And similarly forruntime/scripts.vim
.)The simplest (in terms of complexity, not amount of work) approach would be to rewrite these in Lua as well and have them return the filetype instead. This would make porting new filetypes from Vim a bit harder, but a) upstream has already rewritten that file in Vim9script anyway and b) the same type of manual intervention is already done for the simpler (but otherwise similar) inlined functions in
filetype.lua
-- which could then be moved to a common submodule to remove this somewhat arbitrary distinction.The text was updated successfully, but these errors were encountered: