Skip to content

Commit

Permalink
feat(repl): Add the Elisp REPL command (#210)
Browse files Browse the repository at this point in the history
* feat(repl): Add the Elisp REPL command

* fix: Update syntax and rely on gnu

* fix more syntax

* ensure skip all input
  • Loading branch information
jcs090218 authored Jan 7, 2024
1 parent 2a4cf40 commit 3f61ea5
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* feat(_prepare.el): Add program temp buffer (6262821596edb48d4f3b9bc61405129e084350b1)
* fix(indent.el): Further improve indent-lint (c0bf56ccc0c47846cd314067fde6ee4eeedee5aa)
* fix: Compatible to Emacs 26.x (#209)
* feat(repl): Add the Elisp REPL command (#210)

## 0.9.x
> Released Nov 17, 2023
Expand Down
25 changes: 25 additions & 0 deletions cmds/core/repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (C) 2024 the Eask authors.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

"use strict";

exports.command = ['repl', 'ielm'];
exports.desc = UTIL.hide_cmd('Start the Elisp REPL');

exports.handler = async (argv) => {
await UTIL.e_call(argv, 'core/repl');
};
14 changes: 12 additions & 2 deletions docs/content/en/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,9 @@ $ eask [GLOBAL-OPTIONS] concate [FILES..]

# 🚩 Execution

Commands allow you execute on top of Eask core.
Commands allow you to execute on top of the Eask core.

Basically, this allow you to do anything you want!
Basically, this allows you to do anything you want!

## 🔍 eask load

Expand Down Expand Up @@ -328,6 +328,16 @@ Evaluate `FORM` as a lisp form.
$ eask [GLOBAL-OPTIONS] eval [FORM]
```

## 🔍 eask repl

Start the Elisp REPL.

```sh
$ eask [GLOBAL-OPTIONS] repl [FILES..]
```

Alias: `ielm`

## 🔍 eask run script

Run the script.
Expand Down
10 changes: 10 additions & 0 deletions docs/content/zh-TW/Getting-Started/Commands-and-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,16 @@ $ eask [GLOBAL-OPTIONS] emacs [ARGUMENTS ...]
$ eask [GLOBAL-OPTIONS] eval [FORM]
```

## 🔍 eask repl

啟動 Elisp REPL。

```sh
$ eask [GLOBAL-OPTIONS] repl [FILES..]
```

別名: `ielm`

## 🔍 eask run script

運行腳本。
Expand Down
2 changes: 1 addition & 1 deletion lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ These commands will first respect the current workspace. If the current
workspace has no valid Eask-file; it will load global workspace instead."
(member (eask-command) '("init/cask" "init/eldev" "init/keg"
"init/source"
"bump" "cat" "keywords"
"bump" "cat" "keywords" "repl"
"generate/ignore" "generate/license"
"test/melpazoid")))

Expand Down
46 changes: 46 additions & 0 deletions lisp/core/repl.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
;;; core/repl.el --- Start the Elisp REPL -*- lexical-binding: t; -*-

;;; Commentary:
;;
;; Command use to start the Elisp REPL,
;;
;; $ eask repl
;;

;;; Code:

(let ((dir (file-name-directory (nth 1 (member "-scriptload" command-line-args)))))
(load (expand-file-name "_prepare.el"
(locate-dominating-file dir "_prepare.el"))
nil t))

(defvar eask--repl-old-pos nil
"Record the last position to output on the screen for the `ielm' buffer.")

(defun eask--repl-output ()
"Print the REPL result to screen."
(unless eask--repl-old-pos (setq eask--repl-old-pos (point-min)))
(with-current-buffer "*ielm*"
(goto-char eask--repl-old-pos)
(while (not (eobp))
(let ((line (thing-at-point 'line t)))
(unless (string-prefix-p "ELISP> " line)
(eask-print line)))
(forward-line 1)
(end-of-line))
;; Record last output position
(setq eask--repl-old-pos (point))))

(eask-start
(require 'ielm)
(ielm)
(eask--repl-output)
(let ((input))
(while (setq input (read-from-minibuffer (ansi-blue "ELISP> ")))
(with-current-buffer "*ielm*"
(insert input)
(setq eask--repl-old-pos (point)) ; skip all input
(eask--silent (ielm-send-input))
(eask--repl-output)))))

;;; core/repl.el ends here
4 changes: 2 additions & 2 deletions test/checker/dsl/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
(script "test" "echo \"Error: no test specified\" && exit 1")
(script "test" "echo \"Error: no test specified\" && exit 1")

(source "gnu") ; duplicate archives
(source "gnu")
(source 'gnu) ; duplicate archives
(source 'gnu)

(source "magic-archive") ; Unkown archive

Expand Down
2 changes: 1 addition & 1 deletion test/color/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

(package-file "color.el")

(source "gnu")
(source 'gnu)

(depends-on "emacs" "26.1")
1 change: 1 addition & 0 deletions test/commands/exec/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

(exec-paths "./bin/")

(source 'gnu)
(source 'melpa)

(depends-on "emacs" "26.1")
Expand Down
4 changes: 2 additions & 2 deletions test/commands/outdated_upgrade/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

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

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(depends-on "f")
(depends-on "s")
Expand Down
4 changes: 2 additions & 2 deletions test/commands/search/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(package-file "search.el")

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
4 changes: 2 additions & 2 deletions test/commands/test/buttercup/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

(package-file "buttercup.el")

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(development
(depends-on "buttercup"))
Expand Down
4 changes: 2 additions & 2 deletions test/commands/test/ert-runner/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

(package-file "ert-runner.el")

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(development
(depends-on "ert-runner"))
Expand Down
4 changes: 2 additions & 2 deletions test/commands/test/ert/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

(package-file "ert.el")

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(setq network-security-level 'low) ; see https://github.com/jcs090218/setup-emacs-windows/issues/156#issuecomment-932956432
4 changes: 2 additions & 2 deletions test/error/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"0.0.1"
"Test (trigger) error on GitHub Actions")

(source "gnu")
(source "melpa")
(source 'gnu)
(source 'melpa)

(depends-on "emacs" "999.99") ; This is the error we are going to see!
6 changes: 3 additions & 3 deletions test/fixtures/mini.emacs.pkg.1/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"Test command 3."
(message "Test 3: %s" eask-rest))

(source "gnu")
(source "melpa")
(source "jcs-elpa")
(source 'gnu)
(source 'melpa)
(source 'jcs-elpa)

(depends-on "emacs" "26.1")
(depends-on "f")
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/mini.emacs.pkg.2/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
(script "test" "echo \"Have a nice day!~ ;)\"")
(script "info" "eask info")

(source "gnu")
(source "melpa")
(source "jcs-elpa")
(source 'gnu)
(source 'melpa)
(source 'jcs-elpa)

(depends-on "emacs" "26.1")
(depends-on "f")
Expand Down
2 changes: 1 addition & 1 deletion test/options/Eask
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

(package-file "options.el")

(source "gnu")
(source 'gnu)

(depends-on "emacs" "26.1")

0 comments on commit 3f61ea5

Please sign in to comment.