Skip to main content
Just hide two of the angles at each end of the link text.
Source Link
Tobias
  • 33.7k
  • 1
  • 38
  • 78

The following version addresses the wishes from Kartik Shenoy's first comment, i.e.: Just hide two of the angles at each end of the link text:

(defcustom org-hidden-links-additional-re "\\(<<\\)[[:alnum:]]+\\(>>\\)"
  "Regular expression that matches strings where the invisible-property of the sub-matches 1 and 2 is set to org-link."
  :type '(choice (const :tag "Off" nil) regexp)
  :group 'org-link)
(make-variable-buffer-local 'org-hidden-links-additional-re)

(defun org-activate-hidden-links-additional (limit)
  "Put invisible-property org-link on strings matching `org-hide-links-additional-re'."
  (if org-hidden-links-additional-re
      (re-search-forward org-hidden-links-additional-re limit t)
    (goto-char limit)
    nil))

(defun org-hidden-links-hook-function ()
  "Add rule for `org-activate-hidden-links-additional' to `org-font-lock-extra-keywords'.
You can include this function in `org-font-lock-set-keywords-hook'."
  (add-to-list 'org-font-lock-extra-keywords
                              '(org-activate-hidden-links-additional
                                (1 '(face org-target invisible org-link))
                (2 '(face org-target invisible org-link)))))

(add-hook 'org-font-lock-set-keywords-hook #'org-hidden-links-hook-function)

The following version addresses the wishes from Kartik Shenoy's first comment, i.e.: Just hide two of the angles at each end of the link text:

(defcustom org-hidden-links-additional-re "\\(<<\\)[[:alnum:]]+\\(>>\\)"
  "Regular expression that matches strings where the invisible-property of the sub-matches 1 and 2 is set to org-link."
  :type '(choice (const :tag "Off" nil) regexp)
  :group 'org-link)
(make-variable-buffer-local 'org-hidden-links-additional-re)

(defun org-activate-hidden-links-additional (limit)
  "Put invisible-property org-link on strings matching `org-hide-links-additional-re'."
  (if org-hidden-links-additional-re
      (re-search-forward org-hidden-links-additional-re limit t)
    (goto-char limit)
    nil))

(defun org-hidden-links-hook-function ()
  "Add rule for `org-activate-hidden-links-additional' to `org-font-lock-extra-keywords'.
You can include this function in `org-font-lock-set-keywords-hook'."
  (add-to-list 'org-font-lock-extra-keywords
                              '(org-activate-hidden-links-additional
                                (1 '(face org-target invisible org-link))
                (2 '(face org-target invisible org-link)))))

(add-hook 'org-font-lock-set-keywords-hook #'org-hidden-links-hook-function)
Source Link
Tobias
  • 33.7k
  • 1
  • 38
  • 78

Paste the following into your init files. This gives you a new customization option org-hidden-links-additional-re. You can switch this option off or parameterize it with a regular expression. The strings matching this regular expression in an org-buffer are hidden when "descriptive links" are activated (menu item Org->Hyperlinks->Descriptive Links). The default is <<[<]?[[:alnum:]]>>[>]? which hides link targets. This variable is buffer local. You can set it in the file-local variables.

(defcustom org-hidden-links-additional-re "<<[<]?[[:alnum:]]+>>[>]?"
  "Regular expression that matches strings where the invisible-property is set to org-link."
  :type '(choice (const :tag "Off" nil) regexp)
  :group 'org-link)
(make-variable-buffer-local 'org-hidden-links-additional-re)

(defun org-activate-hidden-links-additional (limit)
  "Put invisible-property org-link on strings matching `org-hide-links-additional-re'."
  (if org-hidden-links-additional-re
      (re-search-forward org-hidden-links-additional-re limit t)
    (goto-char limit)
    nil))

(add-hook 'org-font-lock-set-keywords-hook (lambda ()
                         (add-to-list 'org-font-lock-extra-keywords
                              '(org-activate-hidden-links-additional
                                (0 '(face org-target invisible org-link))))))