emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Frankie Y. Liu" <frankie.y.liu@gmail.com>
To: emacs-orgmode@gnu.org
Subject: org-file-apps regex matching against path not link
Date: Thu, 12 Apr 2018 12:22:48 -0700	[thread overview]
Message-ID: <CAD+RoizZVCp=s63weix08t9djo8Kmr71er=tZRKHsS2v6jCsVA@mail.gmail.com> (raw)

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

I wanted to open a pdf at a particular page, the instructions under
org-file-apps suggested using

(add-to-list 'org-file-apps '("\\.pdf::\\(\\d+\\)\\'" . "evince -p %1 %s"))

This doesn't work because the regular expression doesn't parse the link but
the path.  Therefore the ::(\d+) part is not being matched.

I had to write my own version using both file and link but maybe there is a
better way -- or a more elegant solution than what I have below.  Please
let me know.

(add-to-list 'org-file-apps
                       '("\\.pdf\\'" .
                         (lambda
                           (file link)
                           (let*
                               ((mylink
                                 (split-string link "::"))
                                (option
                                 (>
                                  (length mylink)
                                  1))
                                (cmd
                                 (concat "evince " file
                                         (and option
                                              (concat " -p "
                                                      (nth 1 mylink))))))
                             (message "Running %s...done" cmd)
                             (start-process-shell-command cmd nil cmd)))))

[-- Attachment #2: Type: text/html, Size: 2041 bytes --]

             reply	other threads:[~2018-04-12 19:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-12 19:22 Frankie Y. Liu [this message]
2018-04-12 19:38 ` org-file-apps regex matching against path not link Nicolas Goaziou
2018-04-12 22:41   ` Frankie Y. Liu
2018-04-14  7:42     ` Nicolas Goaziou
2018-04-14 14:05       ` Frankie Y. Liu
2018-04-14 14:29         ` Nicolas Goaziou

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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='CAD+RoizZVCp=s63weix08t9djo8Kmr71er=tZRKHsS2v6jCsVA@mail.gmail.com' \
    --to=frankie.y.liu@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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