-
Notifications
You must be signed in to change notification settings - Fork 16
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
Support OSX, resolve #22 #37
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,13 @@ function! s:InformUserAboutCopiedText(first, last) | |
endif | ||
endfunction | ||
|
||
" wait to remove file | ||
function! s:WaitToRemoveFile(file) | ||
sleep 1000m | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this adds a 1-second delay, which wasn't here before. Is this really necessary? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for me, without a delay, safari will not able to read the file before it has been deleted. (I use vim 8 btw) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding a new plugin variable sounds good. You could also make it a floating point variable -- say, |
||
if maktaba#path#Exists(a:file) | ||
call delete(a:file) | ||
endif | ||
endfunction | ||
|
||
"" | ||
" Export syntax-highlighted content to a new browser tab. | ||
|
@@ -104,7 +111,7 @@ function! syncopate#ExportToBrowser() range | |
execute a:firstline . ',' . a:lastline 'TOhtml' | ||
|
||
" Try to save the HTML to a file and open it in the browser. | ||
let l:html_file = tempname() | ||
let l:html_file = tempname().'.html' | ||
silent execute 'saveas!' l:html_file | ||
try | ||
call maktaba#syscall#Create([l:browser, l:html_file]).Call() | ||
|
@@ -114,12 +121,10 @@ function! syncopate#ExportToBrowser() range | |
|
||
" Kill the HTML buffer (and file, if necessary). | ||
bwipeout! | ||
if maktaba#path#Exists(l:html_file) | ||
call delete(l:html_file) | ||
endif | ||
|
||
" Restore any settings necessary. | ||
call s:SyncopateRestoreSettings(l:settings) | ||
call s:WaitToRemoveFile(l:html_file) | ||
endfunction | ||
|
||
|
||
|
@@ -130,17 +135,24 @@ endfunction | |
function! syncopate#ExportToClipboard() range | ||
" Change any necessary settings to prepare for the HTML export. | ||
let l:settings = s:SyncopateSaveAndChangeSettings() | ||
let l:cmd = [ | ||
\ 'xclip', | ||
\ '-t', 'text/html', | ||
\ '-selection', 'clipboard'] | ||
if has('macunix') | ||
let l:cmd = [ | ||
\ 'pbcopy', | ||
\ '-Prefer', 'rtf', | ||
\ '-pboard', 'general'] | ||
endif | ||
|
||
" Generate the HTML; send it to the clipboard; kill the HTML buffer. | ||
execute a:firstline . ',' . a:lastline 'TOhtml' | ||
call s:PutDivInBody() | ||
let l:contents = join(getline(1, '$'), "\n") | ||
let l:succeeded = 0 | ||
try | ||
call maktaba#syscall#Create([ | ||
\ 'xclip', | ||
\ '-t', 'text/html', | ||
\ '-selection', 'clipboard']).WithStdin(l:contents).Call() | ||
call maktaba#syscall#Create(l:cmd).WithStdin(l:contents).Call() | ||
let l:succeeded = 1 | ||
catch /ERROR(ShellError):/ | ||
call maktaba#error#Shout(v:exception) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we really need the delay, how about
s:RemoveFileAfterDelay(file, delay)
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do