diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-09 13:16:35 +0000 |
commit | e2bbf175a2184bd76f6c54ccf8456babeb1a46fc (patch) | |
tree | f0b76550d6e6f500ada964a3a4ee933a45e5a6f1 /tools/frr.vim | |
parent | Initial commit. (diff) | |
download | frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.tar.xz frr-e2bbf175a2184bd76f6c54ccf8456babeb1a46fc.zip |
Adding upstream version 9.1.upstream/9.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tools/frr.vim')
-rw-r--r-- | tools/frr.vim | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tools/frr.vim b/tools/frr.vim new file mode 100644 index 0000000..19ac3fc --- /dev/null +++ b/tools/frr.vim @@ -0,0 +1,78 @@ +" SPDX-License-Identifier: NONE +" settings & syntax hilighting for FRR codebase +" 2019 by David Lamparter, placed in public domain + +let c_gnu=1 + +function! CStyleFRR() + syn clear cFormat + syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbiuoxXDOUfFeEgGcCsSn]\|[pd]\([A-Z][A-Z0-9]*[a-z]*\|\)\|\[\^\=.[^]]*\]\)" contained + syn match cFormat display "%%" contained + + syn keyword cIterator frr_each frr_each_safe frr_each_from + syn keyword cMacroOp offsetof container_of container_of_null array_size + + syn keyword cStorageClass atomic + syn keyword cFormatConst PRId64 PRIu64 PRIx64 + syn keyword cFormatConst PRId32 PRIu32 PRIx32 + syn keyword cFormatConst PRId16 PRIu16 PRIx16 + syn keyword cFormatConst PRId8 PRIu8 PRIx8 + + " you can unlink these by just giving them their own hilighting / color + hi link cFormatConst cFormat + hi link cIterator cRepeat + hi link cMacroOp cOperator + + " indentation + setlocal cindent + setlocal cinoptions=:0,(0,u4,w1,W8 + setlocal shiftwidth=8 + setlocal softtabstop=0 + setlocal textwidth=0 + setlocal fo=croql + setlocal noet +endfunction + +" auto-apply the above based on path rules +"autocmd BufRead,BufNewFile /home/.../frr/*.[ch] call CStyleFRR() + +" only load xref file once, remember on script-scope +let s:xrefjson = "" +let s:xrefpath = "" + +" call directly to force reload with :call FRRLoadXrefJson() +function! FRRLoadXrefJson() abort + let s:xrefpath = findfile("frr.xref", ".;") + if empty(s:xrefpath) + throw "frr.xref JSON file not found in current or parent directories" + endif + let xreflines = readfile(s:xrefpath) + let s:xrefjson = json_decode(join(xreflines, "\n")) +endfunction + +function! FRRXrefJson() abort + if empty(s:xrefjson) + call FRRLoadXrefJson() + endif + return s:xrefjson +endfunction + +function! FRRGotoXref(ident) abort + let refs = FRRXrefJson()["refs"] + if has_key(refs, a:ident) + " TODO: in rare cases, one ID may occur in multiple places. + " Add some UI for that. (This happens if the exact same + " format string is logged in multiple places in the same + " file.) + let loc = refs[a:ident][0] + let basepath = fnamemodify(s:xrefpath, ":p:h") + let path = fnamemodify(basepath . "/" . loc["file"], ":.") + execute "e ".fnameescape(path) + execute ":".loc["line"] + else + echoerr printf("cannot find xref with ID %s", a:ident) + endif +endfunction + +" invoke as :GotoXref 23456-ABCDE +command! -bang -nargs=1 GotoXref :call FRRGotoXref(<q-args>) |