Skip to content

Commit 8634bd4

Browse files
clasonpbnj
andcommitted
vim-patch:9.1.1042: filetype: just files are not recognized
Problem: filetype: just files are not recognized Solution: adjust filetype detection pattern, detect just shebang line, include just ftplugin, indent and syntax plugin (Peter Benjamin) closes: vim/vim#16466 vim/vim@72755b3 Co-authored-by: Peter Benjamin <[email protected]>
1 parent 28998e1 commit 8634bd4

File tree

6 files changed

+481
-0
lines changed

6 files changed

+481
-0
lines changed

runtime/ftplugin/just.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
" Vim ftplugin file
2+
" Language: Justfile
3+
" Maintainer: Peter Benjamin <@pbnj>
4+
" Last Change: 2025 Jan 19
5+
" Credits: The original author, Noah Bogart <https://github.com/NoahTheDuke/vim-just/>
6+
7+
" Only do this when not done yet for this buffer
8+
if exists("b:did_ftplugin")
9+
finish
10+
endif
11+
let b:did_ftplugin = 1
12+
13+
setlocal iskeyword+=-
14+
setlocal comments=n:#
15+
setlocal commentstring=#\ %s
16+
17+
let b:undo_ftplugin = "setlocal iskeyword< comments< commentstring<"

runtime/indent/just.vim

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
" Vim indent file
2+
" Language: Justfile
3+
" Maintainer: Peter Benjamin <@pbnj>
4+
" Last Change: 2025 Jan 19
5+
" Credits: The original author, Noah Bogart <https://github.com/NoahTheDuke/vim-just/>
6+
7+
" Only load this indent file when no other was loaded yet.
8+
if exists("b:did_indent")
9+
finish
10+
endif
11+
let b:did_indent = 1
12+
13+
setlocal indentexpr=GetJustfileIndent()
14+
setlocal indentkeys=0},0),!^F,o,O,0=''',0=\"\"\"
15+
16+
let b:undo_indent = "setlocal indentexpr< indentkeys<"
17+
18+
if exists("*GetJustfileIndent")
19+
finish
20+
endif
21+
22+
function GetJustfileIndent()
23+
if v:lnum < 2
24+
return 0
25+
endif
26+
27+
let prev_line = getline(v:lnum - 1)
28+
let last_indent = indent(v:lnum - 1)
29+
30+
if getline(v:lnum) =~ "\\v^\\s+%([})]|'''$|\"\"\"$)"
31+
return last_indent - shiftwidth()
32+
elseif prev_line =~ '\V#'
33+
return last_indent
34+
elseif prev_line =~ "\\v%([:{(]|^.*\\S.*%([^']'''|[^\"]\"\"\"))\\s*$"
35+
return last_indent + shiftwidth()
36+
elseif prev_line =~ '\\$'
37+
if v:lnum == 2 || getline(v:lnum - 2) !~ '\\$'
38+
if prev_line =~ '\v:\=@!'
39+
return last_indent + shiftwidth() + shiftwidth()
40+
else
41+
return last_indent + shiftwidth()
42+
endif
43+
endif
44+
elseif v:lnum > 2 && getline(v:lnum - 2) =~ '\\$'
45+
return last_indent - shiftwidth()
46+
elseif prev_line =~ '\v:\s*%(\h|\()' && prev_line !~ '\V:='
47+
return last_indent + shiftwidth()
48+
endif
49+
50+
return last_indent
51+
endfunction

runtime/lua/vim/filetype.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,8 @@ local extension = {
661661
jsp = 'jsp',
662662
jl = 'julia',
663663
just = 'just',
664+
Just = 'just',
665+
JUST = 'just',
664666
kl = 'karel',
665667
KL = 'karel',
666668
kdl = 'kdl',
@@ -1650,8 +1652,11 @@ local filename = {
16501652
['.vsconfig'] = 'jsonc',
16511653
['bun.lock'] = 'jsonc',
16521654
['.justfile'] = 'just',
1655+
['.Justfile'] = 'just',
1656+
['.JUSTFILE'] = 'just',
16531657
['justfile'] = 'just',
16541658
['Justfile'] = 'just',
1659+
['JUSTFILE'] = 'just',
16551660
Kconfig = 'kconfig',
16561661
['Kconfig.debug'] = 'kconfig',
16571662
['Config.in'] = 'kconfig',

runtime/lua/vim/filetype/detect.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,7 @@ local patterns_hashbang = {
18771877
ruby = 'ruby',
18781878
['node\\(js\\)\\=\\>\\|js\\>'] = { 'javascript', { vim_regex = true } },
18791879
['rhino\\>'] = { 'javascript', { vim_regex = true } },
1880+
just = 'just',
18801881
-- BC calculator
18811882
['^bc\\>'] = { 'bc', { vim_regex = true } },
18821883
['sed\\>'] = { 'sed', { vim_regex = true } },

0 commit comments

Comments
 (0)