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.

1
  • 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? Commented Jan 10, 2017 at 6:59

1 Answer 1

4
+50

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)
10
  • Can you add a face for this overlay? So it can has different background color with 'default face. Thanks. Commented Jan 14, 2017 at 3:00
  • Sure, I added a line to the display function to set a face.
    – justbur
    Commented Jan 14, 2017 at 15:07
  • I added your added line code, but it does not work. And I use your code to created a minor mode github.com/stardiviner/eldoc-overlay-mode Commented Jan 14, 2017 at 15:28
  • Did you change the face? I set it to default but you'll have to change it to see a difference.
    – justbur
    Commented Jan 14, 2017 at 15:38
  • Yes, I changed face. I also define a face for it. Check out my upper link repo's develop branch. Commented Jan 14, 2017 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.