emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Opening org-cite links with different application
@ 2022-05-25 10:52 Alessandro Bertulli
  2022-05-25 11:00 ` Bruce D'Arcus
  0 siblings, 1 reply; 15+ messages in thread
From: Alessandro Bertulli @ 2022-05-25 10:52 UTC (permalink / raw)
  To: emacs-orgmode

Hi all!

I'm keeping a journal of my research activity with org-cite, and
together with citar and vertico, it works great. I have a question
though.

How can I make Org open the PDF file of a resource, using an external
application?

Let me explain: with the point on a org-cite link, pressing C-c C-o asks
me for the resource to open. Selecting the PDF file opens it with
DocView. I want instead to open it with an external PDF viewer
(specifically, Sioyek). But I can't make it do so! Changing
org-file-apps works only when I open "file:" type links. Apparently,
org-cite links don't read that value.

So I'm asking, particularly to org-cite people: is there a way to do so?

Thanks for your time and your patience.

Bertulli


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 10:52 Alessandro Bertulli
@ 2022-05-25 11:00 ` Bruce D'Arcus
  0 siblings, 0 replies; 15+ messages in thread
From: Bruce D'Arcus @ 2022-05-25 11:00 UTC (permalink / raw)
  To: Alessandro Bertulli; +Cc: org-mode-email

On Wed, May 25, 2022 at 6:53 AM Alessandro Bertulli
<alessandro.bertulli96@gmail.com> wrote:

> How can I make Org open the PDF file of a resource, using an external
> application?
>
> Let me explain: with the point on a org-cite link, pressing C-c C-o asks
> me for the resource to open. Selecting the PDF file opens it with
> DocView. I want instead to open it with an external PDF viewer
> (specifically, Sioyek). But I can't make it do so! Changing
> org-file-apps works only when I open "file:" type links. Apparently,
> org-cite links don't read that value.
>
> So I'm asking, particularly to org-cite people: is there a way to do so?

This is not an org-cite issue per se; it's a citar issue, since that
package provides the org-cite "follow" functionality.

You just need to set `citar-file-open-function` to your preferred
function; say xdg-open.

Note that this may change in the future; I'm contemplating making it
an alist so you can set different ones for different extensions.

Bruce


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
@ 2022-05-25 14:10 Alessandro Bertulli
  2022-05-25 14:49 ` Bruce D'Arcus
  2022-05-25 15:21 ` Max Nikulin
  0 siblings, 2 replies; 15+ messages in thread
From: Alessandro Bertulli @ 2022-05-25 14:10 UTC (permalink / raw)
  To: bdarcus; +Cc: emacs-orgmode

Thanks! Precise as always.

I'm not sure if it's the best way to do so, but it worked for me by
using a lambda:

(setq citar-file-open-function '(lambda (file)
	  (async-shell-command (format-message "sioyek \"%s\"" file))))

Moreover, since I don't really care about the terminal output of the PDF
viewer, I followed an Emacs SE suggestion
(https://emacs.stackexchange.com/a/58341/29817) and made the output
buffer not brought up:

(add-to-list 'display-buffer-alist '("*Async Shell Command*"
display-buffer-no-window (nil)))

which, in case I want to inspect it, it's still visitable with the usual
C-x b.

Thank you!

Alessandro


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 14:10 Alessandro Bertulli
@ 2022-05-25 14:49 ` Bruce D'Arcus
  2022-05-25 15:21 ` Max Nikulin
  1 sibling, 0 replies; 15+ messages in thread
From: Bruce D'Arcus @ 2022-05-25 14:49 UTC (permalink / raw)
  To: Alessandro Bertulli; +Cc: org-mode-email

Just curious:

I'm not familiar with Sioyek (though it looks cool!); why do you need
a lambda there?

On Wed, May 25, 2022 at 10:10 AM Alessandro Bertulli
<alessandro.bertulli96@gmail.com> wrote:
>
> Thanks! Precise as always.
>
> I'm not sure if it's the best way to do so, but it worked for me by
> using a lambda:
>
> (setq citar-file-open-function '(lambda (file)
>           (async-shell-command (format-message "sioyek \"%s\"" file))))
>
> Moreover, since I don't really care about the terminal output of the PDF
> viewer, I followed an Emacs SE suggestion
> (https://emacs.stackexchange.com/a/58341/29817) and made the output
> buffer not brought up:
>
> (add-to-list 'display-buffer-alist '("*Async Shell Command*"
> display-buffer-no-window (nil)))
>
> which, in case I want to inspect it, it's still visitable with the usual
> C-x b.
>
> Thank you!
>
> Alessandro


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 14:10 Alessandro Bertulli
  2022-05-25 14:49 ` Bruce D'Arcus
@ 2022-05-25 15:21 ` Max Nikulin
  2022-05-25 16:00   ` Bruce D'Arcus
  1 sibling, 1 reply; 15+ messages in thread
From: Max Nikulin @ 2022-05-25 15:21 UTC (permalink / raw)
  To: Alessandro Bertulli; +Cc: emacs-orgmode

On 25/05/2022 21:10, Alessandro Bertulli wrote:
> 
> I'm not sure if it's the best way to do so, but it worked for me by
> using a lambda:
> 
> (setq citar-file-open-function '(lambda (file)
> 	  (async-shell-command (format-message "sioyek \"%s\"" file))))

First of all, it is unsafe. File names for papers downloaded from 
various sources may have enough fancy characters including double 
quotes, etc. having special meaning for shell.

Use at least `shell-quote-argument' instead of adding double quotes.

Depending on your OS I suggest to have a look at the implementation of 
`browse-url-xdg-open', `browse-url-default-macosx-browser', 
`browse-url-default-windows-browser' for an example how to start 
external viewer process.

On 25/05/2022 18:00, Bruce D'Arcus wrote:
> You just need to set `citar-file-open-function` to your preferred
> function; say xdg-open.

Is there a reason to avoid emacs global or even system global settings 
obtained through mailcap.el? While `mailcap-view-file' is quite new 
addition, the function was inspired by `org-open-file' and the latter 
queries mailcap settings.

Actually I suspect that there may be some problems especially with 
Emacs-27 (see "org--file-default-apps" thread), but the consequences is 
not clear for me yet.
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40247
mailcap-mime-data erased when parsing mime parts


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 15:21 ` Max Nikulin
@ 2022-05-25 16:00   ` Bruce D'Arcus
  2022-05-25 16:46     ` Max Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Bruce D'Arcus @ 2022-05-25 16:00 UTC (permalink / raw)
  To: Max Nikulin; +Cc: Alessandro Bertulli, org-mode-email

On Wed, May 25, 2022 at 11:26 AM Max Nikulin <manikulin@gmail.com> wrote:
>
> On 25/05/2022 21:10, Alessandro Bertulli wrote:
> >
> > I'm not sure if it's the best way to do so, but it worked for me by
> > using a lambda:
> >
> > (setq citar-file-open-function '(lambda (file)
> >         (async-shell-command (format-message "sioyek \"%s\"" file))))
>
> First of all, it is unsafe. File names for papers downloaded from
> various sources may have enough fancy characters including double
> quotes, etc. having special meaning for shell.
>
> Use at least `shell-quote-argument' instead of adding double quotes.
>
> Depending on your OS I suggest to have a look at the implementation of
> `browse-url-xdg-open', `browse-url-default-macosx-browser',
> `browse-url-default-windows-browser' for an example how to start
> external viewer process.
>
> On 25/05/2022 18:00, Bruce D'Arcus wrote:
> > You just need to set `citar-file-open-function` to your preferred
> > function; say xdg-open.
>
> Is there a reason to avoid emacs global or even system global settings
> obtained through mailcap.el? While `mailcap-view-file' is quite new
> addition, the function was inspired by `org-open-file' and the latter
> queries mailcap settings.

No reason, other than that nobody suggested it.

It could be, however, that when using citar, some users may have more
specialized needs. For example, maybe Alessandro wants to use Sioyek
when reading PDFs of scholarly articles and such, but the standard
system PDF viewer otherwise.

But I suppose these aren't mutually exclusive; citar could always,
notwithstanding the bug you note below, fallback to making use of
mailcap?

> Actually I suspect that there may be some problems especially with
> Emacs-27 (see "org--file-default-apps" thread), but the consequences is
> not clear for me yet.
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=40247
> mailcap-mime-data erased when parsing mime parts
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
@ 2022-05-25 16:16 Alessandro Bertulli
  0 siblings, 0 replies; 15+ messages in thread
From: Alessandro Bertulli @ 2022-05-25 16:16 UTC (permalink / raw)
  To: bdarcus; +Cc: emacs-orgmode

It's a PDF viewer that tries to display scientific and academic writings
at his best. It's actually still experimental, in a way, but it looks
promising and, for now, I don't have big problems. Unfortunately, it has
vi-style keybindings :-)

Anyway, I think I need a lambda because there's not a single function
that do what I want for me. Moreover, I need to take an argument (the
file name), to then call, in an async process, "sioyek
/path/to/file.pdf". I don't know, it seemed the most straightforward to
me. Do you have any better idea?

Alessandro


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
@ 2022-05-25 16:24 Alessandro Bertulli
  2022-05-31 14:53 ` Max Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Alessandro Bertulli @ 2022-05-25 16:24 UTC (permalink / raw)
  To: manikulin; +Cc: emacs-orgmode

Thanks for the suggestion! I wasn't aware of shell-quote-argument, now
it seems much more robust:

(setq citar-file-open-function '(lambda (file)
				  (async-shell-command (format-message
				  "sioyek %s" (shell-quote-argument
				  file)))))

I can't use browse-url-xdg-open because the PDF viewer I want to use
it's not the system default one: when opening PDFs from Org-cite I
expect to open academic documents, so I use Sioyek for them.

However, this creates an annoying problem: now if I want to open two
documents, when opening the second link Emacs asks "A command is running
in the default buffer. Use a new buffer? (yes on no) " which is very
annoying. I suppose that with xdg there's no problem. Do you have any
idea how to make Emacs "not worry" about output buffers?

Alessandro

P.S. I'm afraid I can't follow you: what's the point with mailcap?


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 16:00   ` Bruce D'Arcus
@ 2022-05-25 16:46     ` Max Nikulin
  2022-05-26 18:45       ` Bruce D'Arcus
  0 siblings, 1 reply; 15+ messages in thread
From: Max Nikulin @ 2022-05-25 16:46 UTC (permalink / raw)
  To: emacs-orgmode

On 25/05/2022 23:00, Bruce D'Arcus wrote:
> On Wed, May 25, 2022 at 11:26 AM Max Nikulin wrote:
>> On 25/05/2022 18:00, Bruce D'Arcus wrote:
>>> You just need to set `citar-file-open-function` to your preferred
>>> function; say xdg-open.
>>
>> Is there a reason to avoid emacs global or even system global settings
>> obtained through mailcap.el? While `mailcap-view-file' is quite new
>> addition, the function was inspired by `org-open-file' and the latter
>> queries mailcap settings.
> 
> No reason, other than that nobody suggested it.
> 
> It could be, however, that when using citar, some users may have more
> specialized needs. For example, maybe Alessandro wants to use Sioyek
> when reading PDFs of scholarly articles and such, but the standard
> system PDF viewer otherwise.
> 
> But I suppose these aren't mutually exclusive; citar could always,
> notwithstanding the bug you note below, fallback to making use of
> mailcap?

Disclaimer: I am not a citar user, so be skeptic concerning my 
suggestions. I suppose `mailcap-view-file' (when available) and 
`org-open-file' are at least reasonable defaults when a user has 
expressed their wishes by configuring citar.

It would be great to open the cited document at the particular page 
(e.g. from the locator), but there are a lot of complications on this 
way. The file may contain only a range of pages, every PDF viewer has 
its own way to specify a page or a string to search for. `org-file-apps' 
might be tuned for such purpose (modulo a bug in handling of additional 
arguments).

I have had a quick glance into the code I have an additional question 
why `browse-url' is not used for `citar-file-open-external'.

