Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mpedramfar opened this issue Oct 8, 2023 · 4 comments
Open

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

mpedramfar opened this issue Oct 8, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@mpedramfar
Copy link
Contributor

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 mpedramfar added the enhancement New feature or request label Oct 8, 2023
@bdarcus
Copy link
Contributor

bdarcus commented Oct 8, 2023

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
Copy link
Contributor Author

mpedramfar commented Oct 8, 2023

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
Copy link
Contributor

bdarcus commented Oct 10, 2023

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants