emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Maxim Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Org mode links: Open a PDF file at a given page and highlight a given string
Date: Wed, 3 Mar 2021 19:37:39 +0700	[thread overview]
Message-ID: <s1nvuk$d45$1@ciao.gmane.io> (raw)
In-Reply-To: <87czwhw5d5.fsf@kyleam.com>

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

On 03/03/2021 05:36, Kyle Meyer wrote:
> Rodrigo Morales writes:
> [...]
>> + create a Org link to specific pages of a PDF and highlight a given
>>    string.
>> #+begin_src emacs-lisp :results silent
>> (setq org-file-apps
>>        '(("\\.pdf::\\([0-9]+\\)::\\([^:]+\\)\\'" . "zathura -P %1 -f %2 %s")))
>> #+end_src
>> The following link must open the PDF at a given page and highlight the
>> given string. However, I'm getting the following error (see the
>> =#+begin_example= block below.)
>> [[file:~/Downloads/grub.pdf::95::do]]

Correct link should be [[info:grub#true]] (a joke, at least a kind of).

Actually I never considered search string for highlighting of particular 
text, so thank you for the hint. Browsers could generate (mutually 
incompatible) link to particular rectangle. With xpopple (fork of old 
xpdf) it is possible to send command to select region.

However I think it is better to use logical links instead of page numbers:

    okular --find do ~/Downloads/grub.pdf'#true'
    xpdf ~/Downloads/grub.pdf +true

Unfortunately firefox replaces "#" to percent-encoded sequence in 
command line argument and could not find the file. It requires editing 
in address bar.

>> #+begin_example
>> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>>    replace-match(nil t t "zathura -P 95 -f %2 /home/username/Downloads/grub....")
> I haven't looked at this closely or tried to trigger the error, but an
> in-flight patch is touching this area
> (<https://orgmode.org/list/87mtw8fupl.fsf@kyleam.com>).  I've yet to
> revisit it to address Maxim's helpful feedback, but I hope to soon and
> will look at this error then too.

Kyle, your patch works for such handlers. This case is another argument 
to replace all substitutions in a single pass. Global state (match data) 
is the source of the problem.

I am attaching informal single-line patch for quick plumbing. 
Alternative is to use save-match-data around string-match inside the loop.

[-- Attachment #2: org-open-file-multi-subst.patch --]
[-- Type: text/x-patch, Size: 568 bytes --]

diff --git a/lisp/org.el b/lisp/org.el
index fd6226702..f45adb308 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8757,8 +8757,8 @@ If the file does not exist, throw an error."
 	(let ((match-index 1)
 	      (number-of-groups (- (/ (length link-match-data) 2) 1)))
-	  (set-match-data link-match-data)
 	  (while (<= match-index number-of-groups)
+	    (set-match-data link-match-data)
 	    (let ((regex (concat "%" (number-to-string match-index)))
 		  (replace-with (match-string match-index dlink)))
 	      (while (string-match regex cmd)

  reply	other threads:[~2021-03-03 12:38 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-02 20:07 Org mode links: Open a PDF file at a given page and highlight a given string Rodrigo Morales
2021-03-02 22:36 ` Kyle Meyer
2021-03-03 12:37   ` Maxim Nikulin [this message]
2021-09-27 16:39   ` Max Nikulin
2021-03-03  2:31 ` Juan Manuel Macías
2021-03-03 14:51   ` Maxim Nikulin
2021-03-03 16:11     ` Juan Manuel Macías
2021-03-05 13:02       ` Maxim Nikulin
2022-09-03 13:00 ` Max Nikulin
2022-09-20 11:54   ` Ihor Radchenko
2022-09-20 17:03     ` Max Nikulin
2022-09-21  8:17       ` Ihor Radchenko
2022-09-21  8:18       ` Ihor Radchenko
2023-01-25 11:46         ` AW
2023-01-25 11:55           ` Ihor Radchenko
2023-01-25 12:35           ` Max Nikulin
2023-01-25 14:33           ` Jean Louis
2022-10-04  6:45 ` 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:

  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='s1nvuk$d45$1@ciao.gmane.io' \
    --to=manikulin@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* 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


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