mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-01 12:17:25 -05:00
fix(eval): eros overlay going off-screen
Evaluating code (and :tools (eval +overlay) enabled) will do one of two things with the return value: If long, it will be displayed in a popup window on the bottom of the frame. If short (<3-4 lines), it will be displayed in an overlay at the end of the line. If you happened to have scrolled horizontally (such that the BOL isn't visible), the overlay would be displayed offscreen and unreadable. Any attempt to scroll it into view will cause it to disappear (as per its transient nature). This fix pads each newline in said overlay such that the overlay is pushed into view.
This commit is contained in:
@ -24,11 +24,33 @@
|
||||
(defun +eval-display-results-in-overlay (output &optional source-buffer)
|
||||
"Display OUTPUT in a floating overlay next to the cursor."
|
||||
(require 'eros)
|
||||
(let ((this-command #'+eval/buffer-or-region)
|
||||
(let* ((this-command #'+eval/buffer-or-region)
|
||||
(prefix eros-eval-result-prefix)
|
||||
(lines (split-string output "\n"))
|
||||
(prefixlen (length prefix))
|
||||
(len (+ (apply #'max (mapcar #'length lines))
|
||||
prefixlen))
|
||||
(col (- (current-column) (window-hscroll)))
|
||||
(next-line? (or (cdr lines)
|
||||
(< (- (window-width)
|
||||
(save-excursion (goto-char (point-at-eol))
|
||||
(- (current-column)
|
||||
(window-hscroll))))
|
||||
len)))
|
||||
(pad (if next-line?
|
||||
(+ (window-hscroll) prefixlen)
|
||||
0))
|
||||
(where (if next-line?
|
||||
(line-beginning-position 2)
|
||||
(line-end-position)))
|
||||
eros-eval-result-prefix
|
||||
eros-overlays-use-font-lock)
|
||||
(with-current-buffer (or source-buffer (current-buffer))
|
||||
(eros--make-result-overlay output
|
||||
:where (line-end-position)
|
||||
(eros--make-result-overlay
|
||||
(concat (make-string (max 0 (- pad prefixlen)) ?\s)
|
||||
prefix
|
||||
(string-join lines (concat "\n" (make-string pad ?\s))))
|
||||
:where where
|
||||
:duration eros-eval-result-duration))))
|
||||
|
||||
;;;###autoload
|
||||
|
Reference in New Issue
Block a user