我想在 Emacs 里调用一个包的函数来运行快捷指令,需要给快捷指令的 URL Scheme 传递参数。
想要获得的函数返回值
thing-at-point 'sentence
想要传递的参数
ACTION run-shortcut
NAME EmacsTranslate
INPUT text
TEXT thing-at-point 'sentence
包的函数(自带的文档说明)
Signature
(siri-shortcuts-browse-url &optional ACTION NAME INPUT TEXT QUERY)
Documentation
Browse a Shortcuts scheme URL ACTION.
If ACTION is nil, then the bare URL is used, which will navigate to
Shortcuts app's last state.
ACTION - one of "create-shortcut", "open-shortcut", "run-shortcut", "gallery" or "gallery/search".
NAME - Shortcut name, can be unescaped.
INPUT - The initial input into the shortcut.
There are two input options: a text string or the word clipboard.
When the INPUT value is a text string, that text is used.
When the input value is Clipboard, the contents of the clipboard are used.
TEXT - If INPUT is set to text, then value of TEXT is passed as input to the shortcut.
If INPUT is set to clipboard, then this parameter is ignored.
QUERY - determines the URL-encoded keywords to be searched in the Gallery.
它的定义
(defun siri-shortcuts-browse-url (&optional action name input text query)
(let ((scheme "shortcuts://")
(path (cond
((null action) "")
((string= action "create-shortcut") "create-shortcut")
((and (string= action "open-shortcut") name)
(concat "open-shortcut?name=" (url-encode-url name)))
((and (string= action "run-shortcut") name)
(concat "run-shortcut?name=" (url-encode-url name)
"&input=" input "&text=" (url-encode-url text)))
((string= action "gallery") "gallery")
((and (string= action "gallery/search") query)
(concat "gallery/search?query=" (url-encode-url query))))))
(browse-url (concat scheme path))))
问题已解决,效果见如下视频:
使用过程中可能会有快捷指令的临时窗口蹦出来,强迫症慎用。