From fea561f678db51da5e93307be87c76f58df8e8a9 Mon Sep 17 00:00:00 2001 From: Ethan Leba Date: Sat, 18 Dec 2021 10:31:20 -0500 Subject: [PATCH 1/3] feat(eval): :send-region and :send-buffer handlers Ref: #2496 --- modules/tools/eval/autoload/eval.el | 8 ++++++-- modules/tools/eval/autoload/settings.el | 9 ++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/modules/tools/eval/autoload/eval.el b/modules/tools/eval/autoload/eval.el index 4fc951ae7..9d9183206 100644 --- a/modules/tools/eval/autoload/eval.el +++ b/modules/tools/eval/autoload/eval.el @@ -73,7 +73,9 @@ (buffer-file-name (buffer-base-buffer)))) "emacs") (alist-get 'emacs-lisp-mode +eval-runners))) - (+eval/region (point-min) (point-max)) + (if-let ((buffer-handler (plist-get (cdr (alist-get major-mode +eval-repls)) :send-buffer))) + (funcall buffer-handler) + (+eval/region (point-min) (point-max))) (quickrun)))) ;;;###autoload @@ -85,7 +87,9 @@ (ignore-errors (get-buffer-window (or (+eval--ensure-in-repl-buffer) t)))) - (+eval/send-region-to-repl beg end)) + (funcall (or (plist-get (cdr (alist-get major-mode +eval-repls)) :send-region) + #'+eval/send-region-to-repl) + beg end)) ((let ((runner (or (alist-get major-mode +eval-runners) (and (require 'quickrun nil t) diff --git a/modules/tools/eval/autoload/settings.el b/modules/tools/eval/autoload/settings.el index 90116eaba..a11cb3831 100644 --- a/modules/tools/eval/autoload/settings.el +++ b/modules/tools/eval/autoload/settings.el @@ -22,7 +22,14 @@ PLIST is a property list that map special attributes to this repl. These are recognized: :persist BOOL - If non-nil, this REPL won't be killed when its window is closed." + If non-nil, this REPL won't be killed when its window is closed. + :send-region FUNC + A function that accepts a BEG and END, and sends the contents of the region + to the REPL. Defaults to `+eval/send-region-to-repl'. + :send-buffer FUNC + A function of no arguments that sends the contents of the buffer to the REPL. + Defaults to `+eval/region', which will run the :send-region specified function + or `+eval/send-region-to-repl'." (declare (indent defun)) (dolist (mode (doom-enlist modes)) (setf (alist-get mode +eval-repls) From aebd4b0c9938f40f744ae2083da11e79a237ffba Mon Sep 17 00:00:00 2001 From: Ethan Leba Date: Sat, 18 Dec 2021 10:37:15 -0500 Subject: [PATCH 2/3] docs(eval): explain DWIM behavior --- modules/tools/eval/autoload/eval.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/tools/eval/autoload/eval.el b/modules/tools/eval/autoload/eval.el index 9d9183206..573329335 100644 --- a/modules/tools/eval/autoload/eval.el +++ b/modules/tools/eval/autoload/eval.el @@ -114,7 +114,10 @@ ;;;###autoload (defun +eval/buffer-or-region () - "Evaluate the whole buffer." + "Evaluate the region if it's active, otherwise evaluate the whole buffer. + +If a REPL is open the code will be evaluated in it, otherwise a quickrun +runner will be used." (interactive) (call-interactively (if (use-region-p) From 1d0f4ca424e1eb61b3042d608fb461d6850f0a48 Mon Sep 17 00:00:00 2001 From: Ethan Leba Date: Sat, 18 Dec 2021 10:39:14 -0500 Subject: [PATCH 3/3] tweak(python): use `python-shell` repl handlers Fix: #4375 --- modules/lang/python/config.el | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/lang/python/config.el b/modules/lang/python/config.el index a5c955e83..31f40c12f 100644 --- a/modules/lang/python/config.el +++ b/modules/lang/python/config.el @@ -26,7 +26,10 @@ (when (executable-find "Microsoft.Python.LanguageServer") (set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer")))) :config - (set-repl-handler! 'python-mode #'+python/open-repl :persist t) + (set-repl-handler! 'python-mode #'+python/open-repl + :persist t + :send-region #'python-shell-send-region + :send-buffer #'python-shell-send-buffer) (set-docsets! '(python-mode inferior-python-mode) "Python 3" "NumPy" "SciPy" "Pandas") (set-ligatures! 'python-mode