emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: [PATCH] org.el: Fix percent substitutions in `org-open-file'
Date: Fri, 2 Sep 2022 22:41:18 +0700	[thread overview]
Message-ID: <tet86v$mie$1@ciao.gmane.io> (raw)
In-Reply-To: <87tu5qm11q.fsf@localhost>

On 02/09/2022 19:08, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> Subject: [PATCH] org.el: Fix percent substitutions in `org-open-file'
> 
>> +(defun org--open-file-format-command
>> +    (mailcap-command file link match-data)
>> +  "Format MAILCAP-COMMAND to launch viewer for FILE.
>> +
>> ...
>> +For example, to specify particular location withing a PDF file,
>> +`org-file-apps' list may have the following entries (order is important):
>> +
>> +    ;; Page and search string,
>> +    ;; e.g. <file:///usr/share/doc/bash/bashref.pdf::34::order of redirections>.
>> +    (\"\\\\.pdf::\\\\([0-9]+\\\\)::\\\\(.+\\\\)\\\\\\='\"
>> +        . \"okular --page %1 --find %2 %s\")
>> +    ;; Internal anchor and search string,
>> +    ;; e.g. <file:///usr/share/doc/bash/bashref.pdf::Redirections::allocate a file>.

In the meanwhile I have realized that it should be

<file:///usr/share/doc/bash/bashref.pdf::#Redirections::allocate a file>

To allow just search as

<file:///usr/share/doc/bash/bashref.pdf::allocate a file>

>> +    (\"\\\\.pdf::\\\\(.+\\\\)::\\\\(.+\\\\)\\\\\\='\"
>> +        . \"okular --find %2 file://%s\\\\\\\\#%1\")
>> +    ;; Page number, e.g. <file:///usr/share/doc/bash/bashref.pdf::34>.
>> +    (\"\\\\.pdf::\\\\([0-9]+\\\\)\\\\\\='\" . \"okular --page %1 %s\")
>> +    ;; Internal reference, e.g. <file:///usr/share/doc/bash/bashref.pdf::Redirections>.

And <file:///usr/share/doc/bash/bashref.pdf::#Redirections>
As a side effect it should dramatically reduce number of backslashes 
since hash symbol becomes a part of %1 substitution.

>> +    (\"\\\\.pdf::\\\\(.+\\\\)\\\\\\='\" . \"okular file://%s\\\\\\\\#%1\")
>> +    ;; No location within the file, optionally followed by \"::\",
>> +    ;; e.g. <file:///usr/share/doc/bash/bashref.pdf>.
>> +    (\"\\\\.pdf\\\\(?:::\\\\)?\\\\\\='\" . \"okular %s\")
> 
> This is a nice set of examples, but it probably does not belong to this
> docstring. I'd rather see this in `org-file-apps' docstring or even in
> the manual.

I thought on this and I do not think it should be added to the manual. 
Instead a set of hooks should be defined for popular PDF viewers: 
evince, zathura, xpdf, firefox, chromium & Co, etc. Such hook injects a 
number of supported `org-file-apps' records and users may add suitable 
hook to e.g. (with-eval-after-load 'org (push ...)). It may be 
implemented as a dedicated package org-pdf-viewers.el. The only problems 
is that adding entries programmatically breaks easy customization 
interface for `org-file-apps'. Currently there is the same issue with 
`org-link-parameters' that is a defcustom variables with entries added 
by various org extensions.

I added the example with hope to better explain the purpose of this 
function.



  reply	other threads:[~2022-09-02 16:42 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 16:08 greedy substitution in org-open-file Maxim Nikulin
2021-02-12  7:16 ` Kyle Meyer
2021-02-12 16:46   ` Maxim Nikulin
2021-02-13  4:38     ` Kyle Meyer
2021-02-15 17:04       ` Maxim Nikulin
2021-03-03 12:47       ` Maxim Nikulin
2021-03-21 12:36       ` Maxim Nikulin
2022-08-27 17:20         ` [PATCH] org.el: Fix percent substitutions in `org-open-file' Max Nikulin
2022-09-02 12:08           ` Ihor Radchenko
2022-09-02 15:41             ` Max Nikulin [this message]
2022-09-03  8:26               ` Ihor Radchenko
2022-09-04 12:16                 ` [PATCH v2] " Max Nikulin
2022-09-05  5:46                   ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='tet86v$mie$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).