|
From: | Max Nikulin |
Subject: | Re: [PATCH] org.el: Fix percent substitutions in `org-open-file' |
Date: | Fri, 2 Sep 2022 22:41:18 +0700 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 |
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.
[Prev in Thread] | Current Thread | [Next in Thread] |