all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Proper use of 'org-file-apps'
@ 2013-06-27  4:27 Vladimir Lomov
  2013-06-27  5:52 ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Lomov @ 2013-06-27  4:27 UTC (permalink / raw)
  To: General discussions about Org-mode

Hello,
I wonder how to use 'org-file-apps'.

As I understand, when I run ~C-c C-o~ on a link of form
[[file:file.pdf][a PDF file]] Org mode uses this variable to decide how
to 'open' this type of file. Instead of docview mode of Emacs I want to
use Okular (it allows to select text from PDF file), so I read docstring
of 'org-file-apps' variable and tried to change it accordingly, but
seems I do something strange because following example don't work.

#######################################################################
#+TITLE: Self-contained example
#+AUTHOR: Vladimir Lomov
#+PROPERTY: padline no

* Minimal configuration for Emacs

This is minimal configuration to run Emacs
#+BEGIN_SRC emacs-lisp :tangle org-apps-c.el
  (add-to-list 'load-path "/usr/share/emacs/site-lisp/org")
  (require 'org)
  (setq org-file-apps
   '( ("\\.pdf::\\(\\d+\\)\\'" . "run-me --page %1 %s")
      ("\\.pdf\\'" . "run-me %s")
    )
  )
#+END_SRC

The test script ~run-me~
#+BEGIN_SRC sh :tangle run-me :shebang "#!/bin/bash"
  file=run-me.log
  echo "INPUT" >> ${file}
  echo "'$@'" >> ${file}
#+END_SRC

The test Org document
#+BEGIN_SRC org :tangle sample.org
  ,#+TITEL: A sample
  
  ,* Sample head
  
  1. First item, PDF file, [[file:file.pdf][a file]];
  2. second item, PDF file with selected page, [[file:file.pdf::2][a file]].
#+END_SRC
Note, that to actually test it one needs a PDF file named as
~file.pdf~ located in the same directory as the test Org document.

This is how I run Emacs to test my settings:
#+BEGIN_EXAMPLE
emacs -Q -l org-apps-c.el --eval '(find-file "sample.org")'
#+END_EXAMPLE

What I expect? After I run ~C-c C-o~ on both links, I would expect to
see two different lines (parameters passed to test script) in
~run-me.log~ file. Instead, both parameters are the same. What I do
wrong? Did I understand ~org-file-apps~ correctly?

Org mode version is
#+BEGIN_EXAMPLE
Org-mode version 8.0.3 (release_8.0.3-276-g685b29 @ /usr/share/emacs/site-lisp/org/)
#+END_EXAMPLE

Emacs version is
#+BEGIN_EXAMPLE
GNU Emacs 24.3.50.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.8.2) of 2013-06-26 on HOST
#+END_EXAMPLE
#######################################################################

---
WBR, Vladimir Lomov

