diff options
Diffstat (limited to 'runtime/doc/lua.txt')
-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* |