runtime(zig): refactor zig ftplugin, remove auto format

Refactored zig ftplugin, removed upstream comment, aucmd and
auto formatting support. Updated documentation for zig configuration
settings and added new maintainer.

closes: #13803

Signed-off-by: Tiseno <mathias.lindgren@stabelo.se>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Tiseno
2024-05-21 23:27:03 +02:00
committed by Christian Brabandt
parent b335a9312c
commit d1d9316c66
4 changed files with 50 additions and 138 deletions

View File

@ -1,68 +1,52 @@
" Vim filetype plugin file
" Language: Zig
" Upstream: https://github.com/ziglang/zig.vim
" Language: Zig
" Maintainer: Mathias Lindgren <math.lindgren@gmail.com>
" Last Change: 2024 May 21
" Based on: https://github.com/ziglang/zig.vim
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
let s:cpo_orig = &cpo
let s:cpo_save = &cpo
set cpo&vim
compiler zig_build
" Match Zig builtin fns
setlocal iskeyword+=@-@
" Recommended code style, no tabs and 4-space indentation
setlocal expandtab
setlocal tabstop=8
setlocal softtabstop=4
setlocal shiftwidth=4
setlocal formatoptions-=t formatoptions+=croql
setlocal suffixesadd=.zig,.zir,.zon
let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
let b:undo_ftplugin = 'setl isk< fo< sua< mp< def<'
setlocal suffixesadd=.zig,.zir
if get(g:, 'zig_recommended_style', 1)
setlocal expandtab
setlocal tabstop=8
setlocal softtabstop=4
setlocal shiftwidth=4
let b:undo_ftplugin .= ' | setl et< ts< sts< sw<'
endif
if has('comments')
setlocal comments=:///,://!,://
setlocal commentstring=//\ %s
let b:undo_ftplugin .= ' | setl com< cms<'
endif
if has('find_in_path')
let &l:includeexpr='substitute(v:fname, "^([^.])$", "\1.zig", "")'
let &l:include='\v(\@import>|\@cInclude>|^\s*\#\s*include)'
endif
let &l:define='\v(<fn>|<const>|<var>|^\s*\#\s*define)'
" Safety check: don't execute zig from current directory
if !exists('g:zig_std_dir') && exists('*json_decode') &&
\ executable('zig') && dist#vim#IsSafeExecutable('zig', 'zig')
silent let s:env = system('zig env')
if v:shell_error == 0
let g:zig_std_dir = json_decode(s:env)['std_dir']
endif
unlet! s:env
let b:undo_ftplugin .= ' | setl inex< inc<'
endif
if exists('g:zig_std_dir')
let &l:path = g:zig_std_dir . ',' . &l:path
let &l:path .= ',' . g:zig_std_dir
let b:undo_ftplugin .= ' | setl pa<'
endif
let b:undo_ftplugin =
\ 'setl isk< et< ts< sts< sw< fo< sua< mp< com< cms< inex< inc< pa<'
augroup vim-zig
autocmd! * <buffer>
autocmd BufWritePre <buffer> if get(g:, 'zig_fmt_autosave', 1) | call zig#fmt#Format() | endif
augroup END
let b:undo_ftplugin .= '|au! vim-zig * <buffer>'
let &cpo = s:cpo_orig
unlet s:cpo_orig
let &cpo = s:cpo_save
unlet s:cpo_save
" vim: tabstop=8 shiftwidth=4 softtabstop=4 expandtab