feat(org): fancy docs links with activation fns
This commit is contained in:
parent
eed6d90586
commit
c26d64c9b9
2 changed files with 117 additions and 11 deletions
|
@ -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"
|
||||
|
|
|
@ -562,23 +562,28 @@ relative to `org-directory', unless it is an absolute path."
|
|||
(org-link-set-parameters
|
||||
"var"
|
||||
: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
|
||||
"fn"
|
||||
: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
|
||||
"face"
|
||||
:follow (-call-interactively #'describe-face)
|
||||
:activate-func #'+org-link--face-link-activate-face
|
||||
:face '(font-lock-type-face underline))
|
||||
(org-link-set-parameters
|
||||
"doom-package"
|
||||
:follow #'+org-link-follow-doom-package-fn
|
||||
:activate-func #'+org-link--doom-package-link-activate-fn
|
||||
:face (lambda (_) '(:inherit org-priority :slant italic))
|
||||
:eldoc (-eldoc-fn "Doom package" 'org-priority))
|
||||
(org-link-set-parameters
|
||||
"doom-module"
|
||||
:follow #'+org-link-follow-doom-module-fn
|
||||
:activate-func #'+org-link--doom-module-link-activate-fn
|
||||
:face #'+org-link--doom-module-link-face-fn
|
||||
:eldoc (-eldoc-fn "Doom module" 'org-priority))
|
||||
(org-link-set-parameters
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue