refactor(org): move doom-docs link defs to :lang org

Where they will be further generalized, later.

This also prevents an issue where org was loaded while the profile init
files are generated, which caused a warning about org-loaddefs which
introduces a noticable delay.
This commit is contained in:
Henrik Lissner 2022-09-16 03:10:36 +02:00
parent 511f0ca38f
commit ab9896c526
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
3 changed files with 198 additions and 235 deletions

View file

@ -40,6 +40,90 @@ exist, and `org-link' otherwise."
'error)))
(plist-put plist :requires nil))))
;;;###autoload
(defun +org-link-read-desc-at-point (&optional default context)
"TODO"
(if (and (stringp default) (not (string-empty-p default)))
(string-trim default)
(if-let* ((context (or context (org-element-context)))
(context (org-element-lineage context '(link) t))
(beg (org-element-property :contents-begin context))
(end (org-element-property :contents-end context)))
(unless (= beg end)
(replace-regexp-in-string
"[ \n]+" " " (string-trim (buffer-substring-no-properties beg end)))))))
;;;###autoload
(defun +org-link-read-kbd-at-point (&optional default context)
"TODO"
(+org-link--describe-kbd
(+org-link-read-desc-at-point default context)))
(defun +org-link--describe-kbd (keystr)
(dolist (key `(("<leader>" . ,doom-leader-key)
("<localleader>" . ,doom-localleader-key)
("<prefix>" . ,(if (bound-and-true-p evil-mode)
(concat doom-leader-key " u")
"C-u"))
("<help>" . ,(if (bound-and-true-p evil-mode)
(concat doom-leader-key " h")
"C-h"))
("\\<M-" . "alt-")
("\\<S-" . "shift-")
("\\<s-" . "super-")
("\\<C-" . "ctrl-")))
(setq keystr
(replace-regexp-in-string (car key) (cdr key)
keystr t t)))
keystr)
(defun +org-link--read-module-link (link)
(cl-destructuring-bind (category &optional module flag)
(let ((desc (+org-link-read-desc-at-point link)))
(if (string-prefix-p "+" (string-trim-left desc))
(list nil nil (intern desc))
(mapcar #'intern (split-string desc " " nil))))
(list :category category
:module module
:flag flag)))
;;;###autoload
(defun +org-link--doom-module-link-face-fn (link)
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-link link)
(if (doom-module-locate-path category module)
`(:inherit org-priority
:weight bold)
'error)))
;;;###autoload
(defun +org-link-follow-doom-module-fn (link)
"TODO"
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-link link)
(when category
(let ((doom-modules-dirs (list doom-modules-dir)))
(if-let* ((path (doom-module-locate-path category module))
(path (or (car (doom-glob path "README.org"))
path)))
(find-file path)
(user-error "Can't find Doom module '%s'" link))))
(when flag
(goto-char (point-min))
(when (and (re-search-forward "^\\*+ \\(?:TODO \\)?Module flags")
(re-search-forward (format "^\\s-*- \\+%s ::[ \n]"
(substring (symbol-name flag) 1))
(save-excursion (org-get-next-sibling)
(point))))
(org-show-entry)
(recenter)))))
;;;###autoload
(defun +org-link-follow-doom-package-fn (link)
"TODO"
(doom/describe-package
(intern-soft
(+org-link-read-desc-at-point link))))
;;
;;; Image data functions (for custom inline images)