5

I have the following code to replace default eldoc display function:

(defun my-eldoc-display-message-momentary (format-string &rest args)
    "Display eldoc message near point."
    (when format-string
      ;; (pos-tip-show (apply 'format format-string args))
      (momentary-string-display
       (apply 'format format-string args)
       (save-excursion (forward-line) (point))
       )
      ))

(setq eldoc-message-function #'my-eldoc-display-message-momentary)

But it does not work smoothly.

  • it display slowly
  • the exit-char for momentary-string-display should be excepted in most programming code inputting (not SPC, not [a-zA-Z], not [*,-+=!] etc)

Hope someone can improve it.

stardiviner
  • 1,888
  • 26
  • 45
  • 1
    Would you mind to define the slowness? I've tested the code above but didn't see the slowness, meaning that `pos-tip-show` version and `momentary-string-display` version displays in the same timing on my system, as far as I can tell. Would you also tell me about excepted `exit-char`? What behavior are you looking for? – Yasushi Shoji Jan 10 '17 at 06:59

1 Answers1

4

As with the comment, pos-tip-show works fine for me too.

I did hack together a better (but not perfect) version of the momentary-string-display version. I just rewrote the display function so that it deleted the overlay passively through a hook instead of waiting for an exit-char, which doesn't seem appropriate for what you are trying to do. The display function I put together temporarily overwrites the next line of the buffer with the message. See if you like it.

(defvar my-display-overlay nil)

(defun my-delete-string-display ()
  (when (overlayp my-display-overlay)
    (delete-overlay my-display-overlay))
  (remove-hook 'post-command-hook 'my-delete-string-display))

(defun my-string-display-next-line (string)
  "Overwrite contents of next line with STRING until next command."
  (let ((str (concat
               (make-string (1+ (current-indentation)) 32)
               (propertize (copy-sequence string) 'face '(:background "#3e4451" :extend t))))
         (start-pos nil)
         (end-pos nil))
    (unwind-protect
      (save-excursion
        (my-delete-string-display)
        (forward-line)
        (setq start-pos (point))
        (end-of-line)
        (setq end-pos (point))
        (setq my-display-overlay (make-overlay start-pos end-pos))
        ;; Hide full line
        (overlay-put my-display-overlay 'display "")
        ;; Display message
        (overlay-put my-display-overlay 'before-string str))
      (add-hook 'post-command-hook 'my-delete-string-display))))

(defun my-eldoc-display-message-momentary (format-string &rest args)
  "Display eldoc message near point."
  (when format-string
    (my-string-display-next-line (apply 'format format-string args))))

(setq eldoc-message-function #'my-eldoc-display-message-momentary)
ideasman42
  • 8,375
  • 1
  • 28
  • 105
justbur
  • 1,500
  • 8
  • 8