diff options
author | Jonas Strittmatter <40792180+smjonas@users.noreply.github.com> | 2022-07-03 15:31:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-03 15:31:56 +0200 |
commit | acb7a902812a064fced5ef7d389bd94cb45764bb (patch) | |
tree | 0e3a40a07f8223e1144e0d2e7d61810b0711a718 /runtime/doc | |
parent | 0313aba77a447558c3b373370b60eb78067e1c4d (diff) | |
download | rneovim-acb7a902812a064fced5ef7d389bd94cb45764bb.tar.gz rneovim-acb7a902812a064fced5ef7d389bd94cb45764bb.tar.bz2 rneovim-acb7a902812a064fced5ef7d389bd94cb45764bb.zip |
refactor(runtime): port scripts.vim to lua (#18710)
Diffstat (limited to 'runtime/doc')
-rw-r--r-- | runtime/doc/lua.txt | 54 |
1 files changed, 37 insertions, 17 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 0e72e89672..3372bc90f7 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -2059,11 +2059,31 @@ add({filetypes}) *vim.filetype.add()* }) < + To add a fallback match on contents (see + |new-filetype-scripts|), use > + + vim.filetype.add { + pattern = { + ['.*'] = { + priority = -math.huge, + function(path, bufnr) + local content = vim.filetype.getlines(bufnr, 1) + if vim.filetype.matchregex(content, { [[^#!.*\<mine\>]] }) then + return 'mine' + elseif vim.filetype.matchregex(content, { [[\<drawing\>]] }) then + return 'drawing' + end + end, + }, + }, + } +< + Parameters: ~ {filetypes} (table) A table containing new filetype maps (see example). -match({arg}) *vim.filetype.match()* +match({args}) *vim.filetype.match()* Perform filetype detection. The filetype can be detected using one of three methods: @@ -2096,22 +2116,22 @@ match({arg}) *vim.filetype.match()* < Parameters: ~ - {arg} (table) Table specifying which matching strategy to - use. Accepted keys are: - • buf (number): Buffer number to use for matching. - Mutually exclusive with {contents} - • filename (string): Filename to use for matching. - When {buf} is given, defaults to the filename of - the given buffer number. The file need not - actually exist in the filesystem. When used - without {buf} only the name of the file is used - for filetype matching. This may result in failure - to detect the filetype in cases where the - filename alone is not enough to disambiguate the - filetype. - • contents (table): An array of lines representing - file contents to use for matching. Can be used - with {filename}. Mutually exclusive with {buf}. + {args} (table) Table specifying which matching strategy + to use. Accepted keys are: + • buf (number): Buffer number to use for matching. + Mutually exclusive with {contents} + • filename (string): Filename to use for matching. + When {buf} is given, defaults to the filename of + the given buffer number. The file need not + actually exist in the filesystem. When used + without {buf} only the name of the file is used + for filetype matching. This may result in + failure to detect the filetype in cases where + the filename alone is not enough to disambiguate + the filetype. + • contents (table): An array of lines representing + file contents to use for matching. Can be used + with {filename}. Mutually exclusive with {buf}. Return: ~ (string|nil) If a match was found, the matched filetype. |