假设我在缓冲区中有以下文本
CMM-3: Description
CMM-91: Description 2
Run Code Online (Sandbox Code Playgroud)
我希望CMM-XX成为调用自定义功能的可点击区域
(defun jira-ticket-view (&optional jira-ticket)
"Open Jira Ticket Inside Emacs"
(interactive)
....)
Run Code Online (Sandbox Code Playgroud)
创建一个新的键盘映射,绑定mouse-1
到要调用的函数,然后将键盘映射作为文本属性添加到链接文本。设置mouse-face
为highlight
并添加help-echo
以增加用户友好性-当用户将鼠标指针悬停在文本上方时,这些设置才会生效。
(defun my-function ()
(interactive)
(message "You've clicked the text!"))
(let ((map (make-sparse-keymap)))
(define-key map [mouse-1] 'my-function)
(insert "Foo: "
(propertize "bar" 'keymap map 'mouse-face 'highlight 'help-echo "Click here!")
"\n"))
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参见elisp参考手册中的“可单击文本 ”部分。