-- 
(Never thought I'd be telling Malcolm and Ilya the same thing... :-)
             -- Larry Wall in <199711071819.KAA29909@wall.org>

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

* Re: Proper use of 'org-file-apps'
  2013-06-27  4:27 Proper use of 'org-file-apps' Vladimir Lomov
@ 2013-06-27  5:52 ` Nick Dokos
  2013-06-27  6:58   ` Vladimir Lomov
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2013-06-27  5:52 UTC (permalink / raw)
  To: emacs-orgmode

Vladimir Lomov <lomov.vl@gmail.com> writes:


> #+BEGIN_SRC emacs-lisp :tangle org-apps-c.el
>   (add-to-list 'load-path "/usr/share/emacs/site-lisp/org")
>   (require 'org)
>   (setq org-file-apps
>    '( ("\\.pdf::\\(\\d+\\)\\'" . "run-me --page %1 %s")
>       ("\\.pdf\\'" . "run-me %s")
>     )
>   )
> #+END_SRC
>

\d is Perl regexp syntax for matching a digit, but (afaik) not emacs
syntax. Try

>    '( ("\\.pdf::\\([0-9]+\\)\\'" . "run-me --page %1 %s")

or

>    '( ("\\.pdf::\\([[:digit:]]+\\)\\'" . "run-me --page %1 %s")

instead.
-- 
Nick

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

* Re: Proper use of 'org-file-apps'
  2013-06-27  5:52 ` Nick Dokos
@ 2013-06-27  6:58   ` Vladimir Lomov
  2013-06-27 13:33     ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Lomov @ 2013-06-27  6:58 UTC (permalink / raw)
  To: Nick Dokos; +Cc: emacs-orgmode

** Nick Dokos [2013-06-27 01:52:49 -0400]:

> Vladimir Lomov <lomov.vl@gmail.com> writes:

> > #+BEGIN_SRC emacs-lisp :tangle org-apps-c.el
> >   (add-to-list 'load-path "/usr/share/emacs/site-lisp/org")
> >   (require 'org)
> >   (setq org-file-apps
> >    '( ("\\.pdf::\\(\\d+\\)\\'" . "run-me --page %1 %s")
> >       ("\\.pdf\\'" . "run-me %s")
> >     )
> >   )
> > #+END_SRC


> \d is Perl regexp syntax for matching a digit, but (afaik) not emacs
> syntax. Try

> >    '( ("\\.pdf::\\([0-9]+\\)\\'" . "run-me --page %1 %s")

> or

> >    '( ("\\.pdf::\\([[:digit:]]+\\)\\'" . "run-me --page %1 %s")

> instead.
D'oh, I had searched Emacs manual about meaning of \' but didn't try to
check if \d is acceptable. Nevertheless, 'org-file-apps' docstring must
be updated then, because this \\d part is from it.

Thank you Nick, [[:digit:]] works fine.

---
WBR, Vladimir Lomov

-- 
My family history begins with me, but yours ends with you.
		-- Iphicrates

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

* Re: Proper use of 'org-file-apps'
  2013-06-27  6:58   ` Vladimir Lomov
@ 2013-06-27 13:33     ` Nick Dokos
  2013-06-27 23:56       ` Vladimir Lomov
  0 siblings, 1 reply; 6+ messages in thread
From: Nick Dokos @ 2013-06-27 13:33 UTC (permalink / raw)
  To: emacs-orgmode

Vladimir Lomov <lomov.vl@gmail.com> writes:

> ** Nick Dokos [2013-06-27 01:52:49 -0400]:
>
>> Vladimir Lomov <lomov.vl@gmail.com> writes:
>
>> > #+BEGIN_SRC emacs-lisp :tangle org-apps-c.el
>> >   (add-to-list 'load-path "/usr/share/emacs/site-lisp/org")
>> >   (require 'org)
>> >   (setq org-file-apps
>> >    '( ("\\.pdf::\\(\\d+\\)\\'" . "run-me --page %1 %s")
>> >       ("\\.pdf\\'" . "run-me %s")
>> >     )
>> >   )
>> > #+END_SRC
>
>
>> \d is Perl regexp syntax for matching a digit, but (afaik) not emacs
>> syntax. Try
>
>> >    '( ("\\.pdf::\\([0-9]+\\)\\'" . "run-me --page %1 %s")
>
>> or
>
>> >    '( ("\\.pdf::\\([[:digit:]]+\\)\\'" . "run-me --page %1 %s")
>
>> instead.
> D'oh, I had searched Emacs manual about meaning of \' but didn't try to
> check if \d is acceptable. Nevertheless, 'org-file-apps' docstring must
> be updated then, because this \\d part is from it.
>

Yes, indeed. There's also the vexing question of backslashes. At least
in my version of the C-h v org-file-apps output, the examples appear
with single backslashes in the quoted strings, so if somebody just cuts
and pastes, it is *not* going to work.

Could you make a patch?
-- 
Nick

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

* Re: Proper use of 'org-file-apps'
  2013-06-27 13:33     ` Nick Dokos
@ 2013-06-27 23:56       ` Vladimir Lomov
  2013-06-28  2:14         ` Nick Dokos
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Lomov @ 2013-06-27 23:56 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Nick Dokos

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

Hello,
** Nick Dokos [2013-06-27 09:33:41 -0400]:

> Vladimir Lomov <lomov.vl@gmail.com> writes:

>> ** Nick Dokos [2013-06-27 01:52:49 -0400]:

>>> Vladimir Lomov <lomov.vl@gmail.com> writes:

>>>> #+BEGIN_SRC emacs-lisp :tangle org-apps-c.el
>>>>   (add-to-list 'load-path "/usr/share/emacs/site-lisp/org")
>>>>   (require 'org)
>>>>   (setq org-file-apps
>>>>    '( ("\\.pdf::\\(\\d+\\)\\'" . "run-me --page %1 %s")
>>>>       ("\\.pdf\\'" . "run-me %s")
>>>>     )
>>>>   )
>>>> #+END_SRC


>>> \d is Perl regexp syntax for matching a digit, but (afaik) not emacs
>>> syntax. Try

>>>>    '( ("\\.pdf::\\([0-9]+\\)\\'" . "run-me --page %1 %s")

>>>or

>>>>    '( ("\\.pdf::\\([[:digit:]]+\\)\\'" . "run-me --page %1 %s")

>>> instead.
>> D'oh, I had searched Emacs manual about meaning of \' but didn't try to
>> check if \d is acceptable. Nevertheless, 'org-file-apps' docstring must
>> be updated then, because this \\d part is from it.

> Yes, indeed. There's also the vexing question of backslashes. At least
> in my version of the C-h v org-file-apps output, the examples appear
> with single backslashes in the quoted strings, so if somebody just cuts
> and pastes, it is *not* going to work.

> Could you make a patch?

Something like that?

---
WBR, Vladimir Lomov

-- 
Are we running light with overbyte?

[-- Attachment #2: 0001-Fix-docstring-for-org-file-apps.patch --]
[-- Type: text/x-diff, Size: 1609 bytes --]

From 7840435bd76b38ab536108dfc105fdc53a6aa80d Mon Sep 17 00:00:00 2001
From: Vladimir Lomov <lomov.vl@gmail.com>
Date: Fri, 28 Jun 2013 08:42:15 +0900
Subject: [PATCH] Fix docstring for `org-file-apps'

  * lisp/org.el: `org-file-apps' docstring: doubled backslashes (would
    give usable output when run 'C-h v org-file-apps') and use correct
    regexp to match digits.

  TINYCHANGE
---
 lisp/org.el | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index d0dffc7..5e56231 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1940,8 +1940,8 @@ file identifier are
                  filename matches the regexp.  If you want to
                  use groups here, use shy groups.
 
-                 Example: (\"\\.x?html\\'\" . \"firefox %s\")
-                          (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
+                 Example: (\"\\\\.x?html\\\\'\" . \"firefox %s\")
+                          (\"\\\\(?:xhtml\\\\|html\\\\)\" . \"firefox %s\")
                           to open *.html and *.xhtml with firefox.
 
                - Regular expression which contains (non-shy) groups:
@@ -1956,7 +1956,7 @@ file identifier are
                  In a custom lisp form, you can access the group matches with
                  (match-string n link).
 
-                 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
+                 Example: (\"\\\\.pdf::\\\\([[:digit:]]+\\\\)\\\\'\" . \"evince -p %1 %s\")
                      to open [[file:document.pdf::5]] with evince at page 5.
 
  `directory'   Matches a directory
-- 
1.8.3.1


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

* Re: Proper use of 'org-file-apps'
  2013-06-27 23:56       ` Vladimir Lomov
@ 2013-06-28  2:14         ` Nick Dokos
  0 siblings, 0 replies; 6+ messages in thread
From: Nick Dokos @ 2013-06-28  2:14 UTC (permalink / raw)
  To: emacs-orgmode

Vladimir Lomov <lomov.vl@gmail.com> writes:

> Something like that?

The only question I had was whether there should be a \\' at the end of
the xhtml line. I'm not sure how much real difference it makes, but I
wonder if its absence is going to trip up somebody: "Why do the other
two have a \\' but this one doesn't?"

But I'll let you decide whether it should be present or not. It's
already an improvement as it stands.

I did apply the patch btw and checked that the docstring is as it
should: it's good to go (with the above caveat).

>
> From 7840435bd76b38ab536108dfc105fdc53a6aa80d Mon Sep 17 00:00:00 2001
> From: Vladimir Lomov <lomov.vl@gmail.com>
> Date: Fri, 28 Jun 2013 08:42:15 +0900
> Subject: [PATCH] Fix docstring for `org-file-apps'
>
>   * lisp/org.el: `org-file-apps' docstring: doubled backslashes (would
>     give usable output when run 'C-h v org-file-apps') and use correct
>     regexp to match digits.
>
>   TINYCHANGE
> ---
>  lisp/org.el | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/org.el b/lisp/org.el
> index d0dffc7..5e56231 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -1940,8 +1940,8 @@ file identifier are
>                   filename matches the regexp.  If you want to
>                   use groups here, use shy groups.
>  
> -                 Example: (\"\\.x?html\\'\" . \"firefox %s\")
> -                          (\"\\(?:xhtml\\|html\\)\" . \"firefox %s\")
> +                 Example: (\"\\\\.x?html\\\\'\" . \"firefox %s\")
> +                          (\"\\\\(?:xhtml\\\\|html\\\\)\" . \"firefox %s\")
>                            to open *.html and *.xhtml with firefox.
>  
>                 - Regular expression which contains (non-shy) groups:
> @@ -1956,7 +1956,7 @@ file identifier are
>                   In a custom lisp form, you can access the group matches with
>                   (match-string n link).
>  
> -                 Example: (\"\\.pdf::\\(\\d+\\)\\'\" . \"evince -p %1 %s\")
> +                 Example: (\"\\\\.pdf::\\\\([[:digit:]]+\\\\)\\\\'\" . \"evince -p %1 %s\")
>                       to open [[file:document.pdf::5]] with evince at page 5.
>  
>   `directory'   Matches a directory

-- 
Nick

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

end of thread, other threads:[~2013-06-28  2:15 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-27  4:27 Proper use of 'org-file-apps' Vladimir Lomov
2013-06-27  5:52 ` Nick Dokos
2013-06-27  6:58   ` Vladimir Lomov
2013-06-27 13:33     ` Nick Dokos
2013-06-27 23:56       ` Vladimir Lomov
2013-06-28  2:14         ` Nick Dokos

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.