Skip to content

Commit 54088cd

Browse files
committed
WIP Emacs utilities to remove newlines when sending code to SEPL
1 parent 2b0dda0 commit 54088cd

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

emacs/deps.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
(require 'package)
2+
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
3+
("melpa" . "https://melpa.org/packages/")))
4+
(package-initialize)
5+
(package-refresh-contents)
6+
(package-install 's)
7+
(package-install 'dash)

emacs/sepl-mode.el

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
(require 's)
2+
(require 'dash)
3+
4+
(defun sepl--remove-comments (code)
5+
"Removes comments and newlines from code given in CODE. After execution, all lines will be concatenated to a single line."
6+
(s-join " "
7+
(-map (lambda (line)
8+
(car (s-split ";" line)))
9+
(s-lines code))))
210

311
(defun sepl-eval-sexp ()
412
(interactive)
@@ -7,7 +15,7 @@
715
(backward-sexp)
816
(point)))
917
;; sepl requires single lines
10-
(code (s-replace "\n" " " (buffer-substring start end)))
18+
(code (sepl--remove-comments (buffer-substring start end)))
1119
(tmp-buf (get-buffer-create "*sepl-tmp-buf*")))
1220
(when (boundp 'sepl-repl-process)
1321
(comint-redirect-send-command-to-process code tmp-buf sepl-repl-process nil t)
@@ -17,6 +25,7 @@
1725
(message "=> %s" (s-replace "\n" "\n " (s-trim (buffer-string))))))
1826
(kill-buffer tmp-buf)))
1927

28+
;; TODO: how to handle lines with comments?
2029
(defun sepl-eval-buffer ()
2130
(interactive)
2231
(when (boundp 'sepl-repl-process)
@@ -48,7 +57,8 @@
4857
(require 'scheme)
4958
(setq-local font-lock-keywords scheme-font-lock-keywords)
5059

51-
)
60+
;; TODO: completion of built-ins?
61+
)
5262

5363
(defcustom sepl-program-bin "/Users/marie/Programming/Rust/shade-eval-print-loop/target/debug/shade-eval-print-loop"
5464
"Path to the SEPL binary"

emacs/tests.el

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
;; Basic unit tests for Elisp code
2+
(require 'sepl-mode)
3+
(require 's)
4+
5+
(ert-deftest remove-comments-single-line-test ()
6+
(should (s-equals? "hi there"
7+
(sepl--remove-comments "hi there")))
8+
(should (s-equals? "(+ 2 3)"
9+
(sepl--remove-comments "(+ 2 3)")))
10+
(should (s-equals? ""
11+
(sepl--remove-comments "; Hi there"))))
12+
13+
(ert-deftest remove-comments-multiple-lines-test ()
14+
(should (s-equals? "(+ 1 2) 2 (define (square x) (* x x))"
15+
(sepl--remove-comments "(+ 1 2)\n2\n(define (square x)\n (* x x))"))))

0 commit comments

Comments
 (0)