¿Cómo mostrar superposición como este screencast?


Respuestas:


8

De hecho, logra ese comportamiento usando superposiciones. Específicamente, utiliza la 'after-stringpropiedad para mostrar la documentación (ver: Propiedades de superposición ).

Si examina la función company-coq--show-definition-overlay-at-point(por ejemplo, vía M-x find-function), puede ver exactamente cómo se crea:

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

Se mantiene una referencia a la superposición company-coq-definition-overlaypara facilitar la eliminación posterior de la superposición:

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

Con (overlay-put OVERLAY 'after-string STR)no tiene fontify como en screencast.
— stardiviner

@stardiviner, ¿te preguntas sobre personajes / colores / estilos específicos? Se podría utilizar el edebug para examinar la cadena ins-stren company-coq--show-definition-overlay-at-point. Caras y estilos específicos existirán como propiedades de texto en esa cadena. Propiedades del texto: Propiedades especiales es una referencia útil para decodificar esas propiedades.
— 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)

Creé un repositorio para esto, https://github.com/stardiviner/inline-docs.el y un módulo que utilizo inline-docs.elpara eldoc. https://github.com/stardiviner/eldoc-overlay-mode .


Sería bueno tener eso como un módulo de propósito general, de modo que pueda usarse no solo para eldoc sino también para "modeline quickinfo".
— theldoria

Ya veo, crearé un modo general para esto, luego crearé un modo separado para eldoc.
— stardiviner
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.