Update modules/feature/eval
This commit is contained in:
parent
43d0247d61
commit
35ae1965a7
3 changed files with 42 additions and 38 deletions
|
@ -49,22 +49,3 @@ elisp buffer). Otherwise forward the region to Quickrun."
|
||||||
(insert (current-kill 0)))))
|
(insert (current-kill 0)))))
|
||||||
(t (quickrun-replace-region beg end))))
|
(t (quickrun-replace-region beg end))))
|
||||||
|
|
||||||
|
|
||||||
;;;###autoload (autoload '+repl:eval-region "feature/repl/autoload/repl" nil t)
|
|
||||||
;;;###autoload (autoload '+repl:eval-region-and-replace "feature/repl/autoload/eval" nil t)
|
|
||||||
|
|
||||||
(@after evil
|
|
||||||
(evil-set-command-properties '+repl/eval-buffer :move-point nil :repeat nil)
|
|
||||||
(evil-set-command-properties '+repl/eval-region :move-point nil :repeat nil)
|
|
||||||
|
|
||||||
(evil-define-operator +repl:eval-region (beg end)
|
|
||||||
"Evaluate a region and, if large enough, prints its output to a popup buffer (if an
|
|
||||||
elisp buffer). Otherwise forward the region to Quickrun."
|
|
||||||
:move-point nil :repeat nil
|
|
||||||
(interactive "<r>")
|
|
||||||
(+repl/eval-region beg end))
|
|
||||||
|
|
||||||
(evil-define-operator +repl:eval-region-and-replace (beg end)
|
|
||||||
(interactive "<r>")
|
|
||||||
(+repl/eval-region-and-replace beg end)))
|
|
||||||
|
|
||||||
|
|
12
modules/feature/eval/autoload/evil.el
Normal file
12
modules/feature/eval/autoload/evil.el
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
;;; feature/eval/autoload/evil.el
|
||||||
|
|
||||||
|
;;;###autoload (autoload '+repl:eval-region "feature/eval/autoload/evil" nil t)
|
||||||
|
(evil-define-operator +repl:eval-region (beg end)
|
||||||
|
(interactive "<r>")
|
||||||
|
(+repl/eval-region beg end))
|
||||||
|
|
||||||
|
;;;###autoload (autoload '+repl:eval-region-and-replace "feature/eval/autoload/evil" nil t)
|
||||||
|
(evil-define-operator +repl:eval-region-and-replace (beg end)
|
||||||
|
(interactive "<r>")
|
||||||
|
(+repl/eval-region-and-replace beg end))
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
"A hash-table of plists, containing functions for building source code. Used
|
"A hash-table of plists, containing functions for building source code. Used
|
||||||
by `+eval/build', and filled with the `:build' setting")
|
by `+eval/build', and filled with the `:build' setting")
|
||||||
|
|
||||||
(defvar +eval--runners nil
|
|
||||||
"A list of `quickrun-add-command' arguments.")
|
|
||||||
|
|
||||||
(defvar +eval--repls nil
|
(defvar +eval--repls nil
|
||||||
"A list of `rtog/add-repl' arguments.")
|
"A list of `rtog/add-repl' arguments.")
|
||||||
|
|
||||||
|
@ -26,20 +23,37 @@ by `+eval/build', and filled with the `:build' setting")
|
||||||
(list 'rtog/add-repl mode command)
|
(list 'rtog/add-repl mode command)
|
||||||
`(push ',(list mode command) +eval--repls)))
|
`(push ',(list mode command) +eval--repls)))
|
||||||
|
|
||||||
(@def-setting :build (name mode pred-fn build-fn)
|
(@def-setting :build (name mode pred-fn &optional build-fn)
|
||||||
"Define a build command function (BUILD-FN) for major-mode MODE, called NAME
|
"Define a build command function (BUILD-FN) for major-mode MODE, called NAME
|
||||||
(a symbol). PRED-FN is a predicate function that determines this builder's
|
-- a symbol -- PRED-FN is a predicate function that determines this builder's
|
||||||
suitability for the current buffer."
|
suitability for the current buffer."
|
||||||
|
(unless build-fn
|
||||||
|
(setq build-fn pred-fn
|
||||||
|
pred-fn nil))
|
||||||
`(puthash ',(cons name mode)
|
`(puthash ',(cons name mode)
|
||||||
(list :predicate ,pred-fn :fn ,build-fn)
|
(list :predicate ,pred-fn :fn ,build-fn)
|
||||||
+eval-builders))
|
+eval-builders))
|
||||||
|
|
||||||
(@def-setting :eval (name alist &rest plist)
|
(@def-setting :eval (mode command)
|
||||||
"Define a code evaluator for `quickrun'. Takes the same arguments as
|
"Define a code evaluator for `quickrun'.
|
||||||
`quickrun-add-command'."
|
|
||||||
(if (featurep 'quickrun)
|
1. If MODE is a string and COMMAND is the string, MODE is a file regexp and
|
||||||
(apply 'quickrun-add-command name alist plist)
|
COMMAND is a string key for an entry in `quickrun-file-alist'.
|
||||||
`(push ',(list name alist plist) +eval--runners)))
|
2. If MODE is not a string and COMMAND is a string, MODE is a major-mode symbol
|
||||||
|
and COMMAND is a key; they will be registered in
|
||||||
|
`quickrun--major-mode-alist'.
|
||||||
|
3. If MODE is not a string and COMMAND is a list, use `quickrun-add-command'. e.g.
|
||||||
|
(quickrun-add-command MODE COMMAND :mode MODE)"
|
||||||
|
(if (stringp command)
|
||||||
|
`(@after quickrun
|
||||||
|
(push ,(cons mode command)
|
||||||
|
,(if (stringp mode)
|
||||||
|
'quickrun-file-alist
|
||||||
|
'quickrun--major-mode-alist)))
|
||||||
|
`(@after quickrun
|
||||||
|
(quickrun-add-command
|
||||||
|
,(symbol-name mode)
|
||||||
|
',command :mode ',mode))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -60,16 +74,13 @@ suitability for the current buffer."
|
||||||
;; don't auto-focus quickrun windows. Shackle handles that for us.
|
;; don't auto-focus quickrun windows. Shackle handles that for us.
|
||||||
(setq quickrun-focus-p nil)
|
(setq quickrun-focus-p nil)
|
||||||
|
|
||||||
(dolist (runner +eval--runners)
|
|
||||||
(apply 'quickrun-add-command runner))
|
|
||||||
|
|
||||||
(defun +repl*quickrun-close-popup (&optional _ _ _ _)
|
(defun +repl*quickrun-close-popup (&optional _ _ _ _)
|
||||||
"Allows us to re-run quickrun from inside the quickrun buffer (silently)."
|
"Allows us to re-run quickrun from inside the quickrun buffer (silently)."
|
||||||
(awhen (get-buffer-window quickrun/buffer-name)
|
(awhen (get-buffer-window quickrun/buffer-name)
|
||||||
(let (message-log-max)
|
(let (message-log-max)
|
||||||
(quickrun/kill-running-process)
|
(quickrun/kill-running-process)
|
||||||
(message ""))
|
(message ""))
|
||||||
(doom/popup-close it nil)))
|
(doom/popup-close it)))
|
||||||
|
|
||||||
(defun +repl|quickrun-scroll-to-bof ()
|
(defun +repl|quickrun-scroll-to-bof ()
|
||||||
"Ensures window is scrolled to BOF"
|
"Ensures window is scrolled to BOF"
|
||||||
|
@ -89,10 +100,10 @@ suitability for the current buffer."
|
||||||
:init (@add-hook repl-toggle-mode (evil-initialize-state 'emacs))
|
:init (@add-hook repl-toggle-mode (evil-initialize-state 'emacs))
|
||||||
:config
|
:config
|
||||||
(@set :popup
|
(@set :popup
|
||||||
(:custom (lambda (b &rest _)
|
'(:custom (lambda (b &rest _)
|
||||||
(when (and (featurep 'repl-toggle)
|
(when (and (featurep 'repl-toggle)
|
||||||
(string-prefix-p "*" (buffer-name (get-buffer b))))
|
(string-prefix-p "*" (buffer-name (get-buffer b))))
|
||||||
(buffer-local-value 'repl-toggle-mode b))))
|
(buffer-local-value 'repl-toggle-mode b))))
|
||||||
:popup t :size 16)
|
:popup t :size 16)
|
||||||
|
|
||||||
(dolist (repl +eval--repls)
|
(dolist (repl +eval--repls)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue