owmagow · 2022-12-06 17:57
I am aware of the cl-lib library, and it is pretty cool if you want to write elisp code that is pretty close to Common Lisp code.
HOWEVER, is there any sort of interop library that would allow one to program IN Common Lisp to extend emacs? I would think such an interop system would allow one to interact with Emacs' buffer functionality in particular.
I'm not really sure that such a thing is very practical or would interest many people. But I recently wrote a Python interop library that allows me to use Python libraries from within Common Lisp, and I found it really helped my own understanding of Lisp quite a bit.
I'm just wondering if anything like that has been done. So far, my google searches don't reveal much.
deaddyfreddy · 2022-12-06 18:08
https://git.sr.ht/~hajovonta/glue/
tonicinhibition · 2022-12-06 18:45
That's really cool that you wrote some Python interop library. How did you approach that?
owmagow · 2022-12-06 18:45
Yep, that's a pretty cool start! Thank for pointing that out.
owmagow · 2022-12-06 18:48
There's actually a few out there better than mine. Mine was for the sole purpose of giving me access the the rawpy library, which is used to process RAW camera images.
It basically just runs python processes in asynchronous or synchronous threads and send information back and forth via socket files. It wasn't too complicated.
tonicinhibition · 2022-12-06 19:56
In that case, I'm wondering how you would share memory and variables with the host process. Are you in an isolated bubble when you're running your Python code?
If you *do* want to be able to interact with Emacs, it seems to me that you would need to use macros.
For instance, I wrote a compatibility layer between Common Lisp and AutoLisp that allows me to yank functions from my AutoCAD projects and run them in SLIME. This is basically just a few macros that redefine things like `defun`, because the function signatures and scope rules are different.
To avoid clobbering the global `defun` I use namespaces. Emacs does not have proper namespaces; we use naming conventions as an approximation. This appears to be the strategy taken by `cl-lib`.
If your issue is that you don't like typing `cl-` before your constructs you could write a very tiny transpiler that generates `cl-lib` compatible code given your Common Lisp source as input. Anything you need to implement that is missing could then be pushed upstream to `cl-lib`.
Beyond that is where my understanding hits a wall. You might look into [Guile Emacs](https://www.emacswiki.org/emacs/GuileEmacs#h5o-4) to see how they handle changes to the Lisp Engine itself.
EDIT
There's a comment in [this HN](https://news.ycombinator.com/item?id=23304457) thread by *sillysaurusx* that discusses implementing and porting Lisp dialects from with Emacs.
owmagow · 2022-12-06 21:21
As for Python code, I don't really share memory (at least not in an intentional way) or variables. I simply pipe data back and forth.
So, if I synchronously run python code that is supposed to output a list, the CL program needs to know to expect a list and do any necessary conversions or tweaks on the CL side.
Or if the CL program needs to send an integer to python, the python process needs to be equipped to type-test it and do any necessary conversions.
That's probably not very elegant, but I don't know a ton about how these things are *supposed* to work. I just winged it as best I could so that I could use the Python libraries I needed.
If you look up the library py4cl, I sort of got some inspiration from that and made my own take on it.
As for cl-lib, I like it a lot and use it pretty often.
I mostly am just wondering if any more sophisticated interop stuff is already out there and brainstorming if it even makes sense to create interop between the two systems so that someone who is really all about CL could just stick with it and write utilities that extend emacs using without having to deviate from the ANSI standard (and essentially know two languages) to do so.
Since I think a lot of LISP programmers gravitate towards emacs anyways, it might be a cool thing to have.
klikklakvege · 2022-12-12 07:35
If i would like to extend emacs in common lisp i wouldn't use emacs but lem
owmagow · 2022-12-12 13:56
I did not know about Lem. I’ll check it out. Thank you.