On 25/05/2022 23:24, Alessandro Bertulli wrote:
> I can't use browse-url-xdg-open because the PDF viewer I want to use
> it's not the system default one: when opening PDFs from Org-cite I
> expect to open academic documents, so I use Sioyek for them.

I mean
   (call-process "xdg-open" nil 0 nil url)
with "sioyek" instead of "xdg-open" if you do not like to set the 
application as the default handler for PDF files. It will allow to avoid 
additional settings for shell buffers. Of course, you will loose ability 
to check command output for errors, it is shoot and forget method 
suitable for most of viewers however.



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 16:46     ` Max Nikulin
@ 2022-05-26 18:45       ` Bruce D'Arcus
  2022-05-26 22:17         ` Tim Cross
  0 siblings, 1 reply; 15+ messages in thread
From: Bruce D'Arcus @ 2022-05-26 18:45 UTC (permalink / raw)
  To: Max Nikulin; +Cc: org-mode-email

On Wed, May 25, 2022 at 12:47 PM Max Nikulin <manikulin@gmail.com> wrote:

> I have had a quick glance into the code I have an additional question
> why `browse-url' is not used for `citar-file-open-external'.

The "external" here means opening files external to emacs.

The typical use case is someone wanting to use a system PDF or image viewer.

I had actually forgotten about that function when initially replying!

Bruce


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-26 18:45       ` Bruce D'Arcus
@ 2022-05-26 22:17         ` Tim Cross
  0 siblings, 0 replies; 15+ messages in thread
From: Tim Cross @ 2022-05-26 22:17 UTC (permalink / raw)
  To: emacs-orgmode


"Bruce D'Arcus" <bdarcus@gmail.com> writes:

> On Wed, May 25, 2022 at 12:47 PM Max Nikulin <manikulin@gmail.com> wrote:
>
>> I have had a quick glance into the code I have an additional question
>> why `browse-url' is not used for `citar-file-open-external'.
>
> The "external" here means opening files external to emacs.
>
> The typical use case is someone wanting to use a system PDF or image viewer.
>
> I had actually forgotten about that function when initially replying!
>


The browse-url library could be a good approach. It does support
external applications and from memory, can be configured based on MIME
type and supports both primary and secondary renderer selection (at
least for html). Ability to easily switch between internal/external
rendering could be very useful. 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
@ 2022-05-27 11:15 Alessandro Bertulli
  0 siblings, 0 replies; 15+ messages in thread
From: Alessandro Bertulli @ 2022-05-27 11:15 UTC (permalink / raw)
  To: theophilusx, bdarcus, manikulin; +Cc: emacs-orgmode

Thanks to all for your answers!

Max wrote:
> I mean
>    (call-process "xdg-open" nil 0 nil url)
> with "sioyek" instead of "xdg-open" if you do not like to set the 
> application as the default handler for PDF files. It will allow to avoid 
> additional settings for shell buffers. Of course, you will loose ability 
> to check command output for errors, it is shoot and forget method 
> suitable for most of viewers however.
Thanks for the suggestion, it works quite well. I can't inspect the
output, but for a PDF viewer that's actually the pretty standard
behaviour, so for me it works fine right now.

To Bruce and Tim: thanks, right now this solution works, but if I figure
out a more clever way to do it (based on your suggestions) I'll give a
shout.

Alessando


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-25 16:24 Opening org-cite links with different application Alessandro Bertulli
@ 2022-05-31 14:53 ` Max Nikulin
  2022-06-01 10:33   ` Alessandro Bertulli
  0 siblings, 1 reply; 15+ messages in thread
From: Max Nikulin @ 2022-05-31 14:53 UTC (permalink / raw)
  To: Alessandro Bertulli, emacs-orgmode

On 25/05/2022 23:24, Alessandro Bertulli wrote:
> 
> P.S. I'm afraid I can't follow you: what's the point with mailcap?

