emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* RFC: Syntax for page numbers in file: links?
@ 2010-01-03  0:42 Jan Böcker
  2010-01-03 20:14 ` Samuel Wales
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Jan Böcker @ 2010-01-03  0:42 UTC (permalink / raw)
  To: Org Mode

Hello List,

During the discussion in the "protocol for PDFs?" thread, I realized
that docview: links are an almost exact copy of file: links, the only
single difference being that file: takes a line number and docview:
links take a page number.

Up until now, (docview:) links to PDF files have been the only link type
known to me which took a page number. With the upcoming integration of
Xournal and Org that Daniel M. German is working on, there will already
be two of those.

Daniel also wants to add org-store-link functionality to evince, so he
needs a link type with page numbers for PDFs, too. I could (and have in
a proof-of-concept version) modify org-docview.el to open PDFs with an
external viewer, but I think what really should happen is the following:

- We need a syntax to specify an (optional) page number for file:
  links, and make the line number optional as well.
  This might look something like this:

  - file:<path>[:page][::line]
  - file:~/some-file.txt::23    some-file.txt, line 23
  - file:~/document.pdf:4       document.pdf, page 4
  - file:~/document.odf:3::5    document.odf, page 3, line 5

  This is only what comes to my mind immediately about one possibility
  of encoding this.

- org-docview-store-link should return links in the new syntax
  (e.g. file:~/some-doc.pdf:5 instead of docview:~/some-doc.pdf::5)

- the same syntax could also be used to integrate evince and Xournal

- org-file-apps should allow to specify how to pass a page number to
  an external program. Unlike the file name, this is an optional
  argument, as a link may not specify a page number at all.

  I do not know how to do this in an elegant way, maybe let
  the user specify multiple entries - one for links with a page
  number, one for links without.

- the same should apply to line numbers - maybe someone will integrate
  Org with Open Office or some heretic wants to open all text files in
  zile, who knows?

- if a link with a page number is opened, org-file-apps specifies
  "Visit with Emacs", and emacs decides to open it in doc-view-mode,
  doc-view-goto-page should be called with the page number. (I imagine
  this would be possible using the right hooks?)

- Line number and page number also seem somewhat arbitrary as the only
  pieces of data available to point to a specific location inside a
  document. There are HTML fragment identifiers, which AFAIK work in
  http: links but do not in file: links.
  One might also imagine specifying a precise position in a PDF
  using a line number and a percentage to indicate how far the
  page should be scrolled down.

  So if it is feasible at all, we might want an even more general syntax
  to specify a "target location", maybe attributes such as
  [[file:/path/to/file][page=5,line=3][Description]]
  [[file:notes.txt][search="The quick brown fox"][Description]]

  This may obviously create more problems with backward compatibility.


Luckily, there has been no release featuring docview: links yet, so
there still is a chance to correct this mistake without breaking too much.

If there will be no special syntax for page numbers, we could also
interpret the line number as a page number for PDF and Xournal files,
but that number would still need to be passed to an external application
and cause doc-view-goto-page to be called when visiting a PDF in emacs.

I really do not want to create another file: link type with
org-docview.el, which is why I ask y'all to comment!

- Jan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-03  0:42 RFC: Syntax for page numbers in file: links? Jan Böcker
@ 2010-01-03 20:14 ` Samuel Wales
  2010-01-05 12:32 ` Carsten Dominik
  2010-01-07  1:24 ` Torsten Wagner
  2 siblings, 0 replies; 8+ messages in thread
From: Samuel Wales @ 2010-01-03 20:14 UTC (permalink / raw)
  To: Jan Böcker; +Cc: Org Mode

If you need the syntax to be more general, take a look at extensible
syntax on this list.

-- 
Q: How many CDC "scientists" does it take to change a lightbulb?
A: You only think it's dark. [CDC has denied ME/CFS for 25 years]
=================================================================
Retrovirus: http://www.wpinstitute.org/xmrv/xmrv_qa.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-03  0:42 RFC: Syntax for page numbers in file: links? Jan Böcker
  2010-01-03 20:14 ` Samuel Wales
@ 2010-01-05 12:32 ` Carsten Dominik
  2010-01-05 17:05   ` Jan Böcker
  2010-01-07  1:24 ` Torsten Wagner
  2 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-01-05 12:32 UTC (permalink / raw)
  To: Jan Böcker; +Cc: Org Mode


On Jan 3, 2010, at 1:42 AM, Jan Böcker wrote:

