If I have an [[Org Mode Link]] and then make that line a # Comment [[Org Mode Link]] the fontification changes and I can no longer tell that it is a link. Can this behavior be changed?

  • 3
    One thing you can do is use the #+BEGIN_COMMENT and #+END_COMMENT commands as documented here. Of course, this isn't a perfect solution because it requires you to edit your document, and it's not as pretty visually.
    – PythonNut
    Feb 19, 2015 at 21:55
  • Or better yet, a way to fontify not just org-mode style links, but make anything starting with http:// into an active hyperlink (i.e. such that org-return would follow the link). Jul 24, 2015 at 5:44
  • Did you find a solution to this?
    – serv-inc
    Oct 13, 2015 at 11:48

1 Answer 1


Yes it can.

The function org-set-font-lock-defaults sets font lock defaults for org mode buffers for all the types of org faces.

Not only the contents itself is important but also the order in which it is defined.

FYI, I will show pieces of code from the actual function (org version 8.3.4):

This block takes care of fontifing links. The type of link you are interested in is fourth line ('bracket).

;; Links
(if (memq 'tag lk) '(org-activate-tags (1 'org-tag prepend)))
(if (memq 'angle lk) '(org-activate-angle-links (0 'org-link t)))
(if (memq 'plain lk) '(org-activate-plain-links (0 'org-link t)))
(if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
(if (memq 'radio lk) '(org-activate-target-links (1 'org-link t)))
(if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
(if (memq 'footnote lk) '(org-activate-footnote-links))

The comment lines (meta lines) are taken care by following piece of code:

;; Blocks and meta lines

The most easy (but maybe also a hacky) way to do it is remove the "bracket" s-expression from the list org-font-lock-extra-keywords and add it to the end of the list.

You can do so using a hook named org-font-lock-set-keywords-hook to "swap" these.

I am now using this code:

(defun vlk/org-font-links-in-comments ()
  ;; get bracket link s-expression for the font lock
  (let ((bracket-link-face (nth 12 org-font-lock-extra-keywords)))
    ;; remove the font lock from the list
    (delete bracket-link-face org-font-lock-extra-keywords)
    ;; add it to the end
    (add-to-list 'org-font-lock-extra-keywords bracket-link-face t)))

(org-add-hook 'org-font-lock-set-keywords-hook 'vlk/org-font-links-in-comments)

It certainly can be improved but it is functional for me so far.

  • Seems like this is no longer working for current emacs 27.2 / org-mode 9.6. Is there a recommended way to do this now?
    – Mark
    Jul 6, 2022 at 21:06

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.