Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

Writing an Emacs Backend Plugin in Common Lisp

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.

question from:https://stackoverflow.com/questions/65870752/writing-an-emacs-backend-plugin-in-common-lisp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...