diff options
author | Gregory Anders <8965202+gpanders@users.noreply.github.com> | 2022-06-09 13:12:36 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-09 13:12:36 -0600 |
commit | 58323b1fe2e494cf6a75f108780e21c08996c08e (patch) | |
tree | a301a6d047003efa3835460a793a87d4f205f785 /runtime/doc | |
parent | 28e43881b74b800fa37957e77b5e56994e1120cd (diff) | |
download | rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.tar.gz rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.tar.bz2 rneovim-58323b1fe2e494cf6a75f108780e21c08996c08e.zip |
feat(filetype): remove side effects from vim.filetype.match (#18894)
Many filetypes from filetype.vim set buffer-local variables, meaning
vim.filetype.match cannot be used without side effects. Instead of
setting these buffer-local variables in the filetype detection functions
themselves, have vim.filetype.match return an optional function value
that, when called, sets these variables. This allows vim.filetype.match
to work without side effects.
Diffstat (limited to 'runtime/doc')
-rw-r--r-- | runtime/doc/lua.txt | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index bdd2e6ff8e..c9fd3d2786 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2011,7 +2011,10 @@ add({filetypes}) *vim.filetype.add()* takes the full path and buffer number of the file as arguments (along with captures from the matched pattern, if any) and should return a string that will be used as the buffer's - filetype. + filetype. Optionally, the function can return a second + function value which, when called, modifies the state of the + buffer. This can be used to, for example, set + filetype-specific buffer variables. Filename patterns can specify an optional priority to resolve cases when a file path matches multiple patterns. Higher @@ -2030,7 +2033,10 @@ add({filetypes}) *vim.filetype.add()* foo = "fooscript", bar = function(path, bufnr) if some_condition() then - return "barscript" + return "barscript", function(bufnr) + -- Set a buffer variable + vim.b[bufnr].barscript_version = 2 + end end return "bar" end, @@ -2059,7 +2065,7 @@ add({filetypes}) *vim.filetype.add()* (see example). match({name}, {bufnr}) *vim.filetype.match()* - Set the filetype for the given buffer from a file name. + Find the filetype for the given filename and buffer. Parameters: ~ {name} (string) File name (can be an absolute or @@ -2067,6 +2073,13 @@ match({name}, {bufnr}) *vim.filetype.match()* {bufnr} (number|nil) The buffer to set the filetype for. Defaults to the current buffer. + Return: ~ + (string|nil) If a match was found, the matched filetype. + (function|nil) A function that modifies buffer state when + called (for example, to set some filetype specific buffer + variables). The function accepts a buffer number as its + only argument. + ============================================================================== Lua module: keymap *lua-keymap* |