2022-01-23 20:38:27 +01:00
|
|
|
← [[doom-module-index:][Back to module index]] ! [[doom-module-issues:::tools eval][Issues]] ↖ [[doom-repo:tree/develop/modules/tools/eval/][Github]] ± [[doom-suggest-edit:][Suggest edits]] ? [[doom-help-modules:][Help]]
|
2021-10-16 01:29:27 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
#+TITLE: :tools eval
|
|
|
|
#+SUBTITLE: Run code, run (also, repls)
|
|
|
|
#+CREATED: February 20, 2017
|
|
|
|
#+SINCE: 2.0.0
|
|
|
|
|
|
|
|
* Description :unfold:
|
2019-10-26 01:37:36 -04:00
|
|
|
This modules adds inline code evaluation support to Emacs and a universal
|
|
|
|
interface for opening and interacting with REPLs.
|
2019-01-03 01:58:43 -05:00
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
** Maintainers
|
|
|
|
/This module has no dedicated maintainers./ [[doom-contrib-maintainer:][Become a maintainer?]]
|
2019-01-03 01:58:43 -05:00
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
** Module flags
|
|
|
|
- +overlay ::
|
|
|
|
Enable the use of overlays (near the cursor) to display the result of inline
|
|
|
|
code evaluation (rather than the minibuffer). If the results are too big the
|
|
|
|
minibuffer will be used anyway.
|
|
|
|
|
|
|
|
** Packages
|
|
|
|
- [[doom-package:][quickrun]]
|
2019-01-03 01:58:43 -05:00
|
|
|
|
|
|
|
** Hacks
|
2021-10-16 01:29:27 +02:00
|
|
|
- Quickrun has been modified to:
|
|
|
|
- Use only one output window, in case of consecutive execution of code.
|
|
|
|
- The quickrun window will resize itself to fit its output, once the
|
2019-01-03 01:58:43 -05:00
|
|
|
underlying process is finished executing the code.
|
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
** TODO Changelog
|
|
|
|
# This section will be machine generated. Don't edit it by hand.
|
|
|
|
/This module does not have a changelog yet./
|
|
|
|
|
|
|
|
* Installation
|
|
|
|
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]
|
|
|
|
|
2019-01-03 01:58:43 -05:00
|
|
|
This module has no direct prerequisites.
|
|
|
|
|
2019-10-26 01:45:09 -04:00
|
|
|
However, many languages will require that you install their interpreters, code
|
|
|
|
runners and/or repls to power the functionality of this module. Visit the
|
2021-10-16 01:29:27 +02:00
|
|
|
documentation of their respective [[doom-module:][:lang]] module for instructions.
|
|
|
|
|
|
|
|
* TODO Usage
|
|
|
|
#+begin_quote
|
|
|
|
🔨 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
|
|
|
|
#+end_quote
|
2019-01-03 01:58:43 -05:00
|
|
|
|
|
|
|
** Inline Code Evaluation
|
2017-12-31 23:07:28 -05:00
|
|
|
Quickrun can be invoked via:
|
2021-10-16 01:29:27 +02:00
|
|
|
- ~M-x +eval/buffer~ (or [[kbd:][gR]], or [[kbd:][M-r]])
|
|
|
|
- ~M-x +eval/region~
|
|
|
|
- ~M-x +eval/region-and-replace~
|
|
|
|
- Evil users can use the [[kbd:][gr]] operator to select and run a region.
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2017-08-21 20:07:07 +02:00
|
|
|
** REPLs
|
2019-01-03 01:58:43 -05:00
|
|
|
Invoked via:
|
2021-10-16 01:29:27 +02:00
|
|
|
- [[kbd:][SPC o r]] or ~:repl~ will open a REPL in a popup window. [[kbd:][SPC o R]] or ~:repl!~
|
2019-10-26 01:45:09 -04:00
|
|
|
will open a REPL in the current window. If a REPL is already open and a
|
|
|
|
selection is active, it will be sent to the REPL.
|
2021-10-16 01:29:27 +02:00
|
|
|
- ~M-x +eval/open-repl-other-window~ ([[kbd:][SPC o r]])
|
|
|
|
- ~M-x +eval/open-repl-same-window~ ([[kbd:][SPC o R]])
|
|
|
|
- ~M-x +eval/send-region-to-repl~ ([[kbd:][SPC c s]]) while a selection (and REPL) is
|
2019-10-26 01:45:09 -04:00
|
|
|
active
|
2019-01-03 01:58:43 -05:00
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
* TODO Configuration
|
|
|
|
#+begin_quote
|
|
|
|
🔨 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
|
|
|
|
#+end_quote
|
|
|
|
|
2019-01-03 01:58:43 -05:00
|
|
|
** Register a REPL for a major-mode
|
|
|
|
REPLs are defined for most languages Doom supports. Check that language module's
|
|
|
|
README.org to see if it does (and if it requires additional setup).
|
|
|
|
|
2019-02-18 01:56:38 -05:00
|
|
|
To use them, you may use ~M-x +eval/open-repl-other-window~, ~M-x
|
|
|
|
+eval/open-repl-same-window~, ~:repl~ (for evil users) or the default binding:
|
2021-10-16 01:29:27 +02:00
|
|
|
[[kbd:][SPC o r]]. These will open a REPL in a popup window.
|
2019-01-03 01:58:43 -05:00
|
|
|
|
|
|
|
#+begin_quote
|
2019-10-26 01:45:09 -04:00
|
|
|
You can simply call that mode's REPL command manually. e.g. ~M-x ielm~, but this
|
|
|
|
will bar you from the benefits of Doom's REPL system (like send-to-repl
|
|
|
|
functionality).
|
2019-01-03 01:58:43 -05:00
|
|
|
#+end_quote
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2019-01-05 16:55:01 -05:00
|
|
|
Otherwise, you can define your own for a specified major mode:
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2019-10-26 01:45:09 -04:00
|
|
|
~(set-repl-handler! MAJOR-MODES FUNCTION)~
|
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
=MAJOR-MODES= is a single major mode symbol or a list of them.
|
2017-08-21 20:07:07 +02:00
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
=FUNCTION= should return a repl buffer. Any window changes in this function are
|
|
|
|
ignored, then the REPL is opened in a popup window. E.g.
|
|
|
|
#+begin_src emacs-lisp
|
2019-02-18 01:56:38 -05:00
|
|
|
(defun +lua/open-repl ()
|
2017-05-25 20:08:50 +02:00
|
|
|
(interactive)
|
2019-01-05 16:55:01 -05:00
|
|
|
(lua-start-process "lua" "lua")
|
|
|
|
(pop-to-buffer lua-process-buffer))
|
|
|
|
|
2019-02-18 01:56:38 -05:00
|
|
|
(set-repl-handler! 'lua-mode #'+lua/open-repl)
|
2021-10-16 01:29:27 +02:00
|
|
|
#+end_src
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2019-01-03 01:58:43 -05:00
|
|
|
** Change how code is evaluated in a major mode
|
2017-12-31 23:07:28 -05:00
|
|
|
Run regions or entire buffers with [[https://github.com/syohex/emacs-quickrun][Quickrun]]. Output is show in a popup window.
|
|
|
|
|
|
|
|
Quickrun includes support for many languages, usually by sending text directly
|
|
|
|
to interpreters or compilers. However, occasionally, you'll find a language
|
|
|
|
without support (like [[https://crystal-lang.org/][Crystal]]), or a language with better Emacs integration
|
|
|
|
(like elisp).
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2021-10-16 01:29:27 +02:00
|
|
|
To define a "runner":
|
|
|
|
#+begin_src emacs-lisp
|
2019-01-03 01:58:43 -05:00
|
|
|
(set-eval-handler! 'crystal-mode
|
|
|
|
'((:command . "crystal")
|
|
|
|
(:exec . "%c %s")
|
|
|
|
(:description . "Run Crystal script")))
|
2021-10-16 01:29:27 +02:00
|
|
|
#+end_src
|
2017-05-25 20:08:50 +02:00
|
|
|
|
|
|
|
A simpler version is simply to use the path to the binary:
|
2021-10-16 01:29:27 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-01-03 01:58:43 -05:00
|
|
|
(set-eval-handler! 'groovy-mode "groovy")
|
2021-10-16 01:29:27 +02:00
|
|
|
#+end_src
|
2017-05-25 20:08:50 +02:00
|
|
|
|
|
|
|
Or if you'd rather run an elisp command:
|
2021-10-16 01:29:27 +02:00
|
|
|
#+begin_src emacs-lisp
|
2019-01-03 01:58:43 -05:00
|
|
|
(set-eval-handler! 'emacs-lisp-mode #'+emacs-lisp-eval)
|
2021-10-16 01:29:27 +02:00
|
|
|
#+end_src
|
2017-05-25 20:08:50 +02:00
|
|
|
|
2019-10-26 01:45:09 -04:00
|
|
|
* TODO Troubleshooting
|
2021-10-16 01:29:27 +02:00
|
|
|
/There are no known problems with this module./ [[doom-report:][Report one?]]
|
|
|
|
|
|
|
|
* Frequently asked questions
|
|
|
|
/This module has no FAQs yet./ [[doom-suggest-faq:][Ask one?]]
|
|
|
|
|
|
|
|
* TODO Appendix
|
|
|
|
#+begin_quote
|
|
|
|
🔨 This module has no appendix yet. [[doom-contrib-module:][Write one?]]
|
|
|
|
#+end_quote
|