fix (wrong-type-argument wholenump -1)
[eldoc-overlay.git] / eldoc-overlay-mode.el
blob7e0de50c256127d7471abee3f1108a2838735c05
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
33 (if (= (current-indentation) 0)
34 (current-indentation)
35 (- (current-indentation) 1))
36 ?\s))
37 (border-line (make-string (window-body-width) ?―))
38 (str (concat (propertize border-line 'face 'font-lock-doc-face)
39 "\n"
40 indent-spaces
41 (propertize "➜ " 'face 'font-lock-doc-face)
42 (copy-sequence string) ; original eldoc string with format
43 "\n"
44 (propertize border-line 'face 'font-lock-doc-face)
45 "\n"
47 start-pos end-pos)
48 (unwind-protect
49 (save-excursion
50 (eldoc-overlay--clear-overlay)
51 (forward-line)
52 (setq start-pos (point))
53 (end-of-line)
54 (setq end-pos (point))
55 (setq eldoc-overlay--overlay (make-overlay start-pos end-pos (current-buffer)))
56 ;; Change the face
57 ;; (overlay-put eldoc-overlay--overlay 'face 'eldoc-overlay-face)
58 ;; Hide full line
59 ;; (overlay-put eldoc-overlay--overlay 'display "")
60 ;; (overlay-put eldoc-overlay--overlay 'display :height 120)
61 ;; pre-pend indentation spaces
62 ;; (overlay-put eldoc-overlay--overlay 'line-prefix indent-spaces)
63 ;; auto delete overlay with property 'evaporate
64 (overlay-put eldoc-overlay--overlay 'evaporate t)
65 ;; Display message
66 (overlay-put eldoc-overlay--overlay 'before-string str))
67 (add-hook 'post-command-hook 'eldoc-overlay--clear-overlay))))
69 (defun eldoc-overlay-display-message-momentary (format-string &rest args)
70 "Display eldoc message FORMAT-STRING near point with extra ARGS."
71 (when format-string
72 (eldoc-overlay--string-display-next-line
73 (apply 'format format-string args))))
75 (defvar eldoc-overlay-mode-map
76 (let ((map (make-sparse-keymap)))
77 map))
79 ;;;###autoload
80 (define-minor-mode eldoc-overlay-mode
81 "Minor mode for displaying eldoc with contextual documentation overlay."
82 :init-value t
83 :lighter " ElDoc overlay"
84 :keymap eldoc-overlay-mode-map
85 :global t
86 (if eldoc-overlay-mode
87 (setq eldoc-message-function #'eldoc-overlay-display-message-momentary)
88 (setq eldoc-message-function #'eldoc-minibuffer-message)
92 ;;; ----------------------------------------------------------------------------
94 (provide 'eldoc-overlay-mode)
96 ;;; eldoc-overlay-mode.el ends here