don't pre-pend indentation spaces.
[eldoc-overlay.git] / eldoc-overlay-mode.el
blob18610de6c65027566dea0f02e6331bbda371ed4b
1 ;;; eldoc-overlay-mode.el --- Display eldoc with contextual documentation overlay.
3 ;; Author: stardiviner <numbchild@gmail.com>
4 ;; Keywords: eldoc overlay
5 ;; URL: https://github.com/stardiviner/eldoc-overlay-mode
6 ;; Created: 14th Jan 2017
7 ;; Version: 0.0.1
8 ;; Package-Requires: ((emacs "25.1"))
10 ;;; Commentary:
14 ;;; Code:
15 ;;; ----------------------------------------------------------------------------
17 (defvar eldoc-overlay--overlay nil)
19 (defface eldoc-overlay-face
20 '((t (:inherit italic)))
21 "Face for eldoc-overlay-mode."
22 :group 'eldoc)
24 (defun eldoc-overlay--clear-overlay ()
25 "Clear eldoc-overlay overlays."
26 (when (overlayp eldoc-overlay--overlay)
27 (delete-overlay eldoc-overlay--overlay))
28 (remove-hook 'post-command-hook 'eldoc-overlay--clear-overlay))
30 (defun eldoc-overlay--string-display-next-line (string)
31 "Overwrite contents of next line with STRING until next command."
32 (let* ((indent-spaces (make-string (- (current-indentation) 2) ?\s))
33 (str (concat (propertize "➜ " 'face 'font-lock-doc-face)
34 (copy-sequence string) ; original eldoc string with format
35 "\n"))
36 start-pos end-pos)
37 (unwind-protect
38 (save-excursion
39 (eldoc-overlay--clear-overlay)
40 (forward-line)
41 (setq start-pos (point))
42 (end-of-line)
43 (setq end-pos (point))
44 (setq eldoc-overlay--overlay (make-overlay start-pos end-pos (current-buffer)))
45 ;; Change the face
46 ;; (overlay-put eldoc-overlay--overlay 'face 'eldoc-overlay-face)
47 ;; Hide full line
48 ;; (overlay-put eldoc-overlay--overlay 'display "")
49 ;; (overlay-put eldoc-overlay--overlay 'display :height 120)
50 ;; pre-pend indentation spaces
51 ;; (overlay-put eldoc-overlay--overlay 'line-prefix indent-spaces)
52 ;; auto delete overlay with property 'evaporate
53 (overlay-put eldoc-overlay--overlay 'evaporate t)
54 ;; Display message
55 (overlay-put eldoc-overlay--overlay 'before-string str))
56 (add-hook 'post-command-hook 'eldoc-overlay--clear-overlay))))
58 (defun eldoc-overlay-display-message-momentary (format-string &rest args)
59 "Display eldoc message FORMAT-STRING near point with extra ARGS."
60 (when format-string
61 (eldoc-overlay--string-display-next-line
62 (apply 'format format-string args))))
64 (defvar eldoc-overlay-mode-map
65 (let ((map (make-sparse-keymap)))
66 map))
68 ;;;###autoload
69 (define-minor-mode eldoc-overlay-mode
70 "Minor mode for displaying eldoc with contextual documentation overlay."
71 :init-value t
72 :lighter " ElDoc overlay"
73 :keymap eldoc-overlay-mode-map
74 :global t
75 (if eldoc-overlay-mode
76 (setq eldoc-message-function #'eldoc-overlay-display-message-momentary)
77 (setq eldoc-message-function #'eldoc-minibuffer-message)
81 ;;; ----------------------------------------------------------------------------
83 (provide 'eldoc-overlay-mode)
85 ;;; eldoc-overlay-mode.el ends here