From 7b86ee092369dfe256621b49d520dba4b8fdcdfe Mon Sep 17 00:00:00 2001 From: laniakea64 Date: Wed, 29 May 2024 20:06:36 -0400 Subject: [PATCH 1/2] Use lua for filename-based justfile detection in Neovim >= 0.10 --- ftdetect/just.lua | 25 +++++++++++++++++++++++++ ftdetect/just.vim | 6 +++++- justfile | 2 +- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 ftdetect/just.lua diff --git a/ftdetect/just.lua b/ftdetect/just.lua new file mode 100644 index 0000000..da44ca2 --- /dev/null +++ b/ftdetect/just.lua @@ -0,0 +1,25 @@ +-- Vim filetype plugin +-- Language: Justfile +-- Maintainer: Noah Bogart +-- URL: https://github.com/NoahTheDuke/vim-just.git +-- Last Change: 2024 May 29 + +if vim.fn.has("nvim-0.10") then + vim.filetype.add({ + extension = { + -- Disable extension-based detection of *.just justfiles. + -- The extensions table is also matched against the program in shebang lines, + -- which in case of just scripts is too broad. + just = function() + return nil + end, + }, + + -- Neovim adds start/end anchors to the patterns + pattern = { + ['[Jj][Uu][Ss][Tt][Ff][Ii][Ll][Ee]'] = 'just', + ['.*%.[Jj][Uu][Ss][Tt][Ff][Ii][Ll][Ee]'] = 'just', + ['.*%.[Jj][Uu][Ss][Tt]'] = 'just', + }, + }) +end diff --git a/ftdetect/just.vim b/ftdetect/just.vim index 536d6ee..4a1dec8 100644 --- a/ftdetect/just.vim +++ b/ftdetect/just.vim @@ -3,5 +3,9 @@ " Maintainer: Noah Bogart " URL: https://github.com/NoahTheDuke/vim-just.git " Last Change: 2024 Mar 03 -au BufNewFile,BufRead \c{,*.}justfile,\c*.just setfiletype just + +if !has("nvim-0.10") + au BufNewFile,BufRead \c{,*.}justfile,\c*.just setfiletype just +endif + au BufNewFile,BufRead * if getline(1) =~# '\v^#!/%(\w|[-/])*/%(env%(\s+-S)?\s+)?just\A' | setfiletype just | endif diff --git a/justfile b/justfile index 6a47589..14f4924 100644 --- a/justfile +++ b/justfile @@ -23,7 +23,7 @@ npreview JUSTFILE='': (_preview_common 'nvim' JUSTFILE) _preview_common vimcmd JUSTFILE: {{vimcmd}} \ -c {{quote("let &runtimepath=\"" + justfile_directory() + ",\" . &runtimepath")}} \ - -c {{quote("runtime ftdetect/just.vim")}} \ + -c {{quote('runtime ftdetect/just.vim | if has("nvim") | runtime ftdetect/just.lua | endif')}} \ {{if JUSTFILE == '' { '-c "set filetype=just"' } \ else { \ "-c " + quote('edit ' + \ From ff1b1788b230f8435248836792b2094381a75562 Mon Sep 17 00:00:00 2001 From: laniakea64 Date: Thu, 30 May 2024 11:11:08 -0400 Subject: [PATCH 2/2] ftdetect: use just.lua in Neovim >= 0.8 --- ftdetect/just.lua | 2 +- ftdetect/just.vim | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ftdetect/just.lua b/ftdetect/just.lua index da44ca2..e2591d9 100644 --- a/ftdetect/just.lua +++ b/ftdetect/just.lua @@ -4,7 +4,7 @@ -- URL: https://github.com/NoahTheDuke/vim-just.git -- Last Change: 2024 May 29 -if vim.fn.has("nvim-0.10") then +if vim.fn.has("nvim-0.8") then vim.filetype.add({ extension = { -- Disable extension-based detection of *.just justfiles. diff --git a/ftdetect/just.vim b/ftdetect/just.vim index 4a1dec8..a3f1c7e 100644 --- a/ftdetect/just.vim +++ b/ftdetect/just.vim @@ -4,7 +4,7 @@ " URL: https://github.com/NoahTheDuke/vim-just.git " Last Change: 2024 Mar 03 -if !has("nvim-0.10") +if !has("nvim-0.8") au BufNewFile,BufRead \c{,*.}justfile,\c*.just setfiletype just endif