From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id cAcxG1GDP2CBNQAA0tVLHw (envelope-from ) for ; Wed, 03 Mar 2021 12:38:41 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 2LnjFlGDP2D4FwAAbx9fmQ (envelope-from ) for ; Wed, 03 Mar 2021 12:38:41 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 74D9926AF7 for ; Wed, 3 Mar 2021 13:38:40 +0100 (CET) Received: from localhost ([::1]:39912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lHQlz-0004cR-LF for larch@yhetil.org; Wed, 03 Mar 2021 07:38:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:39710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHQlB-0004cJ-91 for emacs-orgmode@gnu.org; Wed, 03 Mar 2021 07:37:49 -0500 Received: from ciao.gmane.io ([116.202.254.214]:58220) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lHQl9-000407-O2 for emacs-orgmode@gnu.org; Wed, 03 Mar 2021 07:37:49 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1lHQl7-0003aD-OX for emacs-orgmode@gnu.org; Wed, 03 Mar 2021 13:37:45 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Maxim Nikulin 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 Message-ID: References: <87lfb5pbej.fsf@gmail.com> <87czwhw5d5.fsf@kyleam.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------8A355FBB13120E31BB4CF417" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 In-Reply-To: <87czwhw5d5.fsf@kyleam.com> Content-Language: en-US Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: 28 X-Spam_score: 2.8 X-Spam_bar: ++ X-Spam_report: (2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_ADSP_CUSTOM_MED=0.001, FORGED_GMAIL_RCVD=1, FORGED_MUA_MOZILLA=2.309, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, NICE_REPLY_A=-0.001, NML_ADSP_CUSTOM_MED=0.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1614775121; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=6DjwPdjiSV8tgn9bjcweg+J2v8XYNc2GrORrcaHk6FI=; b=a7BsBmQAdGMBGG8uE19DkXqTvqVqshw5sjeYPAKdcAaTekrlpaPZJS/4lwpsZLRPCFiS07 53XqVfVZpJ3YkUGmXbKHBVSETrTes4JqIybpOgrrQHZJ3tcJcqAKyTNIdnCljzj7rrsdlX Cdfk5aRZQu514/U2rC0ri0ZoDZqpQz9Ejy4pvXbBdybeFJG5pl7dhiEihlSIYiwLUqfOtV gSXwNhR7zBr4iSb2NcR//UnGAskQIToV9fjA72lofstpYlr1p+GDBcSjZzP9JhorC+PLuJ p8IZ9dUJpj7LeCcr9XoGesxdQ9tfbne4D6ZYANE/eOlwEqDQ+fQvFpTsPkAEwg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614775121; a=rsa-sha256; cv=none; b=mYouKs/ODictPnJ7lA5HmG6D1xxd0XJIrgmieFgjtTsajDZNd3+UZis5GP+voHKXc6OE9/ RTmgyVE8X88way9KbjAUZzuWHhAu5E6ZHpUNIv4sJ0zjs+W9Tq3ln5FAkObhUpT9saxMoV 9Nf8LzUqHlV8VhoagauVi2oFjlYwysXHwCdAx6InbkQFS6s+j88S6OEzeBig6xvJFEnHrC j4WLFhsk+bZEcWCh6NlEoNKFcE7/woqn+lPPWX+JuoRHLRvJFR2VOyBoLI3z22dB6JMNDp iIWgBKvD/wgjRoxDiUFbPyey76xMRzkF0lm4Bpterf133CZYkw3GvI1mZxpogg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -1.76 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 74D9926AF7 X-Spam-Score: -1.76 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2pn2E7lP+xoW This is a multi-part message in MIME format. --------------8A355FBB13120E31BB4CF417 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 > (). 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. --------------8A355FBB13120E31BB4CF417 Content-Type: text/x-patch; charset=UTF-8; name="org-open-file-multi-subst.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="org-open-file-multi-subst.patch" 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." (save-match-data (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) --------------8A355FBB13120E31BB4CF417--