Swankful Software-Individuals

Table of Contents

I spend a lot of each day using emacs. Surely my software-individuals can use emacs instead of me. Let's teach my software-individual cognitive robot to insert text into emacs buffers so I personally won't have to.

1. CONTEXT

We gotta have all of clisp common lisp, emacs, and slime (combines common lisp and emacs) as well as software-individuals.

1.1. Other article of me setting up one software-individual

1.2. Installing emacs, clisp lisp compiler and slime (in debian)

Well, these probably warrant their own articles but let's imagine debian.

sudo apt install emacs clisp slime

anyway, congratulations so far.

1.3. Software individual in slime in emacs

In reverse order.

emacs

then in emacs I might

  1. M-x slime-mode <RET> i.e. alt-x, type slime-mode, then press enter.
  2. =M-S-: (setq inferior-lisp-program "clisp -E ISO-8859-1 -modern") <RET> i.e. alt-shift-:, type (setq ..), then press enter. software-individuals uses case sensitivity, which was in vogue in the 90s and strictly uses latin1 characters (formally named ISO-8859-1)
  3. M-x slime <RET> You hopefully get it. Obviously, a buffer named slime clisp repl or something pops up.

1.3.1. Navigate to the correct directory

In the starting example linked above, we are activating the demus agent of the Screwlispbot software-individual.

Load the de facto lisp posix thing

(require "asdf")

(it's packaged with asdf, which is mostly always available)

and chdir (change directory):

(uiop:chdir #p"~/leocommunity/Screwlispbot/demus/Process/main/")

since software-individuals picks up who is doing what by the current directory.

Now that we are in the demus agent we want, load the kernel agent named remus by relative path:

(load #p"../../../remus/Startup/cl/acleo.leos")

and enter the expert shell

(cle)

I guess you saw this:

cs-user> (load #p"../../../remus/Startup/cl/acleo.leos")
;; Loading file ../../../remus/Startup/cl/acleo.leos ...
;;  Loading file ../../Startup/cl/bootfuns.leos ...
;;  Loaded file ../../Startup/cl/bootfuns.leos
****************************************************************************
Now starting up a Leonardo session  --  please stand by

Welcome to a session with the Leonardo software individual Pawn-74
The session is done with the individual's agent called demus
This is session number 47 with this agent

Loading of server and communication support failed.
Could not check in with the Registrar since communication facility not operational

This session operates on a Clisp implementation of CommonLisp.
Since Leonardo was initially developed on the Allegro CommonLisp implementation,
some facilities are not available here, and there is still some danger of
remaining bugs due to inconsistencies of the implementations.
The command-line executive will not start automatically; please type (cle) in
order to start it.


;; Loaded file ../../../remus/Startup/cl/acleo.leos
#P"~/leocommunity/Screwlispbot/remus/Startup/cl/acleo.leos"
cs-user> (cle)
Starting or resuming interaction using the CLE command-loop
****************************************************************************

ses.001) 

Okay! Beginning over! This is why I am adding a major mode so that you do not have to personally set anything up yourself in the future.

2. Teach Screwlispbot software-individual about emacs and swank

In particular, I would like to be able to insert text into a different emacs buffer.

2.1. Add emacs-kb emacs knowledgebase to demus

ses.029) crek emacs-kb
Load-ef: kb-catal at Defblock/kb-catal.leo
;; Loading file ../../../remus/Process/main/Defblock/cl/kb-catal.leos ...
;; Loaded file ../../../remus/Process/main/Defblock/cl/kb-catal.leos
writeloc-file-leo:  Defblock/kb-catal.leo
writeloc-file-leos: Defblock/cl/kb-catal.leos
writeloc-file-leo:  ../../../demus/Emacs/emacs-kb.leo
writeloc-file-leos: ../../../demus/Emacs/cl/emacs-kb.leos

2.2. Add an entityfile about swank

swank is the wire protocol connection by which emacs talks to common lisp out of interest. Mostly you don't think about this, but I want Screwlispbot to send instructions to emacs

ses.030) loadk emacs-kb
Load-ef: emacs-kb at ../../../demus/Emacs/emacs-kb.leo

ses.031) setk emacs-kb
Done

ses.032) crefil swank
Load-ef: emacs-kb at ../../../demus/Emacs/emacs-kb.leo
writeloc-file-leo:  ../../../demus/Emacs/emacs-kb.leo
writeloc-file-leos: ../../../demus/Emacs/cl/emacs-kb.leos
writeloc-file-leo:  ../../../demus/Emacs/swank.leo
swank

ses.033) loadk swank
Load-ef: swank at ../../../demus/Emacs/swank.leo

ses.034) 

2.3. enable slime-evaluate-in-emacs   intermezzo

  1. M-x customize-variable <RET>
  2. slime-enable-evaluate-in-emacs
  3. Toggle it and apply/save in the customize-variable interface

(Letting common lisp control emacs lisp is not activated by default since the default behaviour is the other direction).

2.4. Add a lispdef inserto entity to the swank entityfile

Sandewall's naming scheme is "cute and short" following the unix way I guess. I am painfully copying that style.

ses.034) put inserto type lispdef
put: inserto type lispdef

ses.035) addmember (get swank contents) inserto

ses.036) writefil swank
writeloc-file-leo:  ../../../demus/Emacs/swank.leo

ses.037) 

2.5. Writing inserto's leodef

Sandewall though different people would use different editors, so this step is just "open the file in the way you like and write the single lisp definition into it, save and close it". I will continue using emacs here.

C-x C-f ~/leocommunity/Screwlispbot/demus/Emacs/swank.leo

you hopefully also see:

---------------------------------------------------------
-- swank

[: type entityfile]
[: latest-written "2025-04-27/03:04.+12"]
[: contents <swank inserto>]
[: changed-since-archived t]
[: nullvalued {has-purpose has-author requires mustload removed-entities leos-extension has-profile overlay-on overlay-types overlay-own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}]

---------------------------------------------------------
-- inserto

[: type lispdef]
[: latest-rearchived nil]

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

2.5.1. Leodef inserto

Add this leodef probably having activated M-x lisp-mode:

(leodef inserto inserto (buffer thing)
	(swank:eval-in-emacs
	 `(let* ((old (current-buffer))
		 (new ,(string buffer)))
	    (set-buffer new)
	    (insert ,(string thing))
	    (set-buffer old))))

So now your file is saved as

---------------------------------------------------------
-- swank

[: type entityfile]
[: latest-written "2025-04-27/03:04.+12"]
[: contents <swank inserto>]
[: changed-since-archived t]
[: nullvalued {has-purpose has-author requires mustload removed-entities leos-extension has-profile overlay-on overlay-types overlay-own leos-use dont-display sections local-ents purpose author latest-archived-entity latest-rearchived}]

---------------------------------------------------------
-- inserto

[: type lispdef]
[: latest-rearchived nil]

(leodef inserto inserto (buffer thing)
(swank:eval-in-emacs
`(let* ((old (current-buffer))
	(new ,(string buffer)))
   (set-buffer new)
   (insert ,(string thing))
   (set-buffer old))))

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Reload the file and try inserto

ses.037) loadfil swank
Load-ef: swank at ../../../demus/Emacs/swank.leo
swank

ses.038) inserto *scratch* "foo bar baz"

ses.039) 

Now my scratch buffer looks like:

;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.

foo bar baz

I'm calling it a success. If we add positioning the cursor (probably just sending it to the end of the buffer) and issuing send-input for whatever mode, I figure Screwlispbot can take the emacs reigns from me.

3. Live interviews coming up with Aral Balkan, Kent Pitman and Eduardo Ochs!

(Unless you are joining me from the future, in which case check out the peertube archives https://communitymedia.video/c/screwtape_channel/videos).

The show is every Wednesday 000UTC. This is Tuesday evening in the Americas and very early morning in Europe.

I release a show toot on the Mastodon just before the show goes live, you can see some from previous episodes pinned here: https://mastodon.sdf.org/@screwtape

If you are seeing this before these three weeks of live interviews, please do ping me and the interviewee on the Mastodon with questions, notes and commentary you would like to see addressed in the interview. It's easy to get onto the Mastodon. I am as above and here, Aral (author of Kitty) is https://mastodon.ar.al/@aral (https://ar.al/), Kent is https://climatejustice.social/@KentPitman (https://www.nhplace.com/kent/, maybe https://en.wikipedia.org/wiki/Kent_Pitman), Eduardo is https://emacs.social/@eduardoochs (https://anggtwu.net/). The working sketch is

Apr 29 Aral The LLM attacks on codeberg.org projects, also smallweb
May 6 Edrx emacs ee-pitch, and asking about type theory I guess
May 13 KMP Kent's commercial research at Harlequin Inc in the 90s

in the American-evening time zone (actually the day later at 0UTC).

See you in the live chat / on the Mastodon (mutuals!) / in the archive everyone.

Author: screwlisp

Created: 2025-04-27 Sun 15:58

Validate