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

feat(runtime)!: enable filetype.lua by default#19216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
clason merged 1 commit intoneovim:masterfromclason:toggle-filetype-lua
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat(runtime)!: enable filetype.lua by default
* 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.)
  • Loading branch information
@clason
clason committedJul 6, 2022
commit63496441cc5d2bc5830e2e16a1d24ac18718aca4
47 changes: 14 additions & 33 deletionsruntime/doc/filetype.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,7 +177,9 @@ This means that the contents of compressed files are not inspected.
If a file type that you want to use is not detected yet, there are a few ways
to add it. In any way, it's better not to modify the $VIMRUNTIME/filetype.lua
or $VIMRUNTIME/filetype.vim files. They will be overwritten when installing a
new version of Nvim.
new version of Nvim. The following explains the legacy Vim mechanism (enabled
if |do_legacy_filetype| is set). For Nvim's default mechanism, see
|vim.filetype.add()|.

A. If you want to overrule all default file type checks.
This works by writing one file for each filetype. The disadvantage is that
Expand DownExpand Up@@ -236,39 +238,8 @@ C. If your file type can be detected by the file name or extension.
Write this file as "filetype.vim" in your user runtime directory. For
example, for Unix: >
:w ~/.config/nvim/filetype.vim
<
Alternatively, create a file called "filetype.lua" that adds new
filetypes.
Example: >
vim.filetype.add({
extension = {
foo = "fooscript",
},
filename = {
[".foorc"] = "foorc",
},
pattern = {
[".*/etc/foo/.*%.conf"] = "foorc",
},
})
<
See |vim.filetype.add()|.
*g:do_filetype_lua*
For now, Lua filetype detection is opt-in. You can enable it by adding
the following to your |init.vim|: >
let g:do_filetype_lua = 1
< *g:did_load_filetypes*
In either case, the builtin filetype detection provided by Nvim can be
disabled by setting the did_load_filetypes global variable. If this
variable exists, $VIMRUNTIME/filetype.vim will not run.
Example: >
" Disable filetype.vim (but still load filetype.lua if enabled)
let g:did_load_filetypes = 0

" Disable filetype.vim and filetype.lua
let g:did_load_filetypes = 1

< 3. To use the new filetype detection you must restart Vim.
< 3. To use the new filetype detection you must restart Vim.

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

*g:do_legacy_filetype*
To disable Nvim's default filetype detection and revert to Vim's legacy
filetype detection, add the following to your |init.vim|: >
let g:do_legacy_filetype = 1
< *g:did_load_filetypes*
The builtin filetype detection provided by Nvim can be disabled by setting
the `did_load_filetypes` global variable. If this variable exists, neither
the default `$VIMRUNTIME/filetype.lua` nor the legacy `$VIMRUNTIME/filetype.vim`
will run.

*plugin-details*
The "plugin" directory can be in any of the directories in the 'runtimepath'
option. All of these directories will be searched for plugins and they are
Expand Down
4 changes: 2 additions & 2 deletionsruntime/doc/lua.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2022,8 +2022,8 @@ add({filetypes}) *vim.filetype.add()*

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

Note that Lua filetype detection isonly enabled when
|g:do_filetype_lua| is set to 1.
Note that Lua filetype detection isdisabled when
|g:do_legacy_filetype| is set.

Example: >

Expand Down
32 changes: 12 additions & 20 deletionsruntime/filetype.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
if vim.g.did_load_filetypes and vim.g.did_load_filetypes ~= 0 then
return
end

-- For now, make this opt-in with a global variable
if vim.g.do_filetype_lua ~= 1 then
-- Skip if legacy filetype is enabled or filetype detection is disabled
if vim.g.do_legacy_filetype or vim.g.did_load_filetypes then
return
end
vim.g.did_load_filetypes = 1

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

Expand DownExpand Up@@ -38,21 +35,16 @@ if not vim.g.did_load_ftdetect then
]])
end

-- Set a marker so that the ftdetect scripts are not sourced a second time by filetype.vim
vim.g.did_load_ftdetect = 1

-- If filetype.vim is disabled, set up the autocmd to use scripts.vim
if vim.g.did_load_filetypes then
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
group = 'filetypedetect',
command = "if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
})
-- Set up the autocmd for user scripts.vim
vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
group = 'filetypedetect',
command = "if !did_filetype() && expand('<amatch>') !~ g:ft_ignore_pat | runtime! scripts.vim | endif",
})

vim.api.nvim_create_autocmd('StdinReadPost', {
group = 'filetypedetect',
command = 'if !did_filetype() | runtime! scripts.vim | endif',
})
end
vim.api.nvim_create_autocmd('StdinReadPost', {
group = 'filetypedetect',
command = 'if !did_filetype() | runtime! scripts.vim | endif',
})

if not vim.g.ft_ignore_pat then
vim.g.ft_ignore_pat = '\\.\\(Z\\|gz\\|bz2\\|zip\\|tgz\\)$'
Expand Down
5 changes: 5 additions & 0 deletionsruntime/filetype.vim
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,11 @@
" Maintainer:Bram Moolenaar <Bram@vim.org>
" Last Change:2022 Jun 03

" Only run this if enabled
if !exists("do_legacy_filetype")
finish
endif

" Listen very carefully, I will say this only once
if exists("did_load_filetypes")
finish
Expand Down
3 changes: 1 addition & 2 deletionsruntime/lua/vim/filetype.lua
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2223,8 +2223,7 @@ end
---
--- See $VIMRUNTIME/lua/vim/filetype.lua for more examples.
---
--- Note that Lua filetype detection is only enabled when |g:do_filetype_lua| is
--- set to 1.
--- Note that Lua filetype detection is disabled when |g:do_legacy_filetype| is set.
---
--- Example:
--- <pre>
Expand Down
10 changes: 7 additions & 3 deletionsruntime/scripts.vim
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,9 +11,13 @@
" 'ignorecase' option making a difference. Where case is to be ignored use
" =~? instead. Do not use =~ anywhere.

" Only do the rest when not using Lua filetype detection
" and the FileType autocommand has not been triggered yet.
if exists("g:do_filetype_lua") && g:do_filetype_lua || did_filetype()
" Only run when using legacy filetype
if !exists('g:do_legacy_filetype')
finish
endif

" Only do the rest when the FileType autocommand has not been triggered yet.
if did_filetype()
finish
endif

Expand Down
3 changes: 0 additions & 3 deletionssrc/nvim/testdir/test_filetype_lua.vim
View file
Open in desktop

This file was deleted.

4 changes: 4 additions & 0 deletionssrc/nvim/testdir/test_legacy_filetype.vim
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
let g:do_legacy_filetype = 1
filetype on

source test_filetype.vim

[8]ページ先頭

©2009-2025 Movatter.jp