Created
June 11, 2023 12:54
-
-
Save yewton/eecc7fbb157c57159ce6cc785df0ea73 to your computer and use it in GitHub Desktop.
Org Mode でリンク種別に応じたプレフィクスを表示する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'ol) | |
(defconst my-org-link-prefixes '(("id" . "🦄") | |
("roam" . "🦄") | |
("attachment" . "📎") | |
("file" . "💾") | |
("file+sys" . "💾") | |
("file+emacs" . "🗒") | |
("shell" . "💻") | |
("https" . "🌐") | |
("http" . "🌐") | |
("help" . "❓") | |
("info" . "ℹ") | |
("elisp" . "⚡"))) | |
(defun my-org-link-on-modification (ov changed _start _end &optional _len) | |
(when changed (delete-overlay ov))) | |
(defun my-org-link-activate (type start end bracketp) | |
(remove-overlays start end 'org-link-prefix t) | |
(when (and org-link-descriptive bracketp) | |
(let* ((prefix (or (when-let ((found (cdr-safe (assoc-string type my-org-link-prefixes)))) | |
(format "%s " found)) | |
(format "%s:" (upcase type)))) | |
(ov (make-overlay start end)) | |
(props `((org-link-prefix . t) | |
(before-string . ,prefix) | |
(evaporate . t) | |
(modification-hooks . ,(list #'my-org-link-on-modification)) | |
(insert-in-front-hooks . ,(list #'my-org-link-on-modification))))) | |
(dolist (prop props) | |
(overlay-put ov (car prop) (cdr prop)))))) | |
(dolist (prefix my-org-link-prefixes) | |
(let ((type (car prefix))) | |
(org-link-set-parameters type | |
:activate-func | |
`(lambda (start end _path bracketp) | |
(my-org-link-activate ,type start end bracketp))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment