From c1361c0ede6262d14f8d6c19564ddbbc37c22d14 Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 4 Oct 2022 00:29:43 +0800 Subject: [PATCH] feat(org): add some :help-echo for some links Also use the :help-echo for eldoc. --- modules/lang/org/autoload/org-link.el | 61 +++++++++++++++++++++++++++ modules/lang/org/config.el | 6 +-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/modules/lang/org/autoload/org-link.el b/modules/lang/org/autoload/org-link.el index d5ed8aed1..4e38288b6 100644 --- a/modules/lang/org/autoload/org-link.el +++ b/modules/lang/org/autoload/org-link.el @@ -250,6 +250,67 @@ exist, and `org-link' otherwise." executable 'face (if found 'org-verbatim 'default)))))))) +;; +;;; Help-echo / eldoc + +(defadvice! doom-docs--display-docs-link-in-eldoc-a (&rest _) + "Display help for doom-*: links in minibuffer when cursor/mouse is over it." + :before-until #'org-eldoc-documentation-function + (and (bound-and-true-p doom-docs-mode) + (eq (get-text-property (point) 'help-echo) + #'+org-link-doom--help-echo-from-textprop) + (+org-link-doom--help-echo-from-textprop nil (current-buffer) (point)))) + +(defvar +org-link-doom--help-echo-cache nil) + +(defun +org-link-doom--help-echo-from-textprop (_window object pos) + (let ((link (with-current-buffer object + (save-excursion (goto-char pos) (org-element-context))))) + (if (eq (car +org-link-doom--help-echo-cache) + (org-element-property :begin link)) + (cdr +org-link-doom--help-echo-cache) + (cdr (setq +org-link-doom--help-echo-cache + (cons (org-element-property :begin link) + (+org-link-doom--help-string link))))))) + +(defun +org-link-doom--help-string (link) + (if (not buffer-read-only) + (format "LINK: %s" (org-element-property :raw-link link)) + (pcase (org-element-property :type link) + ("doom-package" + (concat + (propertize "Emacs package " 'face 'bold) + (propertize (org-element-property :path link) 'face 'font-lock-keyword-face) + ", currently " + (cond + ((featurep (intern-soft (org-element-property :path link))) + (propertize "installed and loaded" 'face 'success)) + ((locate-library (org-element-property :path link)) + (propertize "installed but not loaded" 'face 'warning)) + (t (propertize "not installed" 'face 'error ))))) + ("doom-module" + (concat + (propertize "Doom module " 'face 'bold) + (propertize (org-element-property :path link) 'face 'font-lock-keyword-face) + ", currently " + (cl-destructuring-bind (&key category module flag) + (+org-link--read-module-spec (org-element-property :path link)) + (cond + ((doom-module-p category module) + (propertize "enabled" 'face 'success)) + ((and category (doom-module-locate-path category module)) + (propertize "disabled" 'face 'error)) + (t (propertize "unknown" 'face '(bold error))))))) + ("doom-executable" + (concat + (propertize "System executable " 'face 'bold) + (propertize (org-element-property :path link) 'face 'font-lock-keyword-face) + ", " + (if (executable-find (org-element-property :path link)) + (propertize "found" 'face 'success) + (propertize "not found" 'face 'error)) + " on PATH"))))) + ;; ;;; Image data functions (for custom inline images) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index b644f2be3..e81db7175 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -579,17 +579,17 @@ relative to `org-directory', unless it is an absolute path." :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)) + :help-echo #'+org-link-doom--help-echo-from-textprop) (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)) + :help-echo #'+org-link-doom--help-echo-from-textprop) (org-link-set-parameters "doom-executable" :activate-func #'+org-link--doom-executable-link-activate-fn - ;; :help-echo #'doom-docs--help-echo-from-textprop + :help-echo #'+org-link-doom--help-echo-from-textprop :face 'org-verbatim) (org-link-set-parameters "doom-ref"