feat(org): fancy docs links with activation fns

This commit is contained in:
TEC 2022-10-03 23:18:58 +08:00 committed by Henrik Lissner
parent eed6d90586
commit c26d64c9b9
2 changed files with 117 additions and 11 deletions

View file

@ -94,17 +94,56 @@ exist, and `org-link' otherwise."
:flag flag))))
;;;###autoload
(defun +org-link--doom-module-link-face-fn (module-path)
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(if (doom-module-locate-path category module)
`(:inherit org-priority
:weight bold)
'error)))
(defun +org-link--var-link-activate-fn (start end var _bracketed-p)
(when buffer-read-only
(add-text-properties
start end
(list 'display
(concat
#("" 0 1
(rear-nonsticky
t display (raise 0.05)
face (:family "github-octicons"
:inherit font-lock-variable-name-face
:height 0.8
:box (:line-width 1 :style none)))
1 2 (face (:height 0.2)))
var)))))
;;;###autoload
(defun +org-link-follow-doom-module-fn (module-path _prefixarg)
"TODO"
(defun +org-link--fn-link-activate-fn (start end fn _bracketed-p)
(when buffer-read-only
(add-text-properties
start end
(list 'display
(concat
#("λ " 0 1 (face (:inherit font-lock-function-name-face
:box (:line-width 1 :style none)
:height 0.9))
1 2 (face (:height 0.2)))
fn)))))
;;;###autoload
(defun +org-link--face-link-activate-face (start end face _bracketed-p)
(when buffer-read-only
(add-text-properties
start end
(list 'display
(concat
(propertize
""
'rear-nonsticky t
'display '(raise -0.02)
'face (list '(:family "file-icons" :height 1.0)
(if (facep (intern face))
(intern face)
'default)
'(:underline nil)))
#(" " 0 1 (face (:underline nil)))
face)))))
;;;###autoload
(defun +org-link--doom-module-link-follow-fn (module-path _arg)
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(when category
@ -124,6 +163,68 @@ exist, and `org-link' otherwise."
(org-show-entry)
(recenter)))))
;;;###autoload
(defun +org-link--doom-module-link-face-fn (module-path)
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(if (doom-module-locate-path category module)
`(:inherit org-priority
:weight bold)
'error)))
;;;###autoload
(defun +org-link--doom-module-link-activate-fn (start end module-path _bracketed-p)
(when buffer-read-only
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(let ((overall-face
(cond
((doom-module-p category module flag)
'((:underline nil) org-link org-block bold))
((and category (doom-module-locate-path category module))
'(shadow org-block bold))
(t '((:strike-through t) error org-block))))
(icon-face
(if (doom-module-p category module flag) 'success 'error)))
(add-text-properties
start end
(list 'face overall-face
'display
(concat
(propertize
""
'rear-nonsticky t
'display '(raise -0.02)
'face `(:inherit ,icon-face
:family "FontAwesome"
:height 1.0))
module-path)))))))
;;;###autoload
(defun +org-link--doom-package-link-activate-fn (start end package _bracketed-p)
(when buffer-read-only
(let ((overall-face
(if (locate-library package)
'((:underline nil) org-link org-block italic)
'(shadow org-block italic)))
(pkg-face
(cond
((featurep (intern package)) 'success)
((locate-library package) 'warning)
(t 'error))))
(add-text-properties
start end
(list 'face overall-face
'display
(concat
(propertize
"\uf0c4" ; Octicon package symbol
'rear-nonsticky t
'display '(raise -0.02)
'face `(:family "github-octicons" :height 1.0
:inherit ,pkg-face))
" " package))))))
;;;###autoload
(defun +org-link-follow-doom-package-fn (pkg _prefixarg)
"TODO"