Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix justfile filetype detection in Neovim >= 0.10 #91

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions ftdetect/just.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Vim filetype plugin
-- Language: Justfile
-- Maintainer: Noah Bogart <[email protected]>
-- URL: https://github.com/NoahTheDuke/vim-just.git
-- Last Change: 2024 May 29

if vim.fn.has("nvim-0.8") 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
6 changes: 5 additions & 1 deletion ftdetect/just.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
" Maintainer: Noah Bogart <[email protected]>
" 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.8")
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
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ' + \
Expand Down