2019-01-03 01:58:43 -05:00
|
|
|
#+TITLE: feature/eval
|
|
|
|
#+DATE: February 13, 2017
|
|
|
|
#+SINCE: v2.0
|
|
|
|
#+STARTUP: inlineimages
|
|
|
|
|
|
|
|
* Table of Contents :TOC_3:noexport:
|
|
|
|
- [[Description][Description]]
|
|
|
|
- [[Module Flags][Module Flags]]
|
|
|
|
- [[Plugins][Plugins]]
|
|
|
|
- [[Hacks][Hacks]]
|
|
|
|
- [[Prerequisites][Prerequisites]]
|
|
|
|
- [[Features][Features]]
|
|
|
|
- [[Inline Code Evaluation][Inline Code Evaluation]]
|
|
|
|
- [[REPLs][REPLs]]
|
|
|
|
- [[Configuration][Configuration]]
|
|
|
|
- [[Register a REPL for a major-mode][Register a REPL for a major-mode]]
|
|
|
|
- [[Change how code is evaluated in a major mode][Change how code is evaluated in a major mode]]
|
|
|
|
- [[Troubleshooting][Troubleshooting]]
|
|
|
|
|
|
|
|
* Description
|
|
|
|
This modules adds inline code evaluation support to Emacs, and supplies a
|
|
|
|
universal interface for opening and interacting with REPLs.
|
|
|
|
|
|
|
|
** Module Flags
|
|
|
|
This module has no flags.
|
|
|
|
|
|
|
|
** Plugins
|
|
|
|
+ [[https://github.com/syohex/emacs-quickrun][quickrun]]
|
|
|
|
|
|
|
|
** Hacks
|
|
|
|
+ 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
|
|
|
|
underlying process is finished executing the code.
|
|
|
|
|
|
|
|
* Prerequisites
|
|
|
|
This module has no direct prerequisites.
|
|
|
|
|
|
|
|
However, specific languages may require additional setup. Check the
|
|
|
|
documentation of that language's module for details.
|
|
|
|
|
|
|
|
* Features
|
|
|
|
** Inline Code Evaluation
|
2017-12-31 23:07:28 -05:00
|
|
|
Quickrun can be invoked via:
|
|
|
|
+ ~M-x +eval/buffer~ (or ~gR~, or ~M-r~)
|
|
|
|
+ ~M-x +eval/region~
|
|
|
|
+ ~M-x +eval/region-and-replace~
|
|
|
|
+ Evil users can use the ~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:
|
|
|
|
+ =SPC o r= or ~:repl~ will open a REPL in a popup window. =C-u SPC o r= or
|
|
|
|
~:repl!~ 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.
|
2019-02-18 01:56:38 -05:00
|
|
|
+ ~M-x +eval/open-repl-other-window~
|
|
|
|
+ ~M-x +eval/open-repl-same-window~
|
2019-01-03 01:58:43 -05:00
|
|
|
+ ~M-x +eval/send-region-to-repl~ while a selection (and REPL) is active
|
|
|
|
|
|
|
|
* Configuration
|
|
|
|
** 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:
|
|
|
|
=SPC o r=. These will open a REPL in a popup window.
|
2019-01-03 01:58:43 -05:00
|
|
|
|
|
|
|
#+begin_quote
|
|
|
|
You can simply call that mode's REPL command manually. e.g. ~M-x ielm~, but
|
|
|
|
#+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-01-05 16:55:01 -05:00
|
|
|
~(set-repl-handler! MAJOR-MODE FUNCTION)~
|
2017-08-21 20:07:07 +02:00
|
|
|
|
2019-01-05 16:55:01 -05:00
|
|
|
FUNCTION should return a repl buffer. Any window changes in this function are
|
|
|
|
ignored, then the REPL is opened in a popup window.
|
2017-05-25 20:08:50 +02:00
|
|
|
|
|
|
|
#+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)
|
2017-05-25 20:08:50 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
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
|
|
|
|
2017-12-31 23:07:28 -05:00
|
|
|
Here's how you define a "runner":
|
2017-05-25 20:08:50 +02:00
|
|
|
|
|
|
|
#+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")))
|
2017-05-25 20:08:50 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
A simpler version is simply to use the path to the binary:
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2019-01-03 01:58:43 -05:00
|
|
|
(set-eval-handler! 'groovy-mode "groovy")
|
2017-05-25 20:08:50 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Or if you'd rather run an elisp command:
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2019-01-03 01:58:43 -05:00
|
|
|
(set-eval-handler! 'emacs-lisp-mode #'+emacs-lisp-eval)
|
2017-05-25 20:08:50 +02:00
|
|
|
#+END_SRC
|
|
|
|
|
2019-01-03 01:58:43 -05:00
|
|
|
* Troubleshooting
|