I've whipped up a working example of a function that takes a string and temporarily displays it with a timeout after the buffer text:
(defun my-momentarily-display-after-buffer-end (string &optional timeout)
(let ((ov (make-overlay (point-max) (point-max))))
(overlay-put ov 'after-string
(concat (propertize " " 'display
'(space :align-to (+ left-fringe 10)))
(propertize string 'display
'(raise -1))
"\n\n"))
(sit-for (or timeout 5))
(delete-overlay ov)))
The following incantation will result in your lower red box example:
(my-momentarily-display-after-buffer-end "Nothing to see here...")
The reason this works is because overlays use markers as positions to be displayed between. Using the outermost position as start and end of the overlay enables you to display text after it by using the after-string
property. Since overlays can contain propertized text, I set it up to appear indented and with whitespace around it.
The other example can use the same idea to display text after the end
of the line:
(defun my-momentarily-display-after-line-end (string &optional timeout)
(let ((ov (make-overlay (line-end-position) (line-end-position))))
(overlay-put
ov 'after-string
(concat (propertize " " 'display
`(space :align-to (- right-fringe
,(1+ (length string)))))
string))
(sit-for (or timeout 5))
(delete-overlay ov)))
The following invocation will result in your right side red box example:
(my-momentarily-display-after-line-end "annotation")
You can go a lot more crazy and add faces to distinguish these
overlays from buffer text, display them longer than for a timeout,
adjust their position, detect when there's no empty space and use
normal overlays of propertized text, etc. I recommend looking at the
source code of
company-mode because
it's very readable and demonstrates a more elaborate (and mostly
bugfree) usage of overlays to create a flexible popup menu with the
suggested features.
insert
text into the buffer and propertize that?