google / vim-syncopate

Make it easy to share beautiful code. DISCLAIMER: This is not an official Google product.
Apache License 2.0
90 stars 16 forks source link

Syncopate fails on files in non-writable directories #2

Closed dbarnett closed 9 years ago

dbarnett commented 10 years ago

I tried using SyncopateExportToBrowser on a file in /etc/ where I didn't have write access and got some errors:

"/etc/passwd.html"
Error detected while processing function syncopate#ExportToBrowser:
line   12:
"/etc/passwd.html" E212: Can't open file for writing
line   19:
E89: No write since last change for buffer 2 (add ! to override)

and my browser opened to a nonexistent file (since the file was never written).

I think rather than writing the buffer from :TOhtml, it would be better to get the contents with getline(1, '$') and write them to a temp file.

dbarnett commented 10 years ago

Or we could skip writing files entirely and use data URIs, something like:

call maktaba#syscall#Create([
    \ 'sensible-browser',
    \ printf('data:text/html,%s'", join(getline(1, '$')))]).Call()
chiphogg commented 10 years ago

I really like the data URI idea, but I'm concerned about length limits. Either the shell or the browser itself could impose a length limit, and we might lose content. I think a temp file will be more robust. In fact, when I ran into length limts before, a temp file was the suggested workaround.

I think I will save the file to a user-configurable location which defaults to somewhere in /tmp.

Down the road, we could even add a flag for users who don't want to clean up the file automatically. Maybe we could add a :SyncopateOpenHtmlFile command for those users.

xanderman commented 10 years ago

There's probably an xdg dir that would be appropriate. XDG_TMP_DIR or XDG_DATA_DIR, perhaps?