Skip to content

Commit 3f61ea5

Browse files
authored
feat(repl): Add the Elisp REPL command (#210)
* feat(repl): Add the Elisp REPL command * fix: Update syntax and rely on gnu * fix more syntax * ensure skip all input
1 parent 2a4cf40 commit 3f61ea5

File tree

18 files changed

+118
-25
lines changed

18 files changed

+118
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1414
* feat(_prepare.el): Add program temp buffer (6262821596edb48d4f3b9bc61405129e084350b1)
1515
* fix(indent.el): Further improve indent-lint (c0bf56ccc0c47846cd314067fde6ee4eeedee5aa)
1616
* fix: Compatible to Emacs 26.x (#209)
17+
* feat(repl): Add the Elisp REPL command (#210)
1718

1819
## 0.9.x
1920
> Released Nov 17, 2023

cmds/core/repl.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (C) 2024 the Eask authors.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3, or (at your option)
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
"use strict";
19+
20+
exports.command = ['repl', 'ielm'];
21+
exports.desc = UTIL.hide_cmd('Start the Elisp REPL');
22+
23+
exports.handler = async (argv) => {
24+
await UTIL.e_call(argv, 'core/repl');
25+
};

docs/content/en/Getting-Started/Commands-and-options.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,9 @@ $ eask [GLOBAL-OPTIONS] concate [FILES..]
292292

293293
# 🚩 Execution
294294

295-
Commands allow you execute on top of Eask core.
295+
Commands allow you to execute on top of the Eask core.
296296

297-
Basically, this allow you to do anything you want!
297+
Basically, this allows you to do anything you want!
298298

299299
## 🔍 eask load
300300

@@ -328,6 +328,16 @@ Evaluate `FORM` as a lisp form.
328328
$ eask [GLOBAL-OPTIONS] eval [FORM]
329329
```
330330

331+
## 🔍 eask repl
332+
333+
Start the Elisp REPL.
334+
335+
```sh
336+
$ eask [GLOBAL-OPTIONS] repl [FILES..]
337+
```
338+
339+
Alias: `ielm`
340+
331341
## 🔍 eask run script
332342

333343
Run the script.

docs/content/zh-TW/Getting-Started/Commands-and-options.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ $ eask [GLOBAL-OPTIONS] emacs [ARGUMENTS ...]
324324
$ eask [GLOBAL-OPTIONS] eval [FORM]
325325
```
326326

327+
## 🔍 eask repl
328+
329+
啟動 Elisp REPL。
330+
331+
```sh
332+
$ eask [GLOBAL-OPTIONS] repl [FILES..]
333+
```
334+
335+
別名: `ielm`
336+
327337
## 🔍 eask run script
328338

329339
運行腳本。

lisp/_prepare.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ These commands will first respect the current workspace. If the current
159159
workspace has no valid Eask-file; it will load global workspace instead."
160160
(member (eask-command) '("init/cask" "init/eldev" "init/keg"
161161
"init/source"
162-
"bump" "cat" "keywords"
162+
"bump" "cat" "keywords" "repl"
163163
"generate/ignore" "generate/license"
164164
"test/melpazoid")))
165165

lisp/core/repl.el

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
;;; core/repl.el --- Start the Elisp REPL -*- lexical-binding: t; -*-
2+
3+
;;; Commentary:
4+
;;
5+
;; Command use to start the Elisp REPL,
6+
;;
7+
;; $ eask repl
8+
;;
9+
10+
;;; Code:
11+
12+
(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
13+
(load (expand-file-name "_prepare.el"
14+
(locate-dominating-file dir "_prepare.el"))
15+
nil t))
16+
17+
(defvar eask--repl-old-pos nil
18+
"Record the last position to output on the screen for the `ielm' buffer.")
19+
20+
(defun eask--repl-output ()
21+
"Print the REPL result to screen."
22+
(unless eask--repl-old-pos (setq eask--repl-old-pos (point-min)))
23+
(with-current-buffer "*ielm*"
24+
(goto-char eask--repl-old-pos)
25+
(while (not (eobp))
26+
(let ((line (thing-at-point 'line t)))
27+
(unless (string-prefix-p "ELISP> " line)
28+
(eask-print line)))
29+
(forward-line 1)
30+
(end-of-line))
31+
;; Record last output position
32+
(setq eask--repl-old-pos (point))))
33+
34+
(eask-start
35+
(require 'ielm)
36+
(ielm)
37+
(eask--repl-output)
38+
(let ((input))
39+
(while (setq input (read-from-minibuffer (ansi-blue "ELISP> ")))
40+
(with-current-buffer "*ielm*"
41+
(insert input)
42+
(setq eask--repl-old-pos (point)) ; skip all input
43+
(eask--silent (ielm-send-input))
44+
(eask--repl-output)))))
45+
46+
;;; core/repl.el ends here

test/checker/dsl/Eask

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
(script "test" "echo \"Error: no test specified\" && exit 1")
2828
(script "test" "echo \"Error: no test specified\" && exit 1")
2929

30-
(source "gnu") ; duplicate archives
31-
(source "gnu")
30+
(source 'gnu) ; duplicate archives
31+
(source 'gnu)
3232

3333
(source "magic-archive") ; Unkown archive
3434

test/color/Eask

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
(package-file "color.el")
66

7-
(source "gnu")
7+
(source 'gnu)
88

99
(depends-on "emacs" "26.1")

test/commands/exec/Eask

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
(exec-paths "./bin/")
1111

12+
(source 'gnu)
1213
(source 'melpa)
1314

1415
(depends-on "emacs" "26.1")

test/commands/outdated_upgrade/Eask

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
(package-file "outdated-upgrade.el")
66

7-
(source "gnu")
8-
(source "melpa")
7+
(source 'gnu)
8+
(source 'melpa)
99

1010
(depends-on "f")
1111
(depends-on "s")

0 commit comments

Comments
 (0)