如何以这种截屏方式显示叠加图?


Answers:


8

实际上,它确实使用叠加来完成该行为。具体来说,它使用'after-string属性显示文档(请参见:覆盖属性)。

如果您检查函数company-coq--show-definition-overlay-at-point(例如:via M-x find-function),则可以确切地看到其创建方式:

(setq company-coq-definition-overlay (make-overlay ins-pos ins-pos))
(overlay-put company-coq-definition-overlay 'after-string ins-str)

保留了company-coq-definition-overlay对叠加层的引用,以方便以后删除叠加层:

(delete-overlay company-coq-definition-overlay)
(setq company-coq-definition-overlay nil)

(overlay-put OVERLAY 'after-string STR)没有截屏中的字体一样。
stardiviner

@stardiviner您是否想知道特定的字符/颜色/样式?您可以使用edebug检查字符串ins-strcompany-coq--show-definition-overlay-at-point。特定的面孔和样式将作为该字符串中的文本属性存在。 文本属性:特殊属性是解码这些属性的有用参考。
ebpa

1
(defvar inline-docs-overlay nil)

(defgroup inline-docs nil
  "Show inline contextual docs in Emacs."
  :group 'docs)

(defcustom inline-docs-border-symbol ?―
  "Specify symbol for inline-docs border."
  :group 'inline-docs)

(defcustom inline-docs-prefix-symbol ?\s
  "Specify symbol for inline-docs prefix."
  :group 'inline-docs)

(defcustom inline-docs-indicator-symbol "➜"
  "Specify symbol for inline-docs indicator."
  :group 'inline-docs)

(defface inline-docs-face
  '((t (:inherit italic)))
  "Face for `inline-docs-mode'."
  :group 'inline-docs)

(defface inline-docs-border-face
  '((t (:inherit font-lock-doc-face)))
  "Face for inline docs border lines."
  :group 'inline-docs)

(defface inline-docs-prefix-face
  '((t (:inherit default)))
  "Face for inline docs prefix."
  :group 'inline-docs)

(defface inline-docs-indicator-face
  '((t (:inherit font-lock-doc-face)))
  "Face for inline docs indicator."
  :group 'inline-docs)

(defun inline-docs--clear-overlay ()
  "Clear inline-docs overlays."
  (when (overlayp inline-docs-overlay)
    (delete-overlay inline-docs-overlay))
  (remove-hook 'post-command-hook 'inline-docs--clear-overlay))

(defun inline-docs--string-display-next-line (string apply-face)
  "Show STRING contents below point line until next command with APPLY-FACE."
  (let* ((border-line (make-string (window-body-width) inline-docs-border-symbol))
         (prefix (make-string
                  (if (= (current-indentation) 0) ; fix (wrong-type-argument wholenump -1) when current indentation is 0 minus 1 will caused wholenump exception.
                      (current-indentation)
                    (- (current-indentation) 1))
                  inline-docs-prefix-symbol))
         (str (concat (propertize border-line
                                  'face 'inline-docs-border-face)
                      "\n"
                      prefix
                      (propertize (concat inline-docs-indicator-symbol " ")
                                  'face 'inline-docs-indicator-face)
                      (copy-sequence string) ; original eldoc string with format.
                      "\n"
                      (propertize border-line
                                  'face 'inline-docs-border-face)
                      "\n"
                      ))
         start-pos end-pos)
    (unwind-protect
        (save-excursion
          (inline-docs--clear-overlay)
          (forward-line)
          (setq start-pos (point))
          (end-of-line)
          (setq end-pos (point))
          (setq inline-docs-overlay (make-overlay start-pos end-pos (current-buffer)))
          ;; change the face
          (if apply-face
              (overlay-put inline-docs-overlay 'face 'inline-docs-face))
          ;; hide full line
          ;; (overlay-put inline-docs-overlay 'display "")
          ;; (overlay-put inline-docs-overlay 'display :height 20)
          ;; pre-pend indentation spaces
          ;; (overlay-put inline-docs-overlay 'line-prefix prefix)
          ;; auto delete overlay
          (overlay-put inline-docs-overlay 'evaporate t)
          ;; display message
          (overlay-put inline-docs-overlay 'before-string str))
      (add-hook 'post-command-hook 'inline-docs--clear-overlay))))

(defun inline-docs-display-docs-momentary (format-string &rest args)
  "Display inline docs FORMAT-STRING under point with extra ARGS."
  (when format-string
    (inline-docs--string-display-next-line
     (apply 'format format-string args)
     t)))

;;;###autoload
(defalias 'inline-docs 'inline-docs-display-docs-momentary)

我为此创建了 一个仓库,https://github.com/stardiviner/inline-docs.el以及一个inline-docs.el用于eldoc 的模块。 https://github.com/stardiviner/eldoc-overlay-mode


最好将它作为通用模块,这样它不仅可以用于eldoc,还可以用于其他“ modeline quickinfo”。
theldoria

我知道,我将为此创建一个常规模式,然后为eldoc创建一个单独的模式。
stardiviner
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.