From 790c2a6d84def0e2f495c5b169d603c22f9c5872 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 7 Aug 2022 17:38:58 +0200 Subject: [PATCH] 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. --- modules/tools/eval/autoload/eval.el | 30 +++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/modules/tools/eval/autoload/eval.el b/modules/tools/eval/autoload/eval.el index 4c07e2ea2..dbec32bcf 100644 --- a/modules/tools/eval/autoload/eval.el +++ b/modules/tools/eval/autoload/eval.el @@ -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) - eros-overlays-use-font-lock) + (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