emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
479 stars 53 forks source link

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

Open mpedramfar opened 9 months ago

mpedramfar commented 9 months ago

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))))
bdarcus commented 9 months ago

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?

mpedramfar commented 9 months ago

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.

bdarcus commented 9 months ago

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 ;-)

mpedramfar commented 8 months ago

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