2

I am interested in creating an emacs extension that delegates the work to an external program.

I have my logic as a library, however, written in Common Lisp. If I can directly call the CL library from Elisp, that would be simpler for me; otherwise, I can use a client/server architecture.

I have looked into emacs LSP implementation, but I couldn't find a simple entry on how to do it.

Drew
  • 29,895
  • 7
  • 74
  • 104
user2232305
  • 319
  • 2
  • 11
  • Before going client/server, what about building a binary of the CL app and calling it from Elisp? The binary startup time will be very fast. – Ehvince Jan 24 '21 at 15:29
  • See also `slime-eval`, if you use Slime to start a CL process. More pointers: https://www.reddit.com/r/lisp/comments/kce20l/what_is_the_best_way_to_call_common_lisp_inside/ – Ehvince Jan 24 '21 at 15:31
  • I am fine calling a CL binary, as long as I can get the output and use it in my elisp function. If that's possible can you give me some pointers on how to make a binary out of CL app? And how can I use it back elisp? – user2232305 Jan 24 '21 at 16:21

1 Answers1

4

You could build a binary of your CL app and call it from the Elisp side. It seems to suit you fine, so here are more pointers:

How to build a Common Lisp executable

short answer: see https://lispcookbook.github.io/cl-cookbook/scripting.html

Building a binary is done by calling sb-ext:save-lisp-and-die from the terminal (and not from a running image). Note that this function name changes on the different implementations.

ASDF has a directive that allows to do it declaratively, and portably (for all implementations). You add 3 lines in your .asd file and you mention what is your program's entry point. For example:

;; myprogram.asd
  :build-operation "program-op" ;; leave this as is.
  :build-pathname "myprogram"
  :entry-point "myprogram::main"  ;; up to you to write main.

Now, call (asdf:make :myprogram).

See a more complete example in the Cookboo.

Call it from Elisp

See https://wikemacs.org/wiki/Emacs_Lisp_Cookbook#Processes

This returns the output as a string:

  (shell-command-to-string "seq 8 12 | sort")

Full documentation: https://www.gnu.org/software/emacs/manual/html_node/elisp/Synchronous-Processes.html

Other approaches

Other approaches are discussed here: https://www.reddit.com/r/lisp/comments/kce20l/what_is_the_best_way_to_call_common_lisp_inside/

For example, one could start a lisp process with Slime and execute CL code with slime-eval.

Ehvince
  • 17,274
  • 7
  • 58
  • 79