Skip to content

Instantly share code, notes, and snippets.

@dahu
Created August 2, 2012 02:11
Show Gist options
  • Select an option

  • Save dahu/3232488 to your computer and use it in GitHub Desktop.

Select an option

Save dahu/3232488 to your computer and use it in GitHub Desktop.
Chroma mkII - proof of concept for a full-blown plugin
" proof of concept - Chroma: Vim colour printer using *markup*
" Barry Arthur, 2012 08 02
let s:ChromaTags = ['!' , '\\*' , '+' , '/' , '_']
let s:ChromaTagNames = ['Bang' , 'Star' , 'Plus' , 'Slash' , 'UScore']
let s:ChromaHighlights = ['Error' , 'WarningMsg' , 'Type' , 'Keyword' , 'Label']
let s:ChromaTagPattern = '%\([^%]\+\)%'
let s:ChromaEchoPattern = '"|echohl % |echon "\1"|echohl None|echon "'
let s:Chroma = {}
let s:idx = 0
for n in s:ChromaTagNames
let t = s:ChromaTags[s:idx]
let s:Chroma[n] = {
\ 'm' : substitute(s:ChromaTagPattern, '%', t, 'g'),
\ 'r' : substitute(s:ChromaEchoPattern, '%', s:ChromaHighlights[s:idx], '')
\}
let s:idx += 1
endfor
function! Chroma(msg)
let msg = a:msg
for n in s:ChromaTagNames
let msg = substitute(msg, s:Chroma[n]['m'], s:Chroma[n]['r'], 'g')
endfor
exe 'echon "' . msg . '"|echon "\n"'
endfunction
command! -nargs=* Chroma call Chroma(<q-args>)
" examples
Chroma !Error!: You can't /frobnogate/ the +discombobulator+!
call Chroma("a !bang! a *star* a +plus+ a /slash/ a _uscore_ a normal")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment