check for gawk and cleanup comments
This commit is contained in:
parent
9eb422ba89
commit
23f344fb75
@ -1,3 +1,3 @@
|
|||||||
|
|
||||||
au BufNewFile,BufRead */logrotate.d/*,logrotate.conf setfiletype logrotate
|
autocmd BufNewFile,BufRead */logrotate.d/*,logrotate.conf setfiletype logrotate
|
||||||
|
|
||||||
|
@ -7,26 +7,36 @@ if exists("b:did_ftplugin")
|
|||||||
endif
|
endif
|
||||||
b:did_ftplugin = 1
|
b:did_ftplugin = 1
|
||||||
|
|
||||||
def LogrotateHelp(word: string)
|
b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< omnifunc<"
|
||||||
const searchcmd =<< trim END
|
|
||||||
COLUMNS=80 man logrotate 2>/dev/null |
|
|
||||||
gawk '/^CONFIGURATION FILE DIRECTIVES/,/^SCRIPTS/' | gawk '
|
|
||||||
/^ {7}%s/,/^[a-z]/ {
|
|
||||||
if(firstLineDone) {
|
|
||||||
if(/^ {0,7}[^ ]/ && !/endscript/)
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
firstLineDone = 1
|
|
||||||
print(substr($0, 8))
|
|
||||||
}'
|
|
||||||
END
|
|
||||||
printf(join(searchcmd, "\n"), word)
|
|
||||||
->systemlist()
|
|
||||||
->popup_atcursor({ "padding": [0, 1, 1, 1] })
|
|
||||||
enddef
|
|
||||||
|
|
||||||
command -nargs=1 LogRt :call LogrotateHelp(<f-args>)
|
var awkcmd: string
|
||||||
|
|
||||||
b:undo_ftplugin = "setlocal comments< commentstring< formatoptions< keywordprg<"
|
if exists("g:logrotate_awk")
|
||||||
|
awkcmd = g:logrotate_awk
|
||||||
|
else
|
||||||
|
awkcmd = "gawk"
|
||||||
|
endif
|
||||||
|
# Have to use gawk, default awk (mawk) does not support {0,7} syntax
|
||||||
|
if executable(awkcmd)
|
||||||
|
def LogrotateHelp(word: string)
|
||||||
|
const searchcmd =<< trim eval END
|
||||||
|
COLUMNS=80 man logrotate 2>/dev/null |
|
||||||
|
{awkcmd} '/^CONFIGURATION FILE DIRECTIVES/,/^SCRIPTS/' | {awkcmd} '
|
||||||
|
/^ {{7}}%s/,false {{
|
||||||
|
if(firstLineDone && /^ {{0,7}}[^ ]/ && !/endscript/) exit
|
||||||
|
firstLineDone = 1
|
||||||
|
print(substr($0, 8))
|
||||||
|
}}'
|
||||||
|
END
|
||||||
|
printf(join(searchcmd, "\n"), word)
|
||||||
|
->systemlist()
|
||||||
|
->popup_atcursor({ "padding": [0, 1, 1, 1] })
|
||||||
|
enddef
|
||||||
|
|
||||||
setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql keywordprg=:LogRt
|
command -nargs=1 LogRotateHelpCmd :call LogrotateHelp(<f-args>)
|
||||||
|
setlocal keywordprg=:LogRotateHelpCmd
|
||||||
|
b:undo_ftplugin = b:undo_ftplugin .. " keywordprg<"
|
||||||
|
endif
|
||||||
|
|
||||||
|
setlocal omnifunc=syntaxcomplete#Complete
|
||||||
|
setlocal comments=:# commentstring=#\ %s formatoptions-=t formatoptions+=croql
|
||||||
|
@ -1,21 +1,19 @@
|
|||||||
" Vim syntax file
|
" Vim syntax file
|
||||||
" Language: logrotate
|
" Language: logrotate
|
||||||
|
|
||||||
" Quit if a syntax file was already loaded
|
|
||||||
if exists("b:current_syntax")
|
if exists("b:current_syntax")
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
|
|
||||||
syn include @logRotateSh syntax/sh.vim
|
syntax include @logRotateSh syntax/sh.vim
|
||||||
unlet b:current_syntax
|
unlet b:current_syntax
|
||||||
|
|
||||||
syn region logRotateScript matchgroup=logRotateKeyword start="\s*\<\%(firstaction\|lastaction\|prerotate\|postrotate\|preremove\)\>" end="\<endscript\>" contains=@logRotateSh
|
syntax region logRotateScript matchgroup=logRotateKeyword start="\s*\<\%(firstaction\|lastaction\|prerotate\|postrotate\|preremove\)\>" end="\<endscript\>" contains=@logRotateSh
|
||||||
|
|
||||||
|
" for comments, todo, string
|
||||||
runtime! syntax/conf.vim
|
runtime! syntax/conf.vim
|
||||||
|
|
||||||
" syn keyword logRotateTodo contained TODO FIXME XXX
|
syntax keyword logRotateKeyword addextension allowhardlink compress compresscmd
|
||||||
|
|
||||||
syn keyword logRotateKeyword addextension allowhardlink compress compresscmd
|
|
||||||
\ compressext compressoptions copy copytruncate create createolddir
|
\ compressext compressoptions copy copytruncate create createolddir
|
||||||
\ daily dateext dateformat datehourago dateyesterday delaycompress
|
\ daily dateext dateformat datehourago dateyesterday delaycompress
|
||||||
\ endscript extension firstaction hourly ifempty include lastaction
|
\ endscript extension firstaction hourly ifempty include lastaction
|
||||||
@ -27,18 +25,6 @@ syn keyword logRotateKeyword addextension allowhardlink compress compresscmd
|
|||||||
\ shred shredcycles size start su tabooext taboopat uncompresscmd
|
\ shred shredcycles size start su tabooext taboopat uncompresscmd
|
||||||
\ weekly yearly
|
\ weekly yearly
|
||||||
|
|
||||||
" String
|
highlight default link logRotateKeyword Keyword
|
||||||
" syn region logRotateString start=+"+ skip=+\\\\\|\\"+ end=+"+ oneline
|
|
||||||
" syn region logRotateString start=+'+ skip=+\\\\\|\\'+ end=+'+ oneline
|
|
||||||
|
|
||||||
" syn match logRotateComment "^#.*" contains=logRotateTodo,logRotateString,@Spell
|
|
||||||
" syn match logRotateComment "\s#.*"ms=s+1 contains=logRotateTodo,logRotateString,@Spell
|
|
||||||
|
|
||||||
hi def link logRotateKeyword Keyword
|
|
||||||
" hi def link logRotateString String
|
|
||||||
" hi def link logRotateComment Comment
|
|
||||||
" hi def link logRotateTodo Todo
|
|
||||||
|
|
||||||
" hi def link logRotateScript Function
|
|
||||||
|
|
||||||
let b:current_syntax = 'logrotate'
|
let b:current_syntax = 'logrotate'
|
||||||
|
Loading…
Reference in New Issue
Block a user