3

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 '15 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). – incandescentman Jul 24 '15 at 5:44
  • Did you find a solution to this? – serv-inc Oct 13 '15 at 11:48
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
'(org-fontify-meta-lines-and-blocks))))

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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