diff --git a/home/editors/neovim/default.nix b/home/editors/neovim/default.nix index 3b6ced0..d0e400a 100644 --- a/home/editors/neovim/default.nix +++ b/home/editors/neovim/default.nix @@ -83,6 +83,5 @@ in { withPython3 = false; }; - xdg.configFile."nvim/filetype.vim".source = ./filetype.vim; - xdg.configFile."nvim/scripts.vim".source = ./scripts.vim; + xdg.configFile."nvim/filetype.lua".source = ./filetype.lua; } diff --git a/home/editors/neovim/filetype.lua b/home/editors/neovim/filetype.lua new file mode 100644 index 0000000..c6134e6 --- /dev/null +++ b/home/editors/neovim/filetype.lua @@ -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 + }, +}) diff --git a/home/editors/neovim/filetype.vim b/home/editors/neovim/filetype.vim deleted file mode 100644 index 2a590d6..0000000 --- a/home/editors/neovim/filetype.vim +++ /dev/null @@ -1,2 +0,0 @@ -au BufRead,BufNewFile *.nix set filetype=nix - diff --git a/home/editors/neovim/init.lua b/home/editors/neovim/init.lua index 39cd129..3509f3d 100644 --- a/home/editors/neovim/init.lua +++ b/home/editors/neovim/init.lua @@ -19,6 +19,10 @@ vim.g.camelcasemotion_key = "" vim.opt.relativenumber = 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.cmd("syntax on") vim.cmd("colorscheme nvcode") diff --git a/home/editors/neovim/scripts.vim b/home/editors/neovim/scripts.vim deleted file mode 100644 index 49f2dc0..0000000 --- a/home/editors/neovim/scripts.vim +++ /dev/null @@ -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