Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit72877bb

Browse files
authored
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.)
1 parent0950275 commit72877bb

File tree

8 files changed

+45
-63
lines changed

8 files changed

+45
-63
lines changed

‎runtime/doc/filetype.txt‎

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ This means that the contents of compressed files are not inspected.
177177
If a file type that you want to use is not detected yet, there are a few ways
178178
to add it. In any way, it's better not to modify the $VIMRUNTIME/filetype.lua
179179
or $VIMRUNTIME/filetype.vim files. They will be overwritten when installing a
180-
new version of Nvim.
180+
new version of Nvim. The following explains the legacy Vim mechanism (enabled
181+
if|do_legacy_filetype| is set). For Nvim's default mechanism, see
182+
|vim.filetype.add()|.
181183

182184
A. If you want to overrule all default file type checks.
183185
This works by writing one file for each filetype. The disadvantage is that
@@ -236,39 +238,8 @@ C. If your file type can be detected by the file name or extension.
236238
Write this file as "filetype.vim" in your user runtime directory. For
237239
example, for Unix:>
238240
:w ~/.config/nvim/filetype.vim
239-
<
240-
Alternatively, create a file called "filetype.lua" that adds new
241-
filetypes.
242-
Example:>
243-
vim.filetype.add({
244-
extension = {
245-
foo = "fooscript",
246-
},
247-
filename = {
248-
[".foorc"] = "foorc",
249-
},
250-
pattern = {
251-
[".*/etc/foo/.*%.conf"] = "foorc",
252-
},
253-
})
254-
<
255-
See|vim.filetype.add()|.
256-
*g:do_filetype_lua*
257-
For now, Lua filetype detection is opt-in. You can enable it by adding
258-
the following to your|init.vim|:>
259-
let g:do_filetype_lua = 1
260-
<*g:did_load_filetypes*
261-
In either case, the builtin filetype detection provided by Nvim can be
262-
disabled by setting the did_load_filetypes global variable. If this
263-
variable exists, $VIMRUNTIME/filetype.vim will not run.
264-
Example:>
265-
" Disable filetype.vim (but still load filetype.lua if enabled)
266-
let g:did_load_filetypes = 0
267241
268-
" Disable filetype.vim and filetype.lua
269-
let g:did_load_filetypes = 1
270-
271-
< 3. To use the new filetype detection you must restart Vim.
242+
< 3. To use the new filetype detection you must restart Vim.
272243

273244
Your filetype.vim will be sourced before the default FileType autocommands
274245
have been installed. Your autocommands will match first, and the
@@ -315,6 +286,16 @@ the 'runtimepath' for a directory to use. If there isn't one, set
315286
'runtimepath' in the|system-vimrc|. Be careful to keep the default
316287
directories!
317288

289+
*g:do_legacy_filetype*
290+
To disable Nvim's default filetype detection and revert to Vim's legacy
291+
filetype detection, add the following to your|init.vim|:>
292+
let g:do_legacy_filetype = 1
293+
<*g:did_load_filetypes*
294+
The builtin filetype detection provided by Nvim can be disabled by setting
295+
the`did_load_filetypes` global variable. If this variable exists, neither
296+
the default`$VIMRUNTIME/filetype.lua` nor the legacy`$VIMRUNTIME/filetype.vim`
297+
will run.
298+
318299
*plugin-details*
319300
The "plugin" directory can be in any of the directories in the'runtimepath'
320301
option. All of these directories will be searched for plugins and they are

‎runtime/doc/lua.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2022,8 +2022,8 @@ add({filetypes}) *vim.filetype.add()*
20222022

20232023
See $VIMRUNTIME/lua/vim/filetype.lua for more examples.
20242024

2025-
Note that Lua filetype detection isonly enabled when
2026-
|g:do_filetype_lua| is set to 1.
2025+
Note that Lua filetype detection isdisabled when
2026+
|g:do_legacy_filetype| is set.
20272027

20282028
Example:>
20292029

‎runtime/filetype.lua‎

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
ifvim.g.did_load_filetypesandvim.g.did_load_filetypes~=0then
2-
return
3-
end
4-
5-
-- For now, make this opt-in with a global variable
6-
ifvim.g.do_filetype_lua~=1then
1+
-- Skip if legacy filetype is enabled or filetype detection is disabled
2+
ifvim.g.do_legacy_filetypeorvim.g.did_load_filetypesthen
73
return
84
end
5+
vim.g.did_load_filetypes=1
96

107
vim.api.nvim_create_augroup('filetypedetect', {clear=false })
118

@@ -38,21 +35,16 @@ if not vim.g.did_load_ftdetect then
3835
]])
3936
end
4037

41-
-- Set a marker so that the ftdetect scripts are not sourced a second time by filetype.vim
42-
vim.g.did_load_ftdetect=1
43-
44-
-- If filetype.vim is disabled, set up the autocmd to use scripts.vim
45-
ifvim.g.did_load_filetypesthen
46-
vim.api.nvim_create_autocmd({'BufRead','BufNewFile'}, {
47-
group='filetypedetect',
48-
command="if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
49-
})
38+
-- Set up the autocmd for user scripts.vim
39+
vim.api.nvim_create_autocmd({'BufRead','BufNewFile'}, {
40+
group='filetypedetect',
41+
command="if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
42+
})
5043

51-
vim.api.nvim_create_autocmd('StdinReadPost', {
52-
group='filetypedetect',
53-
command='if !did_filetype() | runtime! scripts.vim | endif',
54-
})
55-
end
44+
vim.api.nvim_create_autocmd('StdinReadPost', {
45+
group='filetypedetect',
46+
command='if !did_filetype() | runtime! scripts.vim | endif',
47+
})
5648

5749
ifnotvim.g.ft_ignore_patthen
5850
vim.g.ft_ignore_pat='\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'

‎runtime/filetype.vim‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
" Maintainer:Bram Moolenaar <Bram@vim.org>
44
" Last Change:2022 Jul 5
55

6+
" Only run this if enabled
7+
if!exists("do_legacy_filetype")
8+
finish
9+
endif
10+
611
" Listen very carefully, I will say this only once
712
ifexists("did_load_filetypes")
813
finish

‎runtime/lua/vim/filetype.lua‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,7 @@ end
22272227
---
22282228
--- See $VIMRUNTIME/lua/vim/filetype.lua for more examples.
22292229
---
2230-
--- Note that Lua filetype detection is only enabled when |g:do_filetype_lua| is
2231-
--- set to 1.
2230+
--- Note that Lua filetype detection is disabled when |g:do_legacy_filetype| is set.
22322231
---
22332232
--- Example:
22342233
--- <pre>

‎runtime/scripts.vim‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@
1111
" 'ignorecase' option making a difference. Where case is to be ignored use
1212
" =~? instead. Do not use =~ anywhere.
1313

14-
" Only do the rest when not using Lua filetype detection
15-
" and the FileType autocommand has not been triggered yet.
16-
ifexists("g:do_filetype_lua")&&g:do_filetype_lua||did_filetype()
14+
" Only run when using legacy filetype
15+
if!exists('g:do_legacy_filetype')
16+
finish
17+
endif
18+
19+
" Only do the rest when the FileType autocommand has not been triggered yet.
20+
ifdid_filetype()
1721
finish
1822
endif
1923

‎src/nvim/testdir/test_filetype_lua.vim‎

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
letg:do_legacy_filetype=1
2+
filetypeon
3+
4+
source test_filetype.vim

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp