citar icon indicating copy to clipboard operation
citar copied to clipboard

Feature request: `citar-open-files-or-links`

Open mpedramfar opened this issue 2 years ago • 4 comments

Thanks for the great package! I love how customizable it is.

Is your feature request related to a problem? Please describe. This is a common use case for me, when I want to open a library file if it exists, and if not, open the link in browser. In bibtex-completion, this is implemented in bibtex-completion-open-any.

Describe the solution you'd like A proper way to achieve this would be if citar-open-* functions in general, and citar-open-files function in particular, return non-nil upon success, then the function would be very easy to write:

 (defun citar-open-files-or-links (citekey-or-citekeys)
   "Open library file or URL or DOI link associated with CITEKEY-OR-CITEKEYS.

 Open library file associated with CITEKEY-OR-CITEKEYS.
 If no library file exists, open URL or DOI link associated
 with CITEKEY-OR-CITEKEYS in a browser."
   (interactive (list (citar-select-refs)))
   (unless (citar-open-files citekey-or-citekeys)
     (citar-open-links citekey-or-citekeys)))

Describe alternatives you've considered Currently, this can be implemented by hacking the messaging mechanism:

 (defun citar-open-files-or-links (citekey-or-citekeys)
   "Open library file or URL or DOI link associated with CITEKEY-OR-CITEKEYS.

 Open library file associated with CITEKEY-OR-CITEKEYS.
 If no library file exists, open URL or DOI link associated
 with CITEKEY-OR-CITEKEYS in a browser."
   (interactive (list (citar-select-refs)))
   (let* ((hasfile t)
          (set-message-functions
           (append set-message-functions
                   '((lambda (msg)
                       (when (string-prefix-p "No associated files for" msg)
                         (setq hasfile nil)))))))
     (citar-open-files citekey-or-citekeys)
     (unless hasfile
       (citar-open-links citekey-or-citekeys))))

mpedramfar avatar Oct 08 '23 20:10 mpedramfar

Before I read this more fully ...

This is a common use case for me, when I want to open a library file if it exists, and if not, open the link in browser.

... does not citar-open cover this use case?

bdarcus avatar Oct 08 '23 20:10 bdarcus

It does for the most part. It's just more convenient if I don't have to select the file option every time I want to open a file. What I want is something like a fallback option if the first command fails. Even if the function is not implemented, I think it would be good to have a meaningful return value for citar-open* functions.

mpedramfar avatar Oct 08 '23 21:10 mpedramfar

Even if the function is not implemented, I think it would be good to have a meaningful return value for citar-open* functions.

This is another thing where a PR would be helpful ;-)

bdarcus avatar Oct 10 '23 11:10 bdarcus

This isn't really high priority. When I have time, if it's not implemented, I'll make a PR :)

mpedramfar avatar Oct 15 '23 01:10 mpedramfar