> Hello List,
>
> During the discussion in the "protocol for PDFs?" thread, I realized
> that docview: links are an almost exact copy of file: links, the only
> single difference being that file: takes a line number and docview:
> links take a page number.
>
> Up until now, (docview:) links to PDF files have been the only link  
> type
> known to me which took a page number. With the upcoming integration of
> Xournal and Org that Daniel M. German is working on, there will  
> already
> be two of those.
>
> Daniel also wants to add org-store-link functionality to evince, so he
> needs a link type with page numbers for PDFs, too. I could (and have  
> in
> a proof-of-concept version) modify org-docview.el to open PDFs with an
> external viewer, but I think what really should happen is the  
> following:
>
> - We need a syntax to specify an (optional) page number for file:
>  links, and make the line number optional as well.
>  This might look something like this:
>
>  - file:<path>[:page][::line]
>  - file:~/some-file.txt::23    some-file.txt, line 23
>  - file:~/document.pdf:4       document.pdf, page 4
>  - file:~/document.odf:3::5    document.odf, page 3, line 5
>
>  This is only what comes to my mind immediately about one possibility
>  of encoding this.
>
> - org-docview-store-link should return links in the new syntax
>  (e.g. file:~/some-doc.pdf:5 instead of docview:~/some-doc.pdf::5)

Yes, I think that would make sense.

> - the same syntax could also be used to integrate evince and Xournal

I have yesterday implemented modifies for file link:

file+sys: now forces opening a file with the system's open command
file+emacs: forces opening in Emacs.
I guess it would make sense to make more of these, so that
one could select a specific viewer for selected files, what
do you think?


>
> - org-file-apps should allow to specify how to pass a page number to
>  an external program. Unlike the file name, this is an optional
>  argument, as a link may not specify a page number at all.
>
>  I do not know how to do this in an elegant way, maybe let
>  the user specify multiple entries - one for links with a page
>  number, one for links without.

This is not easy at all, but I am sure it can be done.

>
> - the same should apply to line numbers - maybe someone will integrate
>  Org with Open Office or some heretic wants to open all text files in
>  zile, who knows?

Line numbers is a rotten concept - I am not even sure we
should support it at all.

>
> - if a link with a page number is opened, org-file-apps specifies
>  "Visit with Emacs", and emacs decides to open it in doc-view-mode,
>  doc-view-goto-page should be called with the page number. (I imagine
>  this would be possible using the right hooks?)

You need to do this in the org-docview code.

>
> - Line number and page number also seem somewhat arbitrary as the only
>  pieces of data available to point to a specific location inside a
>  document. There are HTML fragment identifiers, which AFAIK work in
>  http: links but do not in file: links.
>  One might also imagine specifying a precise position in a PDF
>  using a line number and a percentage to indicate how far the
>  page should be scrolled down.
>
>  So if it is feasible at all, we might want an even more general  
> syntax
>  to specify a "target location", maybe attributes such as
>  [[file:/path/to/file][page=5,line=3][Description]]
>  [[file:notes.txt][search="The quick brown fox"][Description]]
>
>  This may obviously create more problems with backward compatibility.

I am not sure if it makes sense to handle more that a page number,  
really.


> Luckily, there has been no release featuring docview: links yet, so
> there still is a chance to correct this mistake without breaking too  
> much.

Well, the next release is not far off....

> If there will be no special syntax for page numbers, we could also
> interpret the line number as a page number for PDF and Xournal files,

Yes, why not.

> but that number would still need to be passed to an external  
> application
> and cause doc-view-goto-page to be called when visiting a PDF in  
> emacs.
>
> I really do not want to create another file: link type with
> org-docview.el, which is why I ask y'all to comment!
>
> - Jan
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-05 12:32 ` Carsten Dominik
@ 2010-01-05 17:05   ` Jan Böcker
  2010-01-06  9:05     ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Böcker @ 2010-01-05 17:05 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode

> I am not sure if it makes sense to handle more that a page number, really.

I have thought about this again and concluded that the approach in my
first post is, indeed, over-engineered. I also believe the approach
proposed in this post to be flexible enough to handle some extensions.

On 05.01.2010 13:32, Carsten Dominik wrote:

> 
> I have yesterday implemented modifies for file link:
> 
> file+sys: now forces opening a file with the system's open command
> file+emacs: forces opening in Emacs.
> I guess it would make sense to make more of these, so that
> one could select a specific viewer for selected files, what
> do you think?

The method of opening a file should not be specified in the link itself,
unless it makes sense to change it for an individual link. Imagine two
users exchanging org files, where one likes to open PDFs with evince and
the other prefers doc-view-mode.

However, this would be useful for links to file types which org-mode
does not know anything about; the user would not have to tell org-mode
about them by modifying org-file-apps first.
Maybe this should not force the opening method, but provide the default
if org-file-apps has nothing to say?


>>
>> - org-file-apps should allow to specify how to pass a page number to
>>  an external program. Unlike the file name, this is an optional
>>  argument, as a link may not specify a page number at all.
>>
>>  I do not know how to do this in an elegant way, maybe let
>>  the user specify multiple entries - one for links with a page
>>  number, one for links without.
> 
> This is not easy at all, but I am sure it can be done.
> 

org-file-apps already allows matching regular expressions against the
file name.
I propose the following changes:
- match the regular expressions against the whole link
- if the matching regex used grouping, in addition to replacing %s with
the file name in a command string, replace %1 with the first match, %2
with the second, etc.
- if the org-file-apps entry specifies a lisp form to be evaluated, make
the group matches available to the lisp form being evaluated.

- org-docview.el would only handle org-store-link functionality and
generate links such as file:<path>::<page>.

With these changes, the following sample entries in org-file-apps could
then specify the method of how to open links to PDF files with and
without page number specifications.

Open PDFs in evince:

regex: 		\.pdf\'
command: 	evince %s

regex:		\.pdf::\(\d+\)\'
command:	evince %s -p %1

Open PDFs in doc-view-mode:

regex:		\.pdf\'
visit in emacs

regex:		\.pdf::\(\d+\)\'
lisp form:	(progn (org-open-file file 1)
		       (docview-goto-page (match-string 1 link)))

The lisp form in the last entry could go into org-docview.el as a
convenience function. We would also need a way for org-docview.el to
supply default entries for org-file-apps, maybe a variable
org-file-apps-defaults-alist or something.

AFAIK, this approach would be backwards-compatible with current
org-file-apps entries, which typically match an extension at the end of
the string and specify a command to open the file with, which gets
passed the file name via %s. If the link specifies arguments, the
current entries would no longer match, but they cannot handle arguments
anyway.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-05 17:05   ` Jan Böcker
@ 2010-01-06  9:05     ` Carsten Dominik
  2010-01-06 11:07       ` Jan Böcker
  0 siblings, 1 reply; 8+ messages in thread
From: Carsten Dominik @ 2010-01-06  9:05 UTC (permalink / raw)
  To: Jan Böcker; +Cc: Org Mode

Hi Jan,

I don't think this will make it into 6.34, so we can relax a bit - in
particular also because I am currently not updating the Emacs
distribution - it is in feature freeze.

Would you like to work on a patch that allows interpreting page numbers
for external applications?

- Carsten

On Jan 5, 2010, at 6:05 PM, Jan Böcker wrote:

>> I am not sure if it makes sense to handle more that a page number,  
>> really.
>
> I have thought about this again and concluded that the approach in my
> first post is, indeed, over-engineered. I also believe the approach
> proposed in this post to be flexible enough to handle some extensions.
>
> On 05.01.2010 13:32, Carsten Dominik wrote:
>
>>
>> I have yesterday implemented modifies for file link:
>>
>> file+sys: now forces opening a file with the system's open command
>> file+emacs: forces opening in Emacs.
>> I guess it would make sense to make more of these, so that
>> one could select a specific viewer for selected files, what
>> do you think?
>
> The method of opening a file should not be specified in the link  
> itself,
> unless it makes sense to change it for an individual link. Imagine two
> users exchanging org files, where one likes to open PDFs with evince  
> and
> the other prefers doc-view-mode.
>
> However, this would be useful for links to file types which org-mode
> does not know anything about; the user would not have to tell org-mode
> about them by modifying org-file-apps first.
> Maybe this should not force the opening method, but provide the  
> default
> if org-file-apps has nothing to say?
>
>
>>>
>>> - org-file-apps should allow to specify how to pass a page number to
>>> an external program. Unlike the file name, this is an optional
>>> argument, as a link may not specify a page number at all.
>>>
>>> I do not know how to do this in an elegant way, maybe let
>>> the user specify multiple entries - one for links with a page
>>> number, one for links without.
>>
>> This is not easy at all, but I am sure it can be done.
>>
>
> org-file-apps already allows matching regular expressions against the
> file name.
> I propose the following changes:
> - match the regular expressions against the whole link
> - if the matching regex used grouping, in addition to replacing %s  
> with
> the file name in a command string, replace %1 with the first match, %2
> with the second, etc.
> - if the org-file-apps entry specifies a lisp form to be evaluated,  
> make
> the group matches available to the lisp form being evaluated.
>
> - org-docview.el would only handle org-store-link functionality and
> generate links such as file:<path>::<page>.
>
> With these changes, the following sample entries in org-file-apps  
> could
> then specify the method of how to open links to PDF files with and
> without page number specifications.
>
> Open PDFs in evince:
>
> regex: 		\.pdf\'
> command: 	evince %s
>
> regex:		\.pdf::\(\d+\)\'
> command:	evince %s -p %1
>
> Open PDFs in doc-view-mode:
>
> regex:		\.pdf\'
> visit in emacs
>
> regex:		\.pdf::\(\d+\)\'
> lisp form:	(progn (org-open-file file 1)
> 		       (docview-goto-page (match-string 1 link)))
>
> The lisp form in the last entry could go into org-docview.el as a
> convenience function. We would also need a way for org-docview.el to
> supply default entries for org-file-apps, maybe a variable
> org-file-apps-defaults-alist or something.
>
> AFAIK, this approach would be backwards-compatible with current
> org-file-apps entries, which typically match an extension at the end  
> of
> the string and specify a command to open the file with, which gets
> passed the file name via %s. If the link specifies arguments, the
> current entries would no longer match, but they cannot handle  
> arguments
> anyway.

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-06  9:05     ` Carsten Dominik
@ 2010-01-06 11:07       ` Jan Böcker
  2010-01-06 11:08         ` Carsten Dominik
  0 siblings, 1 reply; 8+ messages in thread
