From 733f857199482869cbca8e2424e7eaa14b9ab250 Mon Sep 17 00:00:00 2001 From: TEC Date: Sun, 19 Feb 2023 00:23:31 +0800 Subject: [PATCH] feat(org): new "cmd" link type --- modules/lang/org/autoload/org-link.el | 26 ++++++++++++++++++++++++++ modules/lang/org/config.el | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/modules/lang/org/autoload/org-link.el b/modules/lang/org/autoload/org-link.el index 5cd6f3a51..0fb8464b9 100644 --- a/modules/lang/org/autoload/org-link.el +++ b/modules/lang/org/autoload/org-link.el @@ -142,6 +142,25 @@ exist, and `org-link' otherwise." #(" " 0 1 (face (:underline nil))) face))))) +(defun +org-link--command-keys (command) + "Convert command reference TEXT to key binding representation." + (let* ((cmd-prefix (mapcar #'reverse + (split-string (reverse command) " "))) + (cmd (intern-soft (car cmd-prefix))) + (prefix (and (cdr cmd-prefix) + (string-join (reverse (cdr cmd-prefix)) " "))) + (key-binding (where-is-internal cmd nil t)) + (key-text (if key-binding + (key-description key-binding) + (format "M-x %s" cmd)))) + (concat prefix (and prefix " ") key-text))) + +;;;###autoload +(defun +org-link--command-link-activate-command (start end command _bracketed-p) + (when buffer-read-only + (add-text-properties + start end (list 'display (+org-link--command-keys command))))) + ;;;###autoload (defun +org-link--doom-module-link-follow-fn (module-path _arg) (cl-destructuring-bind (&key category module flag) @@ -282,6 +301,13 @@ exist, and `org-link' otherwise." "The key sequence " (propertize (+org-link--describe-kbd (org-element-property :path link)) 'face 'help-key-binding))) + ("cmd" + (concat + "The command " + (propertize (org-element-property :path link) 'face 'font-lock-function-name-face) + " can be invoked with the key sequence " + (propertize (+org-link--command-keys (org-element-property :path link)) + 'face 'help-key-binding))) ("doom-package" (concat (propertize "Emacs package " 'face 'bold) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 27f6fff2e..46d49d419 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -559,6 +559,12 @@ relative to `org-directory', unless it is an absolute path." :follow (-call-interactively #'describe-face) :activate-func #'+org-link--face-link-activate-face :face '(font-lock-type-face underline)) + (org-link-set-parameters + "cmd" + :follow (-call-interactively #'describe-command) + :activate-func #'+org-link--command-link-activate-command + :face 'help-key-binding + :help-echo #'+org-link-doom--help-echo-from-textprop) (org-link-set-parameters "doom-package" :follow #'+org-link-follow-doom-package-fn