14

Org-mode offers a variety of different link types ([http], [file], [bibtex], [magit]...). However, they all get the same look defined by the face value for org-link.

Is it possible to e.g. change the background color depending on the type of link? So that http links would have a yellow background and file links a blue one?

1
  • Yes, it's possible, and there is probably more then one way to do it... but that's about all I can tell you :) Hopefully someone with more elisp skills then I have can write out a simple minor mode or something.
    – Brian Z
    Commented Apr 26, 2015 at 10:40

3 Answers 3

3

Starting from Org-Mode version 9.x.

Thanks to John Kitchin's answer in Fontify broken links in org-mode, I applied different faces for id-links and file-links with a code similar to this:

  (defface org-link-id
    '((t :foreground "#50fa7b"
         :weight bold
         :underline t))
    "Face for Org-Mode links starting with id:."
    :group 'org-faces)
  (defface org-link-file
    '((t :foreground "#ff5555"
         :weight bold
         :underline t))
    "Face for Org-Mode links starting with file:."
    :group 'org-faces)
  (org-link-set-parameters
   "id"
   :face 'org-link-id)
  (org-link-set-parameters
   "file"
   :face 'org-link-file))
1

I would make this a comment, but I don't have enough rep so here goes:

Check out this function: org-activate-plain-links (in org.el).

You can modify the function around the 'add-text-properties', doing a match on each link using a cond for instance. I have student supervision now, but if you don't succeed in doing this, I'll add more information later.

2
  • org-activate-plain-links is a function alias and interactive for ignore, defined in subr.el.gz. This command is obsolete since 9.0; use ignore instead.
    – HappyFace
    Commented Sep 22, 2021 at 11:27
  • org-activate-links is the new function.
    – HappyFace
    Commented Sep 22, 2021 at 11:40
1

See https://github.com/jkitchin/org-ref/blob/651d24df5f52bb3f0d31c71ebdb604ce356fe674/org-ref.el#L484

I use that code to change the appearance of links in org-ref using font lock at https://github.com/jkitchin/org-ref/blob/651d24df5f52bb3f0d31c71ebdb604ce356fe674/org-ref.el#L742

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.