Skip to content
This repository was archived by the owner on Oct 12, 2026. It is now read-only.

Commit e430b30

Browse files
committed
Add Inferior REPL for Emacs
1 parent 879cd09 commit e430b30

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

‎editor-plugins/emacs/README.md‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
## Thumbnail
1+
## Lambda Discipline Major Mode for Emacs
22

33
![Thumbnail](./resources/thumbnail.png)
44

5-
## Getting Started
6-
7-
Right now the only way to use this is to:
5+
### Getting Started
86

97
1. `C-x C-f lbd-mode.el RET`
108
2. `M-x eval-buffer RET`
11-
3. `M-x lbd-mode RET`
9+
3. `M-x lbd-mode RET`
10+
11+
## Running the REPL inside Emacs
12+
13+
![Thumbnail](./resources/repl_thumbnail.png)
14+
15+
To interact with the `lambda-discipline` REPL directly inside Emacs, you can use the provided `lbd-inf-repl.el` script. This sets up an **inferior REPL buffer** powered by `comint-mode`.
16+
17+
### Getting Started
18+
19+
1. `C-x C-f lbd-inf-repl.el RET`
20+
2. `M-x eval-buffer RET`
21+
3. `M-x lbd-run-inf-repl RET`
22+
23+
This will open a buffer called `*lbd*` and start the REPL using `./cmake-build-debug/lbd.exe --repl` with the project root (`../../`) as the working directory.
24+
25+
### Sending Code to the REPL
26+
27+
- Select a region in your buffer and press `C-c C-e` to send it to the REPL.
28+
- You can also type directly into the `*lbd*` buffer just like a normal shell.
29+
30+
### Notes
31+
32+
- The REPL runs with the project root set as the working directory, so relative paths (e.g. `:load examples/foo.lbd`) work the same as on the command line.
33+
- If you update the REPL binary, just restart Emacs or rerun `M-x run-lbd`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(require 'comint)
2+
3+
(defvar lbd-repl-buffer "*lbd*"
4+
"Buffer name for the lambda-discipline REPL.")
5+
6+
(defvar lbd-root-dir
7+
(expand-file-name "../../"
8+
(file-name-directory (or load-file-name buffer-file-name)))
9+
"Root directory of the lambda-discipline project.")
10+
11+
(defun lbd-run-inf-repl ()
12+
"Run an inferior lambda-discipline REPL inside Emacs, rooted at `lbd-root-dir`."
13+
(interactive)
14+
(let* ((default-directory lbd-root-dir) ; set working dir
15+
(exe (expand-file-name "./cmake-build-debug/lbd.exe" lbd-root-dir)))
16+
(unless (comint-check-proc lbd-repl-buffer)
17+
(set-buffer
18+
(apply #'make-comint "lbd" exe nil '("--repl"))))
19+
(pop-to-buffer lbd-repl-buffer)))
20+
21+
(defun lbd-send-region (start end)
22+
"Send the current region to the lbd process."
23+
(interactive "r")
24+
(comint-send-region (get-buffer-process lbd-repl-buffer) start end)
25+
(comint-send-string (get-buffer-process lbd-repl-buffer) "\n"))
26+
27+
(define-key global-map (kbd "C-c C-e") #'lbd-send-region)
100 KB
Loading

0 commit comments

Comments
 (0)