diff --git a/plugin/rtf_highlight.vim b/plugin/rtf_highlight.vim index 0470665..253f479 100644 --- a/plugin/rtf_highlight.vim +++ b/plugin/rtf_highlight.vim @@ -23,22 +23,48 @@ if !exists('g:rtfh_size') let g:rtfh_size = '24' end +if !exists('g:rtfh_clipboard') + let g:rtfh_clipboard = 'pbcopy' +endif + +let s:alias_dict = { + \ 'javascript' : 'js', + \} + " the awesomeness function! RTFHighlight(line1,line2,...) if !executable('highlight') echoerr "Bummer! highlight not found." return endif - + + " default to use the filetype as the syntax + let filetype_aliased = &filetype + + if exists("a:1") + " if the user explicitly set a syntax with the argument, use that. + let filetype_aliased = a:1 + elseif has_key(s:alias_dict, &filetype) + " if there's a known alias for the filetype, use that. + let filetype_aliased = s:alias_dict[&filetype] + endif + + let command = "highlight --syntax=" . filetype_aliased + \. " -s " . g:rtfh_theme + \. " -k " . g:rtfh_font + \. " -K " . g:rtfh_size + \. " -O rtf " + \. "| " . g:rtfh_clipboard + let content = join(getline(a:line1,a:line2),"\n") - let command = "highlight --syntax " . a:1 . " -s " . g:rtfh_theme . " -R -k " . g:rtfh_font . " -K " . g:rtfh_size . " 2> /dev/null" + let output = system(command,content) " let @* = output " for some reason text copied this way " gets pasted as escaped plain text in keynote " but this works well with pbcopy - let retval = system("pbcopy",output) + " let retval = system("pbcopy",output) endfunction " map it to a command -command! -nargs=1 -range=% RTFHighlight :call RTFHighlight(,,) +command! -nargs=? -range=% RTFHighlight :call RTFHighlight(,,)