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)))) :flag flag))))
;;;###autoload ;;;###autoload
(defun +org-link--doom-module-link-face-fn (module-path) (defun +org-link--var-link-activate-fn (start end var _bracketed-p)
(cl-destructuring-bind (&key category module flag) (when buffer-read-only
(+org-link--read-module-spec module-path) (add-text-properties
(if (doom-module-locate-path category module) start end
`(:inherit org-priority (list 'display
:weight bold) (concat
'error))) #("" 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 ;;;###autoload
(defun +org-link-follow-doom-module-fn (module-path _prefixarg) (defun +org-link--fn-link-activate-fn (start end fn _bracketed-p)
"TODO" (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) (cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path) (+org-link--read-module-spec module-path)
(when category (when category
@ -124,6 +163,68 @@ exist, and `org-link' otherwise."
(org-show-entry) (org-show-entry)
(recenter))))) (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 ;;;###autoload
(defun +org-link-follow-doom-package-fn (pkg _prefixarg) (defun +org-link-follow-doom-package-fn (pkg _prefixarg)
"TODO" "TODO"

View file

@ -562,23 +562,28 @@ relative to `org-directory', unless it is an absolute path."
(org-link-set-parameters (org-link-set-parameters
"var" "var"
:follow (-call-interactively #'helpful-variable) :follow (-call-interactively #'helpful-variable)
:face '(font-lock-variable-name-face underline)) :activate-func #'+org-link--var-link-activate-fn
:face 'org-code)
(org-link-set-parameters (org-link-set-parameters
"fn" "fn"
:follow (-call-interactively #'helpful-callable) :follow (-call-interactively #'helpful-callable)
:face '(font-lock-function-name-face underline)) :activate-func #'+org-link--fn-link-activate-fn
:face 'org-code)
(org-link-set-parameters (org-link-set-parameters
"face" "face"
:follow (-call-interactively #'describe-face) :follow (-call-interactively #'describe-face)
:activate-func #'+org-link--face-link-activate-face
:face '(font-lock-type-face underline)) :face '(font-lock-type-face underline))
(org-link-set-parameters (org-link-set-parameters
"doom-package" "doom-package"
:follow #'+org-link-follow-doom-package-fn :follow #'+org-link-follow-doom-package-fn
:activate-func #'+org-link--doom-package-link-activate-fn
:face (lambda (_) '(:inherit org-priority :slant italic)) :face (lambda (_) '(:inherit org-priority :slant italic))
:eldoc (-eldoc-fn "Doom package" 'org-priority)) :eldoc (-eldoc-fn "Doom package" 'org-priority))
(org-link-set-parameters (org-link-set-parameters
"doom-module" "doom-module"
:follow #'+org-link-follow-doom-module-fn :follow #'+org-link-follow-doom-module-fn
:activate-func #'+org-link--doom-module-link-activate-fn
:face #'+org-link--doom-module-link-face-fn :face #'+org-link--doom-module-link-face-fn
:eldoc (-eldoc-fn "Doom module" 'org-priority)) :eldoc (-eldoc-fn "Doom module" 'org-priority))
(org-link-set-parameters (org-link-set-parameters