]>
Commit | Line | Data |
---|---|---|
47a3a827 | 1 | " SPDX-License-Identifier: NONE |
b9a0d38d DL |
2 | " settings & syntax hilighting for FRR codebase |
3 | " 2019 by David Lamparter, placed in public domain | |
4 | ||
5 | let c_gnu=1 | |
6 | ||
7 | function! CStyleFRR() | |
8 | syn clear cFormat | |
9 | syn match cFormat display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbiuoxXDOUfFeEgGcCsSn]\|[pd]\([A-Z][A-Z0-9]*[a-z]*\|\)\|\[\^\=.[^]]*\]\)" contained | |
10 | syn match cFormat display "%%" contained | |
11 | ||
12 | syn keyword cIterator frr_each frr_each_safe frr_each_from | |
13 | syn keyword cMacroOp offsetof container_of container_of_null array_size | |
14 | ||
15 | syn keyword cStorageClass atomic | |
16 | syn keyword cFormatConst PRId64 PRIu64 PRIx64 | |
17 | syn keyword cFormatConst PRId32 PRIu32 PRIx32 | |
18 | syn keyword cFormatConst PRId16 PRIu16 PRIx16 | |
19 | syn keyword cFormatConst PRId8 PRIu8 PRIx8 | |
20 | ||
21 | " you can unlink these by just giving them their own hilighting / color | |
22 | hi link cFormatConst cFormat | |
23 | hi link cIterator cRepeat | |
24 | hi link cMacroOp cOperator | |
25 | ||
26 | " indentation | |
27 | setlocal cindent | |
28 | setlocal cinoptions=:0,(0,u4,w1,W8 | |
29 | setlocal shiftwidth=8 | |
30 | setlocal softtabstop=0 | |
31 | setlocal textwidth=0 | |
32 | setlocal fo=croql | |
33 | setlocal noet | |
34 | endfunction | |
35 | ||
36 | " auto-apply the above based on path rules | |
37 | "autocmd BufRead,BufNewFile /home/.../frr/*.[ch] call CStyleFRR() | |
40e98aa8 DL |
38 | |
39 | " only load xref file once, remember on script-scope | |
40 | let s:xrefjson = "" | |
41 | let s:xrefpath = "" | |
42 | ||
43 | " call directly to force reload with :call FRRLoadXrefJson() | |
44 | function! FRRLoadXrefJson() abort | |
45 | let s:xrefpath = findfile("frr.xref", ".;") | |
46 | if empty(s:xrefpath) | |
47 | throw "frr.xref JSON file not found in current or parent directories" | |
48 | endif | |
49 | let xreflines = readfile(s:xrefpath) | |
50 | let s:xrefjson = json_decode(join(xreflines, "\n")) | |
51 | endfunction | |
52 | ||
53 | function! FRRXrefJson() abort | |
54 | if empty(s:xrefjson) | |
55 | call FRRLoadXrefJson() | |
56 | endif | |
57 | return s:xrefjson | |
58 | endfunction | |
59 | ||
60 | function! FRRGotoXref(ident) abort | |
61 | let refs = FRRXrefJson()["refs"] | |
62 | if has_key(refs, a:ident) | |
63 | " TODO: in rare cases, one ID may occur in multiple places. | |
64 | " Add some UI for that. (This happens if the exact same | |
65 | " format string is logged in multiple places in the same | |
66 | " file.) | |
67 | let loc = refs[a:ident][0] | |
68 | let basepath = fnamemodify(s:xrefpath, ":p:h") | |
69 | let path = fnamemodify(basepath . "/" . loc["file"], ":.") | |
70 | execute "e ".fnameescape(path) | |
71 | execute ":".loc["line"] | |
72 | else | |
73 | echoerr printf("cannot find xref with ID %s", a:ident) | |
74 | endif | |
75 | endfunction | |
76 | ||
77 | " invoke as :GotoXref 23456-ABCDE | |
78 | command! -bang -nargs=1 GotoXref :call FRRGotoXref(<q-args>) |