Commit Graph

21 Commits

Author SHA1 Message Date
dundargoc
aa6b9c677d refactor: use vim._with where possible
This mostly means replacing `nvim_buf_call` and `nvim_win_call` with
`vim._with`.
2024-06-28 19:58:31 +02:00
zeertzjq
5a8a34dafa
fix(filetype): source ftdetect/* after creating scripts.vim autocmds (#29445) 2024-06-22 21:17:36 +08:00
zeertzjq
2955c921ce
fix(filetype): use unexpanded file name (#27931)
When the edited file is a symlink, the unexpanded file name is needed to
to achieve the same behavior as the autocommand pattern matching in Vim.
Neither args.file nor args.match are guaranteed to be unexpanded, so use
bufname() instead.
2024-03-23 11:46:23 +08:00
Hongbo Liu
670c7609c8
fix(filetype): make sure buffer is valid before call nvim_buf_call (#24922) 2023-08-30 10:14:58 -05:00
Gregory Anders
020d1f626a fix(filetype): call on_detect before setting buffer filetype
The on_detect functions returned by filetype.lua set buffer local
variables which are often used by filetype plugins. For example, the
on_detect function for shell buffers sets variables such as b:is_bash or
b:is_sh, which are used by the sh ftplugin.

When called after setting the buffer's filetype, these variables cannot
be used by the ftplugin (because they are not yet defined). Instead,
call on_detect before setting the buffer filetype so that any buffer
variables set by on_detect can be used in the ftplugin.
2023-08-24 12:48:21 -05:00
zeertzjq
dbb840da01
fix(runtime): respect 'rtp' order for all runtime files (#24335) 2023-07-14 06:46:16 +08:00
Christian Clason
042eb74ff1
feat(runtime)!: remove filetype.vim (#20428)
Made obsolete by now graduated `filetype.lua` (enabled by default).

Note that changes or additions to the filetype detection still need to
be made through a PR to vim/vim as we port the _logic_ as well as tests.
2022-10-17 08:52:40 +02:00
zeertzjq
f8a1cadccf
fix(filetype): use :setf instead of nvim_buf_set_option (#20334) 2022-09-25 16:29:25 +02:00
Christian Clason
927d4d2a15
fix(filetype): run filetype.match on StdinReadPost (#20070)
Problem: filetype detection does not run on piped input
Solution: add `StdinReadPost` to main filetype.lua autocommand

Rationale: legacy filetype detection checked contents by sourcing
`scripts.vim` in separate autocommands, including on `StdinReadPost`.
For Lua filetype detection, this was moved into the main autocommand,
with bundled `scripts.vim` gated behind `g:do_legacy_filetype` (i.e.,
only user `scripts.vim` are sourced for compatibility by default). Adding
`StdinReadPost` to the main autocommand again runs content checks on
piped input without requiring code duplication and low-payoff
refactoring.
2022-09-03 19:27:57 +02:00
Christian Clason
72877bb17d
feat(runtime)!: enable filetype.lua by default (#19216)
* revert to filetype.vim by setting `g:do_legacy_filetype`
* skip either filetype.lua or filetype.vim via `g:did_load_filetypes`

(Running both is no longer required and therefore no longer supported.)
2022-07-07 18:53:47 +02:00
smjonas
f9683f2823 fix(filetype): remove call to vim.fn.resolve and pass filename to match function
For example on MacOS, /etc/hostname.file is symlinked to
/private/etc/hostname.file. We only care about the original file path though.
2022-07-06 16:25:51 +02:00
smjonas
f3c78a4465 fix(filetype): fix filetype patterns 2022-07-06 16:25:23 +02:00
Gregory Anders
f3ce06cfa1
refactor(filetype)!: allow vim.filetype.match to use different strategies (#18895)
This enables vim.filetype.match to match based on a buffer (most
accurate) or simply a filename or file contents, which are less accurate
but may still be useful for some scenarios.

When matching based on a buffer, the buffer's name and contents are both
used to do full filetype matching. When using a filename, if the file
exists the file is loaded into a buffer and full filetype detection is
performed. If the file does not exist then filetype matching is only
performed against the filename itself. Content-based matching does the
equivalent of scripts.vim, and matches solely based on file contents
without any information from the name of the file itself (e.g. for
shebangs).

BREAKING CHANGE: use `vim.filetype.match({buf = bufnr})` instead 
of `vim.filetype.match(name, bufnr)`
2022-06-26 18:41:20 +02:00
Gregory Anders
58323b1fe2
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.
2022-06-09 13:12:36 -06:00
Christian Clason
aefdc6783c chore: format runtime with stylua 2022-05-09 16:31:55 +02:00
Christian Clason
5c53e29ca9
fix(ftdetect): source plugins in autogroup (#18237)
In `filetype.lua`, source runtime `ftdetect` scripts within the `filetypedetect` augroup, same as `filetype.vim` (and only do so if `g:did_load_ftdetect` does not exist).
2022-04-23 17:57:38 +02:00
Gregory Anders
f9f843e02e
refactor: use Lua autocommands in filetype.lua (#17711) 2022-03-13 15:52:41 -06:00
Gregory Anders
fdea15723f
feat(filetype): support scripts.vim with filetype.lua (#17517)
When filetype.vim is disabled, create the autocommand that runs
scripts.vim in filetype.lua.
2022-02-24 10:02:17 -07:00
Gregory Anders
f40ce34563
fix(filetype): match on <afile> rather than <abuf> (#16943)
Filetype detection runs on BufRead and BufNewFile autocommands, both of
which can fire without an underlying buffer, so it's incorrect to use
<abuf> to determine the file path. Instead, match on <afile> and assume
that the buffer we're operating on is the current buffer. This is the
same assumption that filetype.vim makes, so it should be safe.
2022-01-05 09:50:54 -07:00
Gregory Anders
60d3bb745d
fix(filetype): set default ft_ignore_pat in filetype.lua (#16917)
This default value is also set in filetype.vim, but if filetype.vim is
disabled the variable is never defined, which causes errors in some of
the dist#ft detection functions.
2022-01-04 15:02:01 -07:00
Gregory Anders
3fd454bd4a
feat: filetype.lua (#16600)
Adds a new vim.filetype module that provides support for filetype detection in
Lua.
2022-01-04 07:28:29 -07:00