1 ;;; inline-docs.el --- Show inline contextual docs.
3 ;; Author: stardiviner <numbchild@gmail.com>
4 ;; Keywords: inline docs overlay
5 ;; URL: https://github.com/stardiviner/inline-docs.el
6 ;; Created: 20th Jan 2017
8 ;; Package-Requires: ((emacs "24.3"))
12 ;; This is a library for showing inline contextual docs above or below.
14 ;; You can use this library function `inline-docs` in packages like
15 ;; https://github.com/stardiviner/eldoc-overlay-mode.
18 ;; (setq eldoc-message-function #'inline-docs)
22 ;; (inline-docs "FORMATED-STRING")
23 ;; (inline-docs "STRING")
27 ;;; ----------------------------------------------------------------------------
31 (defvar inline-docs-overlay nil
)
33 (defgroup inline-docs nil
34 "Show inline contextual docs."
37 (defcustom inline-docs-position
'above
38 "Specify inline-docs display position, up or down.
40 Set `inline-docs-position' to `up' to fix issue that `inline-docs' does not show on single line which don't has next line."
42 :tag
"Specify inline-docs display position."
43 (const :tag
"up" above
)
44 (const :tag
"down" below
))
47 (defcustom inline-docs-border-symbol ?―
48 "Specify symbol for inline-docs border."
52 (defcustom inline-docs-prefix-symbol ?\s
53 "Specify symbol for inline-docs prefix."
57 (defcustom inline-docs-indicator-symbol
"➜"
58 "Specify symbol for inline-docs indicator."
62 (defface inline-docs-face
63 '((t (:inherit default
)))
64 "Face for `inline-docs-mode'."
67 (defface inline-docs-border-face
68 '((t (:inherit font-lock-doc-face
)))
69 "Face for inline docs border lines."
72 (defface inline-docs-prefix-face
73 '((t (:inherit default
)))
74 "Face for inline docs prefix."
77 (defface inline-docs-indicator-face
78 '((t (:inherit font-lock-doc-face
)))
79 "Face for inline docs indicator."
82 (defun inline-docs--clear-overlay ()
83 "Clear inline-docs overlays."
84 (when (overlayp inline-docs-overlay
)
85 (delete-overlay inline-docs-overlay
))
86 (remove-hook 'post-command-hook
'inline-docs--clear-overlay
))
88 (defun inline-docs--string-display-next-line (string apply-face
)
89 "Show STRING contents below point line until next command with APPLY-FACE."
90 (let* ((border-line (make-string (window-body-width) inline-docs-border-symbol
))
92 (if (= (current-indentation) 0) ; fix (wrong-type-argument wholenump -1) when current indentation is 0 minus 1 will caused wholenump exception.
94 (- (current-indentation) 1))
95 inline-docs-prefix-symbol
))
96 (str (concat (propertize border-line
97 'face
'inline-docs-border-face
)
100 (propertize (concat inline-docs-indicator-symbol
" ")
101 'face
'inline-docs-indicator-face
)
102 (copy-sequence string
) ; original eldoc string with format.
104 (propertize border-line
105 'face
'inline-docs-border-face
)
112 (inline-docs--clear-overlay)
113 ;; decide overlay positions
114 (cl-case inline-docs-position
115 ('above
(forward-line 0))
116 ('below
(forward-line)))
117 (setq start-pos
(point))
119 (setq end-pos
(point))
121 (setq inline-docs-overlay
(make-overlay start-pos end-pos
(current-buffer)))
124 (overlay-put inline-docs-overlay
'face
'inline-docs-face
))
126 ;; (overlay-put inline-docs-overlay 'display "")
127 ;; (overlay-put inline-docs-overlay 'display :height 20)
128 ;; pre-pend indentation spaces
129 ;; (overlay-put inline-docs-overlay 'line-prefix prefix)
130 ;; auto delete overlay
131 (overlay-put inline-docs-overlay
'evaporate t
)
133 (overlay-put inline-docs-overlay
'before-string str
))
134 (add-hook 'post-command-hook
'inline-docs--clear-overlay
))))
137 (defun inline-docs-display-docs-momentary (format-string &rest args
)
138 "Display inline docs FORMAT-STRING under point with extra ARGS."
140 (inline-docs--string-display-next-line
141 (apply 'format format-string args
)
145 (defalias 'inline-docs
'inline-docs-display-docs-momentary
)
147 ;;; ----------------------------------------------------------------------------
149 (provide 'inline-docs
)
151 ;;; inline-docs.el ends here