feat(neovim): switch to filetype.lua

Replaces old filetype.vim & scripts.vim.
This commit is contained in:
Felix Schröter 2022-05-01 18:12:08 +02:00
parent 87a72b2ecf
commit c95fe27950
Signed by: felschr
GPG key ID: 671E39E6744C807D
5 changed files with 59 additions and 29 deletions

View file

@ -83,6 +83,5 @@ in {
withPython3 = false; withPython3 = false;
}; };
xdg.configFile."nvim/filetype.vim".source = ./filetype.vim; xdg.configFile."nvim/filetype.lua".source = ./filetype.lua;
xdg.configFile."nvim/scripts.vim".source = ./scripts.vim;
} }

View file

@ -0,0 +1,54 @@
-- opt-in to filetype.lua
vim.g.do_filetype_lua = 1
vim.g.did_load_filetypes = 0
vim.filetype.add({
extension = {
vert = "glsl",
tesc = "glsl",
tese = "glsl",
glsl = "glsl",
geom = "glsl",
frag = "glsl",
comp = "glsl",
rgen = "glsl",
rmiss = "glsl",
rchit = "glsl",
rahit = "glsl",
rint = "glsl",
rcall = "glsl",
},
pattern = {
[".env.*"] = "direnv",
[".*"] = function(path, bufnr)
local first_line = vim.api.nvim_buf_get_lines(bufnr, 0, 1, true)[1]
if first_line:match("^#!.*nix%-shell") ~= nil then
local second_line = vim.api.nvim_buf_get_lines(bufnr, 1, 2, true)[1]
local command = second_line:match("^#!.*nix%-shell .*%-i ([%a%d]*)")
if command == nil then
return nil
elseif command == "sh" or command == "bash" then
return "bash"
elseif command == "ksh" then
return "ksh"
elseif command == "zsh" then
return "zsh"
elseif command == "make" then
return "make"
elseif command == "python" then
return "python"
elseif command == "node" then
return "javascript"
elseif command == "runhaskell" then
return "haskell"
elseif command == "ghci" then
return "haskell"
end
return nil
end
return nil
end
},
})

View file

@ -1,2 +0,0 @@
au BufRead,BufNewFile *.nix set filetype=nix

View file

@ -19,6 +19,10 @@ vim.g.camelcasemotion_key = "<leader>"
vim.opt.relativenumber = true vim.opt.relativenumber = true
vim.opt.splitbelow = true vim.opt.splitbelow = true
-- opt-in to filetype.lua
vim.g.do_filetype_lua = 1
vim.g.did_load_filetypes = 0
vim.g.nvcode_termcolors = 256 vim.g.nvcode_termcolors = 256
vim.cmd("syntax on") vim.cmd("syntax on")
vim.cmd("colorscheme nvcode") vim.cmd("colorscheme nvcode")

View file

@ -1,25 +0,0 @@
if did_filetype()
finish
endif
if getline(1) =~ '^#!.*nix-shell'
let s:matches = matchlist(getline(2), '^#!.*nix-shell .*-i \([^ \t\n]\+\)')
let s:command = s:matches[1]
echo s:command
if s:command != ''
if s:command =~# '^\(bash\d*\|\|ksh\d*\|sh\)\>'
call dist#ft#SetFileTypeSH(s:command)
elseif s:command == 'zsh'
set ft=zsh
elseif s:command =~ 'make\>'
set ft=make
elseif s:command =~ '^node\(js\)\=\>\|^js\>'
set ft=javascript
elseif s:command =~ '^runhaskell'
set ft=haskell
elseif s:command =~ '^ghci'
set ft=haskell
elseif s:command =~ 'python'
set ft=python
endif
endif
endif