2019-04-21 19:59:44 -04:00
|
|
|
;;; tools/eval/config.el -*- lexical-binding: t; -*-
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2019-10-29 18:17:44 -04:00
|
|
|
(defvar +eval-popup-min-lines 4
|
2019-10-26 01:37:36 -04:00
|
|
|
"The output height threshold (inclusive) before output is displayed in a popup
|
2019-10-29 18:17:44 -04:00
|
|
|
buffer rather than an overlay on the line at point or the minibuffer.")
|
2019-10-26 01:37:36 -04:00
|
|
|
|
2017-03-04 18:28:51 -05:00
|
|
|
;; remove ellipsis when printing sexps in message buffer
|
|
|
|
(setq eval-expression-print-length nil
|
|
|
|
eval-expression-print-level nil)
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2017-05-07 02:27:54 +02:00
|
|
|
|
2018-05-14 01:22:33 +02:00
|
|
|
;;
|
2019-10-26 01:37:36 -04:00
|
|
|
;;; Packages
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2019-10-23 21:39:19 -04:00
|
|
|
(set-popup-rule!
|
|
|
|
(lambda (bufname _)
|
|
|
|
(when (boundp '+eval-repl-mode)
|
|
|
|
(buffer-local-value '+eval-repl-mode (get-buffer bufname))))
|
|
|
|
:ttl (lambda (buf)
|
|
|
|
(unless (plist-get +eval-repl-plist :persist)
|
|
|
|
(when-let (process (get-buffer-process buf))
|
|
|
|
(set-process-query-on-exit-flag process nil)
|
|
|
|
(kill-process process)
|
|
|
|
(kill-buffer buf))))
|
|
|
|
:size 0.25 :quit nil)
|
|
|
|
|
|
|
|
|
2018-10-19 21:58:41 -04:00
|
|
|
(after! quickrun
|
2018-01-08 16:18:16 -05:00
|
|
|
(setq quickrun-focus-p nil)
|
|
|
|
|
2018-06-18 02:26:05 +02:00
|
|
|
(set-popup-rule! "^\\*quickrun" :size 0.3 :ttl 0)
|
2017-02-13 16:57:08 -05:00
|
|
|
|
2019-07-23 17:24:56 +02:00
|
|
|
(defadvice! +eval--quickrun-fix-evil-visual-region-a ()
|
2019-05-17 16:01:46 -04:00
|
|
|
"Make `quickrun-replace-region' recognize evil visual selections."
|
2019-07-22 23:29:51 +02:00
|
|
|
:override #'quickrun--outputter-replace-region
|
2019-05-17 16:01:46 -04:00
|
|
|
(let ((output (buffer-substring-no-properties (point-min) (point-max))))
|
|
|
|
(with-current-buffer quickrun--original-buffer
|
|
|
|
(cl-destructuring-bind (beg . end)
|
|
|
|
;; Because `deactivate-mark', the function, was used in
|
|
|
|
;; `quickrun--region-command-common' instead of `deactivate-mark',
|
|
|
|
;; the variable, the selection is disabled by this point.
|
|
|
|
(if (bound-and-true-p evil-local-mode)
|
|
|
|
(cons evil-visual-beginning evil-visual-end)
|
|
|
|
(cons (region-beginning) (region-end)))
|
|
|
|
(delete-region beg end)
|
|
|
|
(insert output))
|
|
|
|
(setq quickrun-option-outputter quickrun--original-outputter))))
|
|
|
|
|
2019-10-26 01:37:36 -04:00
|
|
|
(defadvice! +eval--quickrun-auto-close-a (&rest _)
|
|
|
|
"Silently re-create the quickrun popup when re-evaluating."
|
|
|
|
:before '(quickrun quickrun-region)
|
|
|
|
(when-let (win (get-buffer-window quickrun--buffer-name))
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(quickrun--kill-running-process)
|
|
|
|
(message ""))
|
|
|
|
(delete-window win)))
|
|
|
|
|
2019-07-28 14:52:59 +02:00
|
|
|
(add-hook! 'quickrun-after-run-hook
|
2019-07-22 23:29:51 +02:00
|
|
|
(defun +eval-quickrun-shrink-window-h ()
|
|
|
|
"Shrink the quickrun output window once code evaluation is complete."
|
|
|
|
(when-let (win (get-buffer-window quickrun--buffer-name))
|
|
|
|
(with-selected-window (get-buffer-window quickrun--buffer-name)
|
|
|
|
(let ((ignore-window-parameters t))
|
2019-10-26 01:37:36 -04:00
|
|
|
(shrink-window-if-larger-than-buffer)))))
|
2019-07-22 23:29:51 +02:00
|
|
|
(defun +eval-quickrun-scroll-to-bof-h ()
|
|
|
|
"Ensures window is scrolled to BOF on invocation."
|
|
|
|
(when-let (win (get-buffer-window quickrun--buffer-name))
|
|
|
|
(with-selected-window win
|
2019-10-26 01:37:36 -04:00
|
|
|
(goto-char (point-min))))))
|
|
|
|
|
2019-12-22 23:47:54 -05:00
|
|
|
;; Display evaluation results in an overlay at the end of the current line. If
|
|
|
|
;; the output is more than `+eval-popup-min-lines' (4) lines long, it is
|
|
|
|
;; displayed in a popup.
|
2022-08-12 20:29:19 +02:00
|
|
|
(when (modulep! +overlay)
|
2019-12-22 23:47:54 -05:00
|
|
|
(defadvice! +eval--show-output-in-overlay-a (fn)
|
|
|
|
:filter-return #'quickrun--make-sentinel
|
|
|
|
(lambda (process event)
|
|
|
|
(funcall fn process event)
|
|
|
|
(with-current-buffer quickrun--buffer-name
|
|
|
|
(when (> (buffer-size) 0)
|
|
|
|
(+eval-display-results
|
|
|
|
(string-trim (buffer-string))
|
|
|
|
quickrun--original-buffer)))))
|
|
|
|
|
|
|
|
;; Suppress quickrun's popup window because we're using an overlay instead.
|
2019-10-26 01:37:36 -04:00
|
|
|
(defadvice! +eval--inhibit-quickrun-popup-a (buf cb)
|
|
|
|
:override #'quickrun--pop-to-buffer
|
|
|
|
(setq quickrun--original-buffer (current-buffer))
|
2019-12-22 23:47:54 -05:00
|
|
|
(save-window-excursion
|
|
|
|
(with-current-buffer (pop-to-buffer buf)
|
|
|
|
(setq quickrun-option-outputter #'ignore)
|
|
|
|
(funcall cb))))
|
|
|
|
|
|
|
|
;; HACK Without this, `+eval--inhibit-quickrun-popup-a' throws a
|
|
|
|
;; window-live-p error because no window exists to be recentered!
|
|
|
|
(advice-add #'quickrun--recenter :override #'ignore)))
|
2019-10-26 01:37:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
(use-package! eros
|
2022-08-12 20:29:19 +02:00
|
|
|
:when (modulep! +overlay)
|
2019-10-26 01:37:36 -04:00
|
|
|
:hook (emacs-lisp-mode . eros-mode))
|