jalvesaq / zotcite

Neovim plugin for integration with Zotero
GNU General Public License v3.0
159 stars 13 forks source link

Add ability to open PDFs in Zotero #51

Closed jasonccox closed 2 years ago

jasonccox commented 2 years ago

This behavior is off by default and enabled by setting the vim variable g:zotcite_open_in_zotero to 1.

jalvesaq commented 2 years ago

Thanks for your contribution! However, it doesn't work for me: Zotero was manually installed on Ubuntu Linux 22.04. Maybe I did something wrong...

jasonccox commented 2 years ago

Hm, I'm on Pop!_OS 22.04, which is based on Ubuntu, so that should be pretty similar. I did install Zotero via Flatpak, though, which is probably where the differences arises.

The most likely culprit I can think of is that xdg-open doesn't know that Zotero should handle zotero:// links. If you run xdg-mime query default x-scheme-handler/zotero, what does it output? If it outputs nothing, you can run xdg-mime default zotero.desktop x-scheme-handler/zotero (assuming your installation created the .desktop file as zotero.desktop) and try again.

If that works, I'm happy to update the docs with instructions. If not, we'll have some more debugging to do.

jalvesaq commented 2 years ago

xdg-mime query default x-scheme-handler/zotero outputs zotero.desktop but it still doesn't work. Also, there is no error message because the system call includes & at the end. However, on Linux xdg-open returns immediately. So, we don't need the ampersand and, consequently, we can capture the output and print it if there is an error. Example:

function zotcite#OpenAttachment()
    let zotkey = zotcite#GetCitationKey()
    let fpath = zotcite#GetPDFPath(zotkey, g:zotcite_open_in_zotero)
    if fpath != ''
        let cmd = s:open_cmd . ' "' . fpath . '"'
        let out = system(cmd)
        if v:shell_error != 0
            call zotcite#warning('Error running `' . cmd . '`: ' . substitute(out, "\n", " ", "g"))
        endif
    endif
endfunction

Your code works if I run xdg-mime default zotero.desktop x-scheme-handler/zotero as you suggested. So, it would be good to include the instructions in the documentation.

jasonccox commented 2 years ago

Okay, I've updated the docs.

jalvesaq commented 2 years ago

Thanks!