Initial vim syntax for just

including:
- operators
- quotes/strings
- raw quotes/strings
- backtick sub-shells
- curly substitutions
- "set shell" handling
This commit is contained in:
Dan Buch 2021-05-23 20:18:17 -04:00
parent 7275f13738
commit 6600e7b295
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7
3 changed files with 174 additions and 0 deletions

55
vim-just/example/justfile Normal file
View File

@ -0,0 +1,55 @@
#!/usr/bin/env oh-no
# vim:filetype=just
set shell := ["python", "-c"]
set something
alias d := dogs
export HOTDOGPARTY := hats
now_ish := `print("oh gee")` + `print(sum([1, 2, 5]))`
an_string := "sit ready \"for reals\" 'uh huh' {{an_raw_string + '{{what' }}"
an_raw_string := 'sit ready "wow" {{not_gonna}}'
hats := '''
very serious hat's
'''
wats := """
{{an_string}} \"yay\" 'ok'
{{ 'dog' + just_executable()}}
{{justfile()}}
{{justfile_directory()}}
{{arch()}} {{os()}}
"""
serious_business := ```
from __future__ import print_function
import os
import datetime
print(f"home: {os.environ.get("HOME", "?")}")
print(f"now-ish: {datetime.datetime.now()}")
```
dogs: aminal manimal _secret
# show the aminal by kind
aminal kind='dog':
#!/usr/bin/env python
import sys
import os
print('\n'.join(os.environ.keys()), file=sys.stderr)
_secret +WHATEVER='OK':
@echo "don't tell anyone {{WHATEVER}}"
manimal:
@echo wow

View File

@ -0,0 +1 @@
autocmd BufReadPost justfile,*.justfile setfiletype just

118
vim-just/syntax/just.vim Normal file
View File

@ -0,0 +1,118 @@
" Vim syntax file
" Language: Just Command Runner
" Maintainer: Dan Buch
" Latest Revision: 22 May 2021
if exists("b:current_syntax")
finish
endif
let b:shell_name = "sh"
let b:load_time_cursor = getpos('.')
let b:debug = $JUST_VIM_DEBUG == 'enabled'
function JustGetShellName()
let lineno = 0
while lineno < line("$")
let lineno += 1
let line = getline(lineno)
let set_shell_match = "^ *set *shell *:"
if matchstr(line, set_shell_match) == ""
if b:debug
echom "line number " . lineno . " does not match '" . set_shell_match . "': '" . line . "'"
endif
continue
endif
if b:debug
echom "found matching line number " . lineno . ": " . line
endif
:normal /"<CR>lv/"<CR>hy:nohl
let shell_name = @"
if shell_name != ""
return shell_name
fi
endwhile
return "sh"
endfunc
try
let shell_name = JustGetShellName()
if b:debug
echom "found shell name: '" . shell_name . "'"
endif
exe "syn include @setshellsyntax syntax/" . shell_name . ".vim"
let b:shell_name = shell_name
catch
if b:debug
echom "oh no: " v:exception
echom "just.vim: falling back to sh syntax"
endif
syn include @setshellsyntax syntax/sh.vim
endtry
syn keyword justKeyword alias export if else set
syn keyword justFunction arch os os_family
syn keyword justFunction env_var env_var_or_default invocation_directory
syn keyword justFunction justfile justfile_directory just_executable
syn keyword justSetting shell export dotenv-load positional-arguments
syn match justOperator /\v:/
syn match justOperator /\v\)/
syn match justOperator /\v\(/
syn match justOperator /\v\=/
syn match justOperator /\v:\=/
syn match justQuote /\v"/
syn match justQuote /\v'/
syn match justQuote /\v"""/
syn match justQuote /\v'''/
syn match justBacktick /\v\`/
syn match justBacktick /\v\`\`\`/
syn match justCurlyBrace /\v\{\{/
syn match justCurlyBrace /\v\}\}/
syn region justCurlyBraced matchgroup=justCurlyBrace start=/\v\{\{/ skip=/\v\\\{/ end=/\v\}\}/ contains=justKeyword,justFunction,justOperator,justQuote,justString,justRawString
syn region justString matchgroup=justQuote start=/\v"/ skip=/\v\\"/ end=/\v"/ contains=justCurlyBraced
syn region justString matchgroup=justQuote start=/\v"""/ skip=/\v\\"/ end=/\v"""/ contains=justCurlyBraced
syn region justRawString matchgroup=justQuote start=/\v'/ end=/\v'/
syn region justRawString matchgroup=justQuote start=/\v'''/ end=/\v'''/
syn region justSubshell matchgroup=justBacktick start=/\v\`/ skip=/\v\\\`/ end=/\v\`/ contains=@setshellsyntax
syn region justSubshell matchgroup=justBacktick start=/\v\`\`\`/ skip=/\v\\\`/ end=/\v\`\`\`/ contains=@setshellsyntax
syn match justComment /\v#.*$/
syn match justShebang /\v^ *#!.*$/
hi def link justKeyword Keyword
hi def link justSetting Keyword
hi def link justOperator Operator
hi def link justComment Comment
hi def link justShebang PreProc
hi def link justFunction Function
hi def link justQuote String
hi def link justString String
hi def link justRawString String
hi def link justCurlyBrace Keyword
hi def link justBacktick Special
let b:current_syntax = "just"
" vim:expandtab:ts=2:sts=2