tools/eval: always eval elisp in current session
If you used an +eval/* command from a non-emacs-lisp-mode buffer, quickrun would prompt you for a program to evaluate the code with. If you selected "emacs" the code would evaluate in an external Emacs process and return displayed output (stdout). This commit changes +eval/buffer, +eval/region, and +eval/region-and-replace (and all the other +eval commands that use them) to evaluate code in the current session instead.
This commit is contained in:
parent
ac9e716018
commit
14d341530a
1 changed files with 50 additions and 23 deletions
|
@ -55,31 +55,50 @@
|
||||||
;;
|
;;
|
||||||
;;; Commands
|
;;; Commands
|
||||||
|
|
||||||
|
(defvar quickrun-option-cmdkey)
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eval/buffer ()
|
(defun +eval/buffer ()
|
||||||
"Evaluate the whole buffer."
|
"Evaluate the whole buffer."
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (or (assq major-mode +eval-runners)
|
(let ((quickrun-option-cmdkey (bound-and-true-p quickrun-option-cmdkey)))
|
||||||
(and (fboundp '+eval--ensure-in-repl-buffer)
|
(if (or (assq major-mode +eval-runners)
|
||||||
(ignore-errors
|
(and (fboundp '+eval--ensure-in-repl-buffer)
|
||||||
(get-buffer-window (or (+eval--ensure-in-repl-buffer)
|
(ignore-errors
|
||||||
t)))))
|
(get-buffer-window (or (+eval--ensure-in-repl-buffer)
|
||||||
(+eval/region (point-min) (point-max))
|
t))))
|
||||||
(quickrun)))
|
(and (require 'quickrun nil t)
|
||||||
|
(equal (setq
|
||||||
|
quickrun-option-cmdkey
|
||||||
|
(quickrun--command-key
|
||||||
|
(buffer-file-name (buffer-base-buffer))))
|
||||||
|
"emacs")
|
||||||
|
(alist-get 'emacs-lisp-mode +eval-runners)))
|
||||||
|
(+eval/region (point-min) (point-max))
|
||||||
|
(quickrun))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eval/region (beg end)
|
(defun +eval/region (beg end)
|
||||||
"Evaluate a region between BEG and END and display the output."
|
"Evaluate a region between BEG and END and display the output."
|
||||||
(interactive "r")
|
(interactive "r")
|
||||||
(let ((load-file-name buffer-file-name))
|
(let ((load-file-name buffer-file-name))
|
||||||
(if (and (fboundp '+eval--ensure-in-repl-buffer)
|
(cond ((and (fboundp '+eval--ensure-in-repl-buffer)
|
||||||
(ignore-errors
|
(ignore-errors
|
||||||
(get-buffer-window (or (+eval--ensure-in-repl-buffer)
|
(get-buffer-window (or (+eval--ensure-in-repl-buffer)
|
||||||
t))))
|
t))))
|
||||||
(+eval/send-region-to-repl beg end)
|
(+eval/send-region-to-repl beg end))
|
||||||
(if-let (runner (alist-get major-mode +eval-runners))
|
((let ((runner
|
||||||
(funcall runner beg end)
|
(or (alist-get major-mode +eval-runners)
|
||||||
(quickrun-region beg end)))))
|
(and (require 'quickrun nil t)
|
||||||
|
(equal (setq
|
||||||
|
lang (quickrun--command-key
|
||||||
|
(buffer-file-name (buffer-base-buffer))))
|
||||||
|
"emacs")
|
||||||
|
(alist-get 'emacs-lisp-mode +eval-runners))))
|
||||||
|
lang)
|
||||||
|
(if runner
|
||||||
|
(funcall runner beg end)
|
||||||
|
(let ((quickrun-option-cmdkey lang))
|
||||||
|
(quickrun-region beg end))))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +eval/line-or-region ()
|
(defun +eval/line-or-region ()
|
||||||
|
@ -102,11 +121,19 @@
|
||||||
(defun +eval/region-and-replace (beg end)
|
(defun +eval/region-and-replace (beg end)
|
||||||
"Evaluation a region between BEG and END, and replace it with the result."
|
"Evaluation a region between BEG and END, and replace it with the result."
|
||||||
(interactive "r")
|
(interactive "r")
|
||||||
(cond ((eq major-mode 'emacs-lisp-mode)
|
(let (lang)
|
||||||
(kill-region beg end)
|
(cond
|
||||||
(condition-case nil
|
((or (eq major-mode 'emacs-lisp-mode)
|
||||||
(prin1 (eval (read (current-kill 0)))
|
(and (require 'quickrun nil t)
|
||||||
(current-buffer))
|
(equal (setq
|
||||||
(error (message "Invalid expression")
|
lang (quickrun--command-key
|
||||||
(insert (current-kill 0)))))
|
(buffer-file-name (buffer-base-buffer))))
|
||||||
((quickrun-replace-region beg end))))
|
"emacs")))
|
||||||
|
(kill-region beg end)
|
||||||
|
(condition-case nil
|
||||||
|
(prin1 (eval (read (current-kill 0)))
|
||||||
|
(current-buffer))
|
||||||
|
(error (message "Invalid expression")
|
||||||
|
(insert (current-kill 0)))))
|
||||||
|
((let ((quickrun-option-cmdkey lang))
|
||||||
|
(quickrun-replace-region beg end))))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue