From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: Specify page number in hyperlink [to pdf] Date: Fri, 30 Apr 2010 04:10:34 -0400 Message-ID: <26943.1272615034@gamaville.dokosmarshall.org> References: <4BD87ED7.5030907@san.rr.com> <4BD9DC70.3090006@jboecker.de> <4BDA6005.2080708@san.rr.com> Reply-To: nicholas.dokos@hp.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O7lJG-0000Ai-FF for emacs-orgmode@gnu.org; Fri, 30 Apr 2010 04:10:54 -0400 Received: from [140.186.70.92] (port=42487 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O7lJE-00009Z-7D for emacs-orgmode@gnu.org; Fri, 30 Apr 2010 04:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O7lJ9-0004uO-QI for emacs-orgmode@gnu.org; Fri, 30 Apr 2010 04:10:52 -0400 Received: from vms173001pub.verizon.net ([206.46.173.1]:49010) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O7lJ9-0004ty-M0 for emacs-orgmode@gnu.org; Fri, 30 Apr 2010 04:10:47 -0400 Received: from gamaville.dokosmarshall.org ([unknown] [173.76.32.106]) by vms173001.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L1O00KK0K1M2X30@vms173001.mailsrvcs.net> for emacs-orgmode@gnu.org; Fri, 30 Apr 2010 03:10:35 -0500 (CDT) In-reply-to: Message from Joe Riel of "Thu\, 29 Apr 2010 21\:43\:49 PDT." <4BDA6005.2080708@san.rr.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Joe Riel Cc: nicholas.dokos@hp.com, emacs-orgmode@gnu.org Joe Riel wrote: > Jan B=C3=B6cker wrote: > > On 28.04.2010 20:30, Joe Riel wrote: > >=20=20=20 > >> The hyperlink syntax allows specifying a line number, however, > >> that doesn't do anything (other than force the document to > >> be opened inside of emacs) with a non-text file (say a pdf). > >> > >> Is therea an extension to allow specifying a page number > >> so that a link to a pdf is opened at the specified page? > >>=20=20=20=20=20 > > > > There is in the current git version, its not yet documented though. > > > > > > Add an entry to the variable org-file-apps like this: > > ("\\.pdf::\\([0-9]+\\)\\'" . "evince \"%s\" -p %1") > > > > Or as seen in the customize interface: > > Extension: \.pdf::\([0-9]+\)\' > > Command: evince "%s" -p %1 > > > > The subexpression \([0-9]+\) in the regex captures the page number, > > which replaces the %1 in the command string. (This example assumes you > > want to open your PDFs with evince, which accepts a page number after > > the -p option.) > > > > You can then reference a specific page of a PDF like this: > > [[file:/path/to/document.pdf::42]] > > > > I had planned to document this yesterday, but unfortunately spent the > > better part of the day recovering from a cold. I will send a patch > > describing how this works, when exactly the new behaviour kicks in and > > the implications for backwards compatibility as soon as I find time to > > describe it compactly enough to fit into the docstring. > > > > HTH, Jan > >=20=20=20 > A related question; can this extension be used with link abbreviations? >=20 > I tried >=20 > #+LINK: sample file:/home/joe/sample.pdf >=20 > with >=20 > [[sample::3]] >=20 > but that does not work. >=20 This happens in org-link-expand-abbrev: it splits sample::3 into "sample" and "3", looks up "sample" in org-link-abbrev-alist and performs the replacement, then returns the concatenation of that with the "3" part, thereby eliminating the "::" marker that would trigger the further processing necessary to open the pdf file at the given page. You could try #+LINK: sample file:/home/joe/sample.pdf::%s This will work with the [[sample::3]] link, but not with [[sample]]. Alternatively, you could modify the function to keep the "::" marker (at least conditionally: leave it there if it's already there). That would make both of the above work and I think all the examples of section 4.6 would work as well. Here is a very lighly tested patch: diff --git a/lisp/org.el b/lisp/org.el index 9920504..3ede9c4 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -7703,6 +7703,7 @@ call CMD." (let* ((key (match-string 1 link)) (as (or (assoc key org-link-abbrev-alist-local) (assoc key org-link-abbrev-alist))) + (colontype (and (match-end 1) (match-beginning 3) (substring (match-= string 2 link) 0 (- (match-beginning 3) (match-end 1))))) (tag (and (match-end 2) (match-string 3 link))) rpl) (if (not as) @@ -7713,6 +7714,7 @@ call CMD." ((string-match "%s" rpl) (replace-match (or tag "") t t rpl)) ((string-match "%h" rpl) (replace-match (url-hexify-string (or tag "")) t t rpl)) + ((string-equal colontype "::") (concat rpl colontype tag)) (t (concat rpl tag))))) link)) HTH, Nick