macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.47k stars 680 forks source link

Fix :hardcopy not working in macOS 13 Ventura #1390

Closed ychin closed 1 year ago

ychin commented 1 year ago

MacVim's :hardcopy implementation just uses Preview to show the generated PostScript file and lets the user decide what to do with it. macOS 13 Ventura removed PostScript support from Preview, so we now have to manually convert it to PDF first using pstopdf (which is thankfully bundled with macOS).

While we are at it, update the script so that we actually delete the file after sending it to Preview. Previously MacVim never did that and therefore leaks the file in a temp folder until Vim closes, which isn't ideal for privacy. Now, just set a 10 sec timer to delete the file after it's opened (we just need enough time to allow Preview to open and load the file, which doesn't take much time. The 10 sec timer is to account for slow computers).

Fix #1347

MichaelHendry commented 1 year ago

Thanks, guys.

I had worked around the printing issue on Ventura by adding

se printexpr=system('ps2pdf\ '.v:fname_in.'\ '.v:fname_in.'.pdf\ &&\ open\ '.v:fname_in.'.pdf')\ +\ v:shell_error

to my .vimrc file. I'll update my copy of MacVim when prompted, and test after commenting out the "se printexpr..." line.

Michael

ychin commented 1 year ago

There should be a pre-release version (176.1) coming out soon. If you want that version you can go to Advanced settings to enable the pre-release update channel. Otherwise though if it's been working for you (ps2pdf is more powerful than the OS bundled pstopdf anyway) and you prefer just having something stable you could just wait for a proper release (177) later.

MichaelHendry commented 1 year ago

Thanks, I think I'll just sit tight until 177 is released, I'm having a few problems with unstable software (not MacVim) at the moment...

jubilatious1 commented 1 year ago

I'm on Vim 9.0.1276 (MacVim r176), and :hardcopy all alone goes nowhere (MacOS Ventura 13.3).

That means I need to wait for version-177 ? Thanks.

EDIT1: My current workaround for printing (not viewing) is to grab the file path, go to iTerm2, open vim path/to/file, then use :hardcopy from there.

EDIT2: Just tried @MichaelHendry 's workaround and it indeed does work to create/open a PDF in MacOS Preview:

:hardcopy > 0.ps | !ps2pdf 0.ps && open -a preview 0.pdf

ychin commented 1 year ago

@jubilatious1 you need r177 (which is not released yet) or you can get the pre-release version r176.1. Otherwise if the workaround works for you that works too.