doomemacs/modules/feature/eval
Henrik Lissner d443aed25c
feature/eval: improve compatibility with feature/popups
This makes quickrun, *doom eval* and *Pp Eval Output* buffers behave
better.

Eval output buffers should a) shrink themselves to the size of their
output (within reason), b) *not* grab focus, and c) be easy to close
from afar with C-g/Escape.

Gotchas:

1. Quickrun gets output asynchronously, so we shrink it on
   quickrun-after-run-hook, not in the popup rule.
2. *doom eval* and *Pp Eval Output* opens with its output ready, so the
   popup system may shrink those to fit.
3. *doom eval* and *Pp Eval Output* handle window selection themselves.
   Let them by setting the select window parameter to #'ignore.
2018-01-08 17:30:54 -05:00
..
autoload Remove/replace references to doom-popup-buffer 2018-01-06 03:27:23 -05:00
config.el feature/eval: improve compatibility with feature/popups 2018-01-08 17:30:54 -05:00
packages.el
README.org Update & reformat module readmes for v2.0.9 2018-01-01 13:21:53 -05:00

:feature eval

This modules adds support for evaluating code from inside Emacs, including REPLs.

Install

This module has no external dependencies. However, specific languages may require additional setup.

Check the README.org in that language's module for details.

Usage

REPLs

Invoked via:

  • :repl (evil ex-command)
  • <leader> o r in normal mode (or visual mode, which sends the selection to the open REPL)
  • M-x +eval/open-repl
  • M-x +eval/send-region-to-repl while a selection (and REPL) is active

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.

Configuration

REPLs

REPLs are defined for most of the languages Doom supports (check its README.org to see if it does).

Otherwise, you can define your own for a specified major-mode with the :repl setting.

(set! :repl MAJOR-MODE FUNCTION)

FUNCTION must return the repl buffer. Any window changes are ignored, then handed off to shackle (assuming shackle-mode is on) to display in a popup window.

(defun +emacs-lisp/repl ()
  (interactive)
  (pop-to-buffer
   (or (get-buffer "*ielm*")
       (progn (ielm)
              (let ((buf (get-buffer "*ielm*")))
                (bury-buffer buf)
                buf)))))

(set! :repl 'emacs-lisp-mode #'+emacs-lisp/repl)

Code Evaluation

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 '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 'groovy-mode "groovy")

Or if you'd rather run an elisp command:

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