首页 > 解决方案 > 在 Emacs 工具提示中呈现 HTML?

问题描述

我想在 Emacs 工具提示中显示带有粗体和斜体文本的 HTML。我正在尝试的解决方案是这样的:

(let ((html "regular <b>bold</b> regular <i>italic</i> regular\n")
      (bufname "* render-html-tmp*"))
  (with-current-buffer (get-buffer-create bufname)
    (erase-buffer)
    (insert html)
    (shr-render-region (point-min) (point-max))
    (tooltip-show (buffer-string))))

* render-html-tmp*缓冲区中,粗体和斜体文本正常显示,但在工具提示中,所有五个单词都是纯常规文本,没有粗体或斜体。更改 的值x-gtk-use-system-tooltips没有效果。

同时,当我走到* render-html-tmp*缓冲区的末尾并在那里执行(insert (buffer-string))时,或者将缓冲区内容复制到终止环并将其拉入新缓冲区时,粗体和斜体属性确实会正确显示在插入或拉出的文本中. 所以我的基本想法应该是正确的,而我正在试图弄清楚为什么我没有在工具提示中看到这些属性。

发生了什么,以及如何使粗体和斜体文本显示在工具提示中?

标签: emacstooltip

解决方案


tooltip-show覆盖传递给它的字符串的 face 属性,并用它自己的tooltip属性替换它:

      (x-show-tip (propertize text 'face 'tooltip)
              (selected-frame)
              params
              tooltip-hide-delay
              tooltip-x-offset
              tooltip-y-offset))
      ...

正如 OP 在评论中提到的那样,定义一个修改后的直接tooltip-show传递textx-show-tip而不是执行(propertize text ...)并从他的代码中调用它可以解决问题。


推荐阅读