merge: pull request #5908 from ethan-leba/repl-handler

Add :send-region and :send-buffer options to `set-repl-handler!`
This commit is contained in:
Henrik Lissner 2022-01-03 18:12:31 +01:00 committed by GitHub
commit b88eb77605
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View file

@ -26,7 +26,10 @@
(when (executable-find "Microsoft.Python.LanguageServer") (when (executable-find "Microsoft.Python.LanguageServer")
(set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer")))) (set-eglot-client! 'python-mode '("Microsoft.Python.LanguageServer"))))
:config :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-docsets! '(python-mode inferior-python-mode) "Python 3" "NumPy" "SciPy" "Pandas")
(set-ligatures! 'python-mode (set-ligatures! 'python-mode

View file

@ -73,7 +73,9 @@
(buffer-file-name (buffer-base-buffer)))) (buffer-file-name (buffer-base-buffer))))
"emacs") "emacs")
(alist-get 'emacs-lisp-mode +eval-runners))) (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)))) (quickrun))))
;;;###autoload ;;;###autoload
@ -85,7 +87,9 @@
(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)) (funcall (or (plist-get (cdr (alist-get major-mode +eval-repls)) :send-region)
#'+eval/send-region-to-repl)
beg end))
((let ((runner ((let ((runner
(or (alist-get major-mode +eval-runners) (or (alist-get major-mode +eval-runners)
(and (require 'quickrun nil t) (and (require 'quickrun nil t)
@ -110,7 +114,10 @@
;;;###autoload ;;;###autoload
(defun +eval/buffer-or-region () (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) (interactive)
(call-interactively (call-interactively
(if (use-region-p) (if (use-region-p)

View file

@ -22,7 +22,14 @@ PLIST is a property list that map special attributes to this repl. These are
recognized: recognized:
:persist BOOL :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)) (declare (indent defun))
(dolist (mode (doom-enlist modes)) (dolist (mode (doom-enlist modes))
(setf (alist-get mode +eval-repls) (setf (alist-get mode +eval-repls)