Skip to content

How to hack on lem itself

vindarel edited this page Jul 15, 2024 · 19 revisions

How to Hack on lem Itself

Attaching a Swank client (safest method)

Note

Starting from v2.0.0, Lem uses Micros instead of Swank

主に二つの方法があります。一つ目はlem上でサーバを起動し、別のlemやemacsのslimeから接続する。 プロセスが二つにわかれているのでlemを壊した場合も安全に編集できます。

The safest way to hack Lem is by attaching a Lisp debugger. With this method, it is safe to break Lem because the editing process is separate from the main Lem process.

Start Micros on Lem and connect from a Micros client (from another Lem process or from Emacs Slime):

  1. Start Micros on the lem process you want to debug (lem上でmicrosサーバを起動)
    • Open the Lisp REPL: M-x start-lisp-repl
    • Start the Micros client: CL-USER> (micros:create-server :dont-close t)
  2. Connect to Lem from Emacs or a second lem instance (emacsや別に起動したlemから接続する)
    • M-x slime-connect

Modifying Lem from inside Lem

二つ目の方法はただlemを起動後、ファイルを開き,編集し,式を評価するだけで出来ます。(エディタに直接変更を反映する) 今編集に使っているエディタプロセスと反映されるプロセスが同じなので、壊れた場合に影響するプロセスが編集に使っているエディタである点に注意が必要です。

You can also use Lem to modify itself. All evaluated Lisp expressions are applied immediately.

With this method, the editor and the program are the same process. Be aware that if you break something, the editor can end up in and unusable state and you can loose your work. Normally, Lem catches high-level conditions and errors and prevents breakage, but it depends on what you work on ;)

Run M-x start-lisp-repl. In a Lisp buffer, C-c C-c evaluates the expression under the cursor in the current lem Lisp image.

Loading lem (into your Lisp image)

The project's instructions show how to load and run Lem with Roswell. Here's how we can do without, with a regular SBCL REPL and Quicklisp.

This was tested on LinuxMint 20, with SBCL 2.14 from Roswell and a recent enough Roswell Quicklisp dist (ros update quicklisp).

Clone the repository with git submodules:

git clone --recursive <url to lem>

lem uses an asd file for each of its submodules, so you can't compile the main lem.asd and quickload it. You need to tell your Lisp where to find those .asd files. We have 2 ways:

  1. set CL_SOURCE_REGISTRY=/path/to/lem// before starting the repl. Two slashes at the end tell ASDF to search asd files in subdirectories.
$ cd lem/
$ CL_SOURCE_REGISTRY=$(pwd)// rlwrap sbcl
* (asdf:load-asd "/path/to/lem.asd")
* (ql:quickload "lem")
[…]
* (lem:lem)
[… builds and runs the ncurses frontend …]
  1. You can also add directories to asdf:*central-registry*. Add Lem's project root and all of its submodules/ subdirectories. For instance:
(push (uiop:getcwd) ql:*local-project-directories*)
(loop for subdir in (uiop:subdirectories "/path/to/lem/submodules/")
      do (push subdir asdf:*central-registry*))

;; and all extensions:
(loop for subdir in (uiop:subdirectories "/path/to/lem/extensions/")
      do (push subdir asdf:*central-registry*))

Now you can load the SDL2 frontend:

* (ql:quickload "lem-sdl2")

To build a binary, see the following section.

Building lem

    ./bootstrap
    ./configure

and optionally

    make install

This creates a binary in the bin/ directory.

Running the tests

Compile and load "lem-tests.asd", then from the editor:

(rove:run :lem-tests)

and from the terminal:

ros install cxxxr/sblint fukamachi/rove
rove lem-tests.asd