Skip to content

try to use filetype as syntax style, misc refactoring #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions plugin/rtf_highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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(<line1>,<line2>,<f-args>)
command! -nargs=? -range=% RTFHighlight :call RTFHighlight(<line1>,<line2>,<f-args>)