Skip to content

Commit

Permalink
Use lua for filename-based justfile detection in Neovim >= 0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
laniakea64 committed May 30, 2024
1 parent b46dabb commit 7b86ee0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
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.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
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.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
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

0 comments on commit 7b86ee0

Please sign in to comment.