doomemacs/modules/tools/eval
Henrik Lissner 82ae3a73f3
def-advice!->defadvice! & conform to new advice conventions
This commit does two things:

- Renames def-advice! to defadvice!, in the spirit of naming convenience
  macros after the function/macro they enhance or replace.
- Correct the names of advice functions to indicate visibility and
  intent. A public advice function like doom-set-jump-a is meant to be
  used elsewhere. A private one like +dired--cleanup-header-line-a
  shouldn't -- it likely won't work anywhere but the function(s) it was
  made to advise.
2019-07-23 17:24:56 +02:00
..
autoload Minor tweaks across the board 2019-05-21 00:34:32 -04:00
config.el def-advice!->defadvice! & conform to new advice conventions 2019-07-23 17:24:56 +02:00
packages.el 💥 Remove :feature category 2019-04-24 18:16:04 -04:00
README.org 💥 Remove :feature category 2019-04-24 18:16:04 -04:00

tools/eval

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

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

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.

REPLs

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.
  • M-x +eval/open-repl-other-window
  • M-x +eval/open-repl-same-window
  • 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).

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.

You can simply call that mode's REPL command manually. e.g. M-x ielm, but

Otherwise, you can define your own for a specified major mode:

(set-repl-handler! MAJOR-MODE FUNCTION)

FUNCTION should return a repl buffer. Any window changes in this function are ignored, then the REPL is opened in a popup window.

(defun +lua/open-repl ()
  (interactive)
  (lua-start-process "lua" "lua")
  (pop-to-buffer lua-process-buffer))

(set-repl-handler! 'lua-mode #'+lua/open-repl)

Change how code is evaluated in a major mode

Run regions or entire buffers with 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 Crystal), or a language with better Emacs integration (like elisp).

Here's how you define a "runner":

(set-eval-handler! 'crystal-mode
  '((:command     . "crystal")
    (:exec        . "%c %s")
    (:description . "Run Crystal script")))

A simpler version is simply to use the path to the binary:

(set-eval-handler! 'groovy-mode "groovy")

Or if you'd rather run an elisp command:

(set-eval-handler! 'emacs-lisp-mode #'+emacs-lisp-eval)

Troubleshooting