Skip to content

Commit

Permalink
Add bqn-comint-use-overlay
Browse files Browse the repository at this point in the history
Show inline results using overlays, instead of just the minibuffer.
  • Loading branch information
slotThe committed Sep 16, 2024
1 parent 2471b5e commit 22545bd
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions bqn-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

;; Author: Marshall Lochbaum <mwlochbaum@gmail.com>
;; Version: 0.1.0
;; Package-Requires: ((emacs "26.1") (compat "30.0.0.0"))
;; Package-Requires: ((emacs "26.1") (compat "30.0.0.0") (eros "0.1.0"))
;; URL: https://github.com/museoa/bqn-mode
;; SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -305,6 +305,15 @@ BQN buffers (or recreate them)."
:type 'boolean
:group 'bqn)

(defcustom bqn-comint-use-overlay nil
"Should BQN use overlays for all `bqn-comint-eval-*' style functions?
If this is nil, print the result in the minibuffer instead."
:type 'boolean
:group 'bqn
:set (lambda (sym val)
(when val (require 'eros))
(set-default-toplevel-value sym val)))

(defun bqn--comint-prefix ()
"The prefix for BQNs comint buffers."
(concat "*" bqn-comint--process-name "-"))
Expand Down Expand Up @@ -431,9 +440,19 @@ bqn-comint-process-session and echoes the result."
(error "Attempt to evaluate empty region to %s" bqn-comint--process-name))
(when (and bqn-comint-flash-on-send (pulse-available-p))
(pulse-momentary-highlight-region start end))
(let ((region (buffer-substring-no-properties start end))
(process (get-buffer-process (bqn-comint-buffer))))
(message "%s" (bqn--comint-call-process-silently process region))))
(let* ((region (buffer-substring-no-properties start end))
(process (get-buffer-process (bqn-comint-buffer)))
(response (bqn--comint-call-process-silently process region))
(r-lines (string-lines response))
(single-line? (= 1 (length r-lines))))
(cond
(bqn-comint-use-overlay ; Use overlay
(eros--make-result-overlay response
:where end
:duration eros-eval-result-duration
:format (if single-line? " ⇒ %s" "%s")))
(t ; Insert in minibuffer
(message "%s" response)))))

(defun bqn-comint-eval-dwim ()
"Evaluate the active region or the current line, displaying the result."
Expand Down

0 comments on commit 22545bd

Please sign in to comment.