emacs

2025-10-21T16:00:21.188849Z

Anyone knows if there's a ready made package that lets you run Emacs commands using natural language through AI model? I made a little command like this:

(defun llm-execute-command-with-q-cli ()
    "Use Q CLI LLM to convert natural language to Emacs command."
    (interactive)
    (let* ((user-request (read-string "What do you want to do? "))
           (full-prompt (format "You are an Emacs expert. Convert this request into a single Emacs command. Reply ONLY with the elisp function call, nothing else. Examples: (save-buffers-kill-terminal) for 'quit emacs', (save-buffer) for 'save file'.\n\nUser request: %s\n\nEmacs command:" user-request))
           (raw-response (shell-command-to-string
                          (format "echo %s | q chat --no-interactive --trust-tools= 2>/dev/null"
                                  (shell-quote-argument full-prompt))))
           (clean-response (replace-regexp-in-string "\033\\[[0-9;]*m" "" raw-response))
           (lines (split-string clean-response "\n" t))
           (response (string-trim
                      (replace-regexp-in-string "^.*> " "" (car (last lines))))))
      (when (y-or-n-p (format "Execute: %s? " response))
        (let ((result (eval (read response))))
          (message "Result: %s" result)
          result))))
And it works, but it's pretty slow as it delegates to a full agent cli (Q in this case) and also doesn't run async.

ericdallo 2025-10-21T16:17:50.817949Z

I believe the same could be achieve with ECA after https://github.com/editor-code-assistant/eca-emacs/issues/62, and it's not hard to support it, it would be async and have all ECA features in the background (model choose, behaviors, MCP etc)

2025-10-21T16:28:08.209149Z

Right I could then use that under the hood. Though it be nice to not even have to wrap this in the command haha. Maybe another way would be to have an Emacs eval tool ? So you could just ask the same chat to run things in your emacs?

ericdallo 2025-10-21T16:29:23.147229Z

not sure I got because you would have access to a elisp function which would return a string, then you would be able to do whatever you want with that

2025-10-21T16:29:41.127129Z

Motivation is, I often forget the non intuitive names of emacs commands. Like what's the command to reload file from disk. I was thinking, M-x is a dumb fuzzy search. What if I had a M-x-like where I type natural language and it shows me the command that does it and then I don't need to remember the names.

👍 1
ericdallo 2025-10-21T16:29:48.085039Z

ah got it, yeah, ECA support custom tools, so you could create a tool that do elisp things I guess

2025-10-21T16:31:08.499619Z

But ya, if there was just a way to send prompt and get response back I could update my above function to use that instead of using a shell command.

2025-10-21T16:31:45.438749Z

I would say for my use case, I wouldn't want any tools use, and I wouldn't want any "turn", it should be single question/answer.

2025-10-21T16:32:16.000689Z

But also, it shouldn't go into the same context, each invocation should be a clean context.

ericdallo 2025-10-21T16:32:49.171009Z

makes sense

2025-10-21T16:40:56.557359Z

Probably being able to choose the model.would be nice, haiku is probably enough. And maybe a separate system prompt input from user prompt could be convenient, but I can also do string concat beforehand.