I kept on working on the idea that a minor change to org-activate-links was a simple, yet good solution, and propose that adding an overlay to the visible part of the link (inside the comment) will allow us to set a different face. This spares us from the precedence that font-lock-comment-face takes over almost everything else, and still allows us a link inside a comment line that will be distinguishable and actionable (both via keyboard and mouse).
Attached is the tiny patch that modifies two files: - org.el/org-activate-links (added an overlay to links in comments). - org-faces.el/org-link-comment-face (added face).
>From da325f2298662dd9e191b22bdc36b0a8c8007a69 Mon Sep 17 00:00:00 2001 From: pavodive <[email protected]> Date: Mon, 11 May 2026 19:22:15 -0500 Subject: [PATCH] lisp/org.el: Add an overlay to distinctly show links in comments * org-el (org-activate-links): Added an overlay to the visible part of the link in a comment line, so it shows distinctly. * org-faces.el (org-link-comment-face): Created a new face used to display links when they are in commented lines. TINYCHANGE Reported-by: "Max Nikulin" <[email protected]> Link: https://list.orgmode.org/orgmode/[email protected]/ --- lisp/org-faces.el | 8 ++++++++ lisp/org.el | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/lisp/org-faces.el b/lisp/org-faces.el index b0f5ef9d7..056cf622e 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -183,6 +183,14 @@ set the properties in the `org-column' face. For example, set "Face for links." :group 'org-faces) +(defface org-link-comment-face + '((t :inherit (org-link))) + "Face for Org links that appear inside comment lines. +Inherits from both `org-link' and `font-lock-comment-face' so the +link remains visually distinct from regular links while still +signaling that it lives in commented-out text." + :group 'org-faces) + (defface org-footnote '((((class color) (background light)) (:foreground "Purple" :underline t)) (((class color) (background dark)) (:foreground "Cyan" :underline t)) diff --git a/lisp/org.el b/lisp/org.el index cb36497f4..879f187f9 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5560,6 +5560,7 @@ prompted for." (defun org-activate-links (limit) "Add link properties to links. This includes angle, plain, and bracket links." + (remove-overlays (point) limit 'org-link-comment t) (catch :exit (while (re-search-forward org-link-any-re limit t) (let* ((start (match-beginning 0)) @@ -5628,6 +5629,12 @@ This includes angle, plain, and bracket links." (let ((f (org-link-get-parameter type :activate-func))) (when (functionp f) (funcall f start end path (eq style 'bracket)))) + ;; If the link is on a comment line, put an overlay on the + ;; visible part so it displays distinctly. + (when (save-excursion (goto-char start) (org-at-comment-p)) + (let ((ov (make-overlay visible-start visible-end))) + (overlay-put ov 'face 'org-link-comment-face) + (overlay-put ov 'org-link-comment t))) (throw :exit t)) ;signal success ;; Not a real link, move forward one char and repeat the search. (goto-char (1+ (match-beginning 0)))))) -- 2.34.1
-- PavoDive
