Skip to content

Instantly share code, notes, and snippets.

@dahu
Last active September 8, 2015 07:33
Show Gist options
  • Save dahu/5de25e3ab5b557297dcf to your computer and use it in GitHub Desktop.
Save dahu/5de25e3ab5b557297dcf to your computer and use it in GitHub Desktop.
Example statusline function collecting annotations from buffer
" Barry Arthur 2015-9-8
" Example statusline function collecting annotations from buffer
" embedded annotations are expected to be enclosed in square brackets
" and all upper-case, as in:
" [DESIGN]
" [IMPLEMENTATION]
" [NAMING]
" [OVERALL]
" [STYLE]
let annotations = {
\ 'good' :
\ [ 'DESIGN'
\ , 'IMPLEMENTATION'
\ ], 'bad' :
\ [ 'NAMING'
\ , 'OVERALL'
\ , 'STYLE'
\ ]}
function! UpdateScores()
let scorelist = []
let scores = {'good' : {}, 'bad' : {}}
for line in getline(1, '$')
for trait in ['good', 'bad']
for annotation in g:annotations[trait]
if line =~# '\[' . annotation . '\]'
let scores[trait][annotation] = (get(scores[trait], annotation, 0) + 1)
endif
endfor
endfor
endfor
for trait in ['good', 'bad']
let total = 0
for annotation in sort(keys(scores[trait]))
call add(scorelist, '[' . annotation[0] . ':' . scores[trait][annotation] . ']')
let total += scores[trait][annotation]
endfor
call add(scorelist, '= ' . total)
call add(scorelist, '--')
endfor
return ' Marks: ' . join(scorelist[:-2])
endfunction
set statusline=%f%m%r%h%w\ [%n:%{&ff}/%Y]\%{UpdateScores()}%=[0x\%04.4B][%03v][%p%%\ line\ %l\ of\ %L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment