tools/eval: add +overlay feature

Now, inline evaluation will display results in an overlay next to the
cursor, rather than in the minibuffer (unless it gets too big, in which
case it'll use a popup buffer).
This commit is contained in:
Henrik Lissner 2019-10-26 01:37:36 -04:00
parent c2f6aa3e9d
commit 84a063ca78
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
7 changed files with 111 additions and 33 deletions

View file

@ -7,19 +7,23 @@
(defun +emacs-lisp-eval (beg end)
"Evaluate a region and print it to the echo area (if one line long), otherwise
to a pop up buffer."
(require 'pp)
(let ((debug-on-error t)
(buffer-file-name (buffer-file-name (buffer-base-buffer)))
(doom--current-module (ignore-errors (doom-module-from-path buffer-file-name)))
(temp-buffer-show-hook
(cons (if (fboundp '+word-wrap-mode)
'+word-wrap-mode
'visual-line-mode)
temp-buffer-show-hook)))
(pp-eval-expression
(read (buffer-substring-no-properties beg end)))
(when-let (win (get-buffer-window "*Pp Eval Output*"))
(fit-window-to-buffer win))))
(+eval-display-results
(let* ((buffer-file-name (buffer-file-name (buffer-base-buffer))))
(string-trim-right
(condition-case-unless-debug e
(let ((result
(let ((debug-on-error t))
(eval (read (buffer-substring-no-properties beg end))
`((buffer-file-name . ,buffer-file-name)
(doom--current-module
. ,(ignore-errors
(doom-module-from-path buffer-file-name))))))))
(if (stringp result)
result
(require 'pp)
(pp-to-string result)))
(error (error-message-string e)))))
(current-buffer)))
(defvar +emacs-lisp--face nil)
;;;###autoload