Emacs Lisp: How, an interactive buffer with REPL?

Imagine a dunnet.el game, Eliza's doctor or IELM mode ...; This is by evaluating answers and asking new questions on the main buffer, and then do some things according to their elisp rules.

I would like to create something like an interactive assistant, BUT DO NOT request from the minibuffer how (interactive) (does not Mx) ... I need some kind of REPL loop. So, the question is how to get interaction with the working buffer (main screen), like any text conversation / adventure, but to call my defun'ed functions along the way.

So, I need a basic elisp skeleton to create a custom REPL. The goal is to make a natural language assistant, then parse the anwsers and do some actions according to the rules.

Thank you for your time,

Steve,

+8
emacs lisp interactive read-eval-print-loop buffer
source share
3 answers

Note ielm, which is an elisp repeat included in emacs.

+5
source share

Depending on what can go on in your buffer, can you just give it the main mode with the corresponding return re-bind? (This answer is vaguely inspired by Lisp-Interaction-Mode Cj)

+2
source share

You must bind all the keys that are used to move in the buffer, for example Cp Cn, Up Down Arrows / page up / down just bind them to (lambda ()) . change function for Cb and Cf (left right arrow) if the cursor position is at the beginning or end of the line. And associate the Return key with a function that reads the current line from the end to the optional prompt (you can use Regex to delete the prompt), do whatever you want with that line, and then go to the next line in the buffer and print the result.

0
source share

Source: https://habr.com/ru/post/651122/


All Articles