add metadata
[eldoc-overlay.git] / eldoc-overlay-mode.el
blob829adbf79fcbdab82ce51f1c5e629dabe42354d4
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
6 ;; Created: 14th Jan 2017
7 ;; Version: 0.0.1
8 ;; Package-Requires: ((emacs "24.3"))
10 ;;; Commentary:
14 ;;; Code:
15 ;;; ----------------------------------------------------------------------------
17 (defvar eldoc-overlay-display-overlay nil)
19 (defun eldoc-overlay-delete-string-display ()
20 (when (overlayp eldoc-overlay-display-overlay)
21 (delete-overlay eldoc-overlay-display-overlay))
22 (remove-hook 'post-command-hook 'eldoc-overlay-delete-string-display))
24 (defun eldoc-overlay-string-display-next-line (string)
25 "Overwrite contents of next line with STRING until next command."
26 (let ((str (concat (make-string (1+ (current-indentation)) 32)
27 (copy-sequence string)))
28 start-pos end-pos)
29 (unwind-protect
30 (save-excursion
31 (eldoc-overlay-delete-string-display)
32 (forward-line)
33 (setq start-pos (point))
34 (end-of-line)
35 (setq end-pos (point))
36 (setq eldoc-overlay-display-overlay (make-overlay start-pos end-pos))
37 ;; Hide full line
38 (overlay-put eldoc-overlay-display-overlay 'display "")
39 ;; Display message
40 (overlay-put eldoc-overlay-display-overlay 'before-string str))
41 (add-hook 'post-command-hook 'eldoc-overlay-delete-string-display))))
43 (defun eldoc-overlay-display-message-momentary (format-string &rest args)
44 "Display eldoc message near point."
45 (when format-string
46 (eldoc-overlay-string-display-next-line
47 (apply 'format format-string args))))
49 (defvar eldoc-overlay-mode-map
50 (let ((map (make-sparse-keymap)))
51 map))
53 (define-minor-mode eldoc-overlay-mode
54 "Minor mode for displaying eldoc with contextual documentation overlay."
56 :lighter "ElDoc overlay"
57 :keymap eldoc-overlay-mode-map
58 :global t
59 (if eldoc-overlay-mode
60 (setq eldoc-message-function #'eldoc-overlay-display-message-momentary)
61 (setq eldoc-message-function #'eldoc-minibuffer-message)
65 ;;; ----------------------------------------------------------------------------
67 (provide 'eldoc-overlay-mode)
69 ;;; eldoc-overlay-mode.el ends here