The idea is to keep associations between file types and handlers in a 
single place. Emacs does not have support of XDG handlers (at least out 
of the box) but pretends to have support of mailcap(5) database, 
https://www.rfc-editor.org/rfc/rfc1524.html "RFC 1524 - A User Agent 
Configuration Mechanism For Multimedia Mail Format Information". At 
least Debian provides a script that extracts supported MIME types from 
application .desktop files and adds this info to /etc/mailcap. I do not 
consider mailcap as a perfect solution, but there is nothing better 
within Emacs. I believe that configuring each Emacs package separately 
is even worse. Ideally it should work as a chain of responsibility: 
system-wide configuration in /etc/mailcap, emacs-wide adjustments, maybe 
package specific configuration.

I agree that is customary to set special PDF viewer to open citations. 
Have you considered another approach: to write a script that chooses PDF 
viewer based on file directory and make it system-wide handler? Then 
sioyek may be launched even by clicking on a file in file manager.

P.S. Alessandro, could you, please, response to mails using "reply" 
button. You messages lack of In-Reply-To and References headers, so at 
least thunderbird does not group messages into a thread.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-05-31 14:53 ` Max Nikulin
@ 2022-06-01 10:33   ` Alessandro Bertulli
  2022-06-02 15:53     ` Max Nikulin
  0 siblings, 1 reply; 15+ messages in thread
From: Alessandro Bertulli @ 2022-06-01 10:33 UTC (permalink / raw)
  To: Max Nikulin; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 876 bytes --]

> P.S. Alessandro, could you, please, response to mails using "reply"
> button. You messages lack of In-Reply-To and References headers, so at
> least thunderbird does not group messages into a thread.

Sure, no problem. I usually use vanilla compose-mail to answer,
probably that's the problem. I am now trying directly with Gmail, let
me know if it's working now.

As I wrote in a previous answer, right now I simply set up Citar to
use Sioyek by default:

(setq citar-file-open-function '(lambda (file)
 (call-process "sioyek" nil 0 nil
 file)))

This is not a problem since, when opening a citation, I would most
likely want to use Sioyek for it. However, you gave me nice ideas to
further explore. I'll have a look at mailcap and see if the script is
worth being set up. I'll let you know if I discover something useful!

In any case, thanks for your answer!

Alessandro

[-- Attachment #2: Type: text/html, Size: 1046 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Opening org-cite links with different application
  2022-06-01 10:33   ` Alessandro Bertulli
@ 2022-06-02 15:53     ` Max Nikulin
  0 siblings, 0 replies; 15+ messages in thread
From: Max Nikulin @ 2022-06-02 15:53 UTC (permalink / raw)
  To: Alessandro Bertulli; +Cc: emacs-orgmode

On 01/06/2022 17:33, Alessandro Bertulli wrote:
>  > P.S. Alessandro, could you, please, response to mails using "reply"
>  > button. You messages lack of In-Reply-To and References headers, so at
>  > least thunderbird does not group messages into a thread.
> 
> Sure, no problem. I usually use vanilla compose-mail to answer,
> probably that's the problem. I am now trying directly with Gmail, let
> me know if it's working now.

I do not use Emacs as MUA for a couple of reasons, but I am sure that it 
should be possible to properly reply without switching to web UI. 
`compose-mail' has an argument that allows to pass extra arguments. 
Commands like `message-reply' or `rmail-reply' should be more convenient 
for such purpose.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-06-02 15:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-25 16:24 Opening org-cite links with different application Alessandro Bertulli
2022-05-31 14:53 ` Max Nikulin
2022-06-01 10:33   ` Alessandro Bertulli
2022-06-02 15:53     ` Max Nikulin
  -- strict thread matches above, loose matches on Subject: below --
2022-05-27 11:15 Alessandro Bertulli
2022-05-25 16:16 Alessandro Bertulli
2022-05-25 14:10 Alessandro Bertulli
2022-05-25 14:49 ` Bruce D'Arcus
2022-05-25 15:21 ` Max Nikulin
2022-05-25 16:00   ` Bruce D'Arcus
2022-05-25 16:46     ` Max Nikulin
2022-05-26 18:45       ` Bruce D'Arcus
2022-05-26 22:17         ` Tim Cross
2022-05-25 10:52 Alessandro Bertulli
2022-05-25 11:00 ` Bruce D'Arcus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).