From: Jan Böcker @ 2010-01-06 11:07 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: Org Mode

On 06.01.2010 10:05, Carsten Dominik wrote:

> Would you like to work on a patch that allows interpreting page numbers
> for external applications?

I'll definitely take a stab at it and see how far I get while learning
more about elisp along the way. I will post to the mailing list if I
make significant progress or give up.

- Jan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-06 11:07       ` Jan Böcker
@ 2010-01-06 11:08         ` Carsten Dominik
  0 siblings, 0 replies; 8+ messages in thread
From: Carsten Dominik @ 2010-01-06 11:08 UTC (permalink / raw)
  To: Jan Böcker; +Cc: Org Mode


On Jan 6, 2010, at 12:07 PM, Jan Böcker wrote:

> On 06.01.2010 10:05, Carsten Dominik wrote:
>
>> Would you like to work on a patch that allows interpreting page  
>> numbers
>> for external applications?
>
> I'll definitely take a stab at it and see how far I get while learning
> more about elisp along the way. I will post to the mailing list if I
> make significant progress or give up.

Thanks!

- Carsten

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: RFC: Syntax for page numbers in file: links?
  2010-01-03  0:42 RFC: Syntax for page numbers in file: links? Jan Böcker
  2010-01-03 20:14 ` Samuel Wales
  2010-01-05 12:32 ` Carsten Dominik
@ 2010-01-07  1:24 ` Torsten Wagner
  2 siblings, 0 replies; 8+ messages in thread
From: Torsten Wagner @ 2010-01-07  1:24 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

during following this thread I noticed one "problem" with the page and line-
number concept

>   - file:~/some-file.txt::23    some-file.txt, line 23

A txt-file may have no clear page boarders. Thus only a line number might make 
sens

>   - file:~/document.pdf:4       document.pdf, page 4

A PDF may have only pages and maybe (I do not know at the moment) there is a 
way to address bookmarks and toc entries and even line numbers

>   - file:~/document.odf:3::5    document.odf, page 3, line 5

A odf can have both line numbers and page numbers as well as chapters-, 
paragraphs- etc. markers.

Thus, it depends heavily on the kind of document and on the ability of the 
external reader. 
I would suggest to make sure, if no page number but a line number is given, 
this line number should be dealt as absolute value (starting from the very 
first line). If a page number and a line number is given, the line number is 
relative to the given page. Furthermore, there should be something to deal 
with wrong inputs. E.g. given page number for file-types which does not have 
defined pages (like txt, source code, etc.). 

Nice would be the possibility to refer to TOC, paragraphs and other markers 
since they would keep valid even if later versions of the file change the 
position and make page and line number invalid.

Just my thoughts

Torsten




> 
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-01-07  1:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-03  0:42 RFC: Syntax for page numbers in file: links? Jan Böcker
2010-01-03 20:14 ` Samuel Wales
2010-01-05 12:32 ` Carsten Dominik
2010-01-05 17:05   ` Jan Böcker
2010-01-06  9:05     ` Carsten Dominik
2010-01-06 11:07       ` Jan Böcker
2010-01-06 11:08         ` Carsten Dominik
2010-01-07  1:24 ` Torsten Wagner

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