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

Commit 8c63a04

Browse files
committed
feat: update emacs major mode, new example examples/aoc-24/day-01/part_02
1 parent 6f47558 commit 8c63a04

5 files changed

Lines changed: 87 additions & 9 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)

‎editor-plugins/emacs/lbd-mode.el‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
;;; lbd-mode.el --- Major mode for Lambda-Discipline Language -*- lexical-binding: t; -*-
22
;;
3-
;; Author: NinthCircle
3+
;; Author: Lakshay Chauhan
44
;; Version: 0.1
55
;; Keywords: languages
6-
;; URL: https://gitlab.com/ninthcircle/lambda-discipline/-/tree/master/editor-plugins/emacs/lbd-mode.el
6+
;; URL: https://raw.githubusercontent.com/nos1dot618/lambda-discipline/refs/heads/master/editor-plugins/emacs/lbd-mode.el
77

88
(defvar lbd-mode-hook nil)
99

@@ -31,12 +31,15 @@
3131
"Syntax table for lbd-mode.")
3232

3333
;; Comment settings
34-
(setq-local comment-start "-- ")
34+
(setq-local comment-start "--")
3535
(setq-local comment-end "")
3636

3737
;; Font lock
3838
(defconst lbd--keywords
39-
'("true" "false" "if_then" "pair" "first" "second" "use")
39+
'("true" "false" "if_then" "pair" "first" "second" "use"
40+
"print" "add" "sub" "mul" "cmp" "if_zero" "sort" "parse_float"
41+
"list" "list_size" "list_get" "list_remove" "list_append" "map" "transpose" "zip" "foldr"
42+
"slurp_file" "lines" "split")
4043
"Language keywords for lbd-mode.")
4144

4245
(defvar lbd-font-lock-keywords
100 KB
Loading

‎examples/aoc-24/day-01/part_02.lbd‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Problem Link: <https://adventofcode.com/2024/day/1>
2+
3+
-- TODO: This is super slow, optimize this
4+
5+
use "examples/std.lbd"
6+
7+
content: String = (slurp_file "examples/aoc-24/day-01/input.txt")
8+
entries: List = (lines content)
9+
10+
tmp: String -> Any = \x: String. (rot_2 split " " x)
11+
cols: List = (transpose (map tmp entries))
12+
13+
tmp2: List -> Any = \x: List. (map parse_float x)
14+
lists: List = (map tmp2 cols)
15+
16+
eq2: Float -> Float -> Float = \x: Float. \y: Float. (if_then (eq y x) 1 0)
17+
add2: Float -> Float -> Float = \x: Float. \y: Float. (add y x)
18+
19+
count: List -> Any -> Float = \xs: List. \x: Any. (foldr add2 0 (map (eq2 x) xs))
20+
21+
l0: List = (list_get lists 0)
22+
l1: List = (list_get lists 1)
23+
24+
tmp3: List -> Float = \xs: List. (mul (list_get xs 0) (list_get xs 1))
25+
26+
(print "Answer: " (foldr add2 0 (map tmp3 (zip (list l0 (map (count l1) l0))))) "\n")

0 commit comments

Comments
 (0)