0

I am searching for the best strategy to define custom behaviour for file: org-links locally to a buffer. Is there a way to modify or redefine this type of org-link ?

2 Answers 2

0

I think you need to tweak org-open-at-point of org.el. It contains the following lines:

((string= type "file")
 (if (string-match "::\\([0-9]+\\)\\'" path)
     (setq line (string-to-number (match-string 1 path))
           path (substring path 0 (match-beginning 0)))
   (if (string-match "::\\(.+\\)\\'" path)
       (setq search (match-string 1 path)
             path (substring path 0 (match-beginning 0)))))
 (when (string-match "[*?{]" (file-name-nondirectory path))
   (dired path)
   (org-open-file path arg line search)
   )
 )

So if you'd manage to enclose the behavior you want in a variable, then you can adjust its value for a given buffer (for example it can contain a regexp, a binary name, or just some elisp code), and you are done.

What exactly you are trying to achieve?

3
  • I am using gitit to write a wiki; file links to pages behave differently in the org buffer and the resulting html wiki page, exported by pandoc, so I have to adapt org behaviour to gitit
    – csantosb
    Commented Feb 19, 2015 at 21:29
  • @csantosb: I still don't understand what exactly you are trying to achieve.
    – Adobe
    Commented Feb 19, 2015 at 21:41
  • Under gitit links to wiki pages must appear as [[file:/category1/category2/mypage][my-page]], regardless of the page they appear on, and they are relative to the top level. Problem is, this is meaningless to org, unless I redefine file: links locally
    – csantosb
    Commented Feb 20, 2015 at 12:55
0

I guess the more elegant approach consist on setting locally org-link-abbrev-alist in some buffers, following its name, so that file: links get overloaded.

(setq-local org-link-abbrev-alist
        '(("file" . "%(custom logic)")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.