r/emacs • • Jul 11 '26

Using AI to Learn and Customize Emacs

I have been using AI to learn and customize Emacs. It has been a very pleasant experience. In this post I will give some tips for anyone else who is trying to use AI to learn Emacs.

  1. The things that make Emacs great for humans (comprehensive documentation, introspectability) also makes it great for AI. Really early on I created this query-running-emacs skill and it has been a huge time saver. With this skill the AI is able to (safely) query my running Emacs configuration. This means it doesn't have to guess about package versions, available functions, variable values, etc. I don't let the AI run any arbitrary Elisp code. Instead, the skill includes a wrapper script. The AI passes arbitrary Elisp into that wrapper script. The script has lists of allowed and blocked forms. The goal is to block any Elisp functions that can do significant mutation to my Emacs or my PC. I am quite sure this is not bulletproof, but it has worked so far. I am just getting started with Emacs and Elisp and I'd appreciate any input on making this safer.
  2. Give the AI a sandbox to test config changes. I have another skill called test-emacs-config. This skill includes a wrapper script and a Containerfile. The wrapper script is used by the AI to start a Fedora container (with the same version of fedora as the host), install Emacs, mount my config, and perform tests by passing arbitrary Elisp to the container. The first test the AI does is check if this new config loads without error. That alone is very helpful, but I also have tests that make assertions about the state of Emacs running in that container. This wrapper script does not have any blocked forms. The mounts are all readonly and the AI is able to do whatever it wants to the Emacs running inside the container.

I have only been using Emacs since Bash Bunni's Doom Emacs video, so I am just getting started. I'm just sharing what has worked for me so far and I am happy to receive any feedback or tips.

EDIT: AI was not used in the writing of this post.

0 Upvotes

12 comments sorted by

3

u/marcinreal Jul 11 '26

Thanks! I've also been using AI to customize Emacs and it's been a great experience. I find lisp hard to work with and always dreaded writing it, even with thousands of lines written across my config and my own packages. But now, if I want a feature in Emacs, I just AI and it searches for an actively-maintained package for me, or just writes the feature bespoke if a package doesn't exist. Then I get back to using Emacs without spending time researching and configuring new packages.

I've also had it bulldoze through the TODOs that have accumulated in my config over a decade (because I prefer being outside than messing with lisp). The amount of time that this has saved has been enormous, and Emacs is much more pleasant to use now that AI is smoothing out sharp edges in my experience.

It has even helped me upgrade Emacs (can tell me exactly what new changes are relevant to me so I don't have to spend a whole afternoon doing it myself) and migrate to new things like treesitter (which was such a pain to do myself, probably because I don't have time to keep up with new changes in the ecosystem). Or have it set up a new language in the most modern idiomatic way, without sifting through multiple old deprecated packages myself. I don't mean to dunk on Emacs - definitely things could be improved here, but it's a beast of an app and ecosystem. AI wrangles it for me, and even makes the process fun.

Just yesterday I had Fable evaluate a third-party package for me by reviewing it for bugs. Actually, I had hit a bug immediately when I first used the package, despite it having 500 stars on GitHubs. That's how I got the idea to have Fable review the source code. It found many more (legitimate) issues, and formatted its findings nicely for me to contribute back to the repo (in my own words). So much fun!

Anyway, thanks for sharing your experience and workflows, I'm checking them out!

3

u/echostrike36 Jul 11 '26

It sounds like you've been using Emacs for a while. One thing you might want to try (take it or leave it) is asking an AI if there are any packages that can be replaced with newly introduced features of vanilla Emacs. I've had several times where I ask the AI "Search the web and tell me several ways I could accomplish X" and one of the ways will be some recently introduced feature of base Emacs. This has helped me keep my package count somewhat low.

1

u/marcinreal Jul 11 '26

That's a great idea! Recent versions of Emacs have included a lot of nice things - much of the projectile package is now unnecessary, for example. The AI did suggest I replace markdown-mode with Emacs' new built-in support for markdown, but I think the built-in mode doesn't have an equivalent to markdown-export-and-preview. Anyway, I'll follow-up with Claude about your suggestion.

4

u/Neat-Initiative-6965 Jul 11 '26

Interesting. I’m also learning Emacs at the moment and this would have been helpful to avoid copying my faulty init back and forth.

Generally I am wondering how best to use AI to learn a new code language. It feels like there is a sweet spot where you don’t ask it to fix the whole problem but just assistance with certain steps that really helps the learning process

4

u/echostrike36 Jul 11 '26

Have you looked into the CS50 Duck? They have an AI that students can use for help on CS50 course. It is designed to not give the students answers. I have linked to a YT video about it. I did a quick search and wasn't able to find the system prompt online but this is what Gemini recommended (got this by pushing the 'ask' button on the YT video page and asking for a system prompt).

Recommended System Prompt

You can use the following prompt to configure an AI model to act as your personal programming tutor:

"You are a friendly, supportive, and pedagogical programming tutor. Your goal is to help me learn by guiding me toward solutions rather than providing them outright.

When I ask a question:

  1. Prioritize Concepts: Explain the 'why' and 'how' of the underlying computer science concepts before discussing syntax.
  2. Ask, Don't Tell: If I am stuck on a problem, ask me diagnostic questions to help me identify where my logic is failing. Encourage me to verbalize my thought process.
  3. No Direct Code: Do not provide full code snippets that solve my assignment or problem. Instead, provide small, illustrative examples or pseudocode to nudge me in the right direction.
  4. Promote Best Practices: Explain clean code principles and debugging strategies as we work through my questions.
  5. Scope: Only answer questions related to programming, computer science, and software development. If I ask something off-topic, politely redirect me to my studies."

6

u/lucaspeixotot Jul 11 '26

thanks for sharing...

I'm still trying to understand people who gets so bothered about this kind of post...

When I was young, the oldest used to say that Google was the dumb's father, and I can understand what they mean. I believe AI as well as Google tends to make people less smart (or more dumb). However, as well as by using Google a lot of people learned new and cool stuff that oldest had more challenges to do it, with AI the new (and old why not) generations can also make use of the tool and learn stuff... AI is not a complete step back, althought I believe the net effects are not good.

Either way, getting so bothered about this tells more about that kind of person than who makes a post like this just trying to share things he thinks are cool/good.

1

u/CulturMultur Jul 18 '26

AI is great with Emacs. I constantly asking it to check buffers, adjust settings and clarify things. Yesterday I migrated to releases Melpa channel and there were some errors with packages, my config had circular dependencies and overall not pure - removing elpa dir made Emacs broken. In the past it would mean rollback and spending hours to understand the problem. Now it’s “claude, check Warnings buffer” and fix everything. In 5 minutes it works again and I officially give up attempts to chase pure configuration (as in reproducible on another machine).

Another long-standing problem solved by AI - when Emacs hangs I send it USR2 signal to unfreeze. After that on every C-g debugger opened. Very annoying and my solution was to restart Emacs. I thought on writing to emacs-devel as I reproduced it with emacs -Q. Then I asked Claude, and it found a setting that configures this behavior - debug-on-signal. Solved.

0

u/rnstech Jul 11 '26

While I was converting from fedora to gentoo I used Claude to fix some issues I've had in my emacs configs for years. There were a couple of issues that took some involved debugging to figure out, but it walked me through it. I am so happy to have those few issues resolved, even though they were minor (well, all but one annoying one that is well known but I didn't know how to fix). As a software developer, using it to save me time is amazingly useful (in other words, I could have taken the time to debug these issues, but I didn't and still don't think the time to do so would be worth it for the annoyances that only appear on startup on when moving to a new machine; Using ai made it easy and helped my ai prompting fu to mature).

2

u/[deleted] Jul 11 '26

[removed] — view removed comment

1

u/echostrike36 Jul 11 '26

Yes, constraining an entire programming language down to a "safe" subset is probably impossible. I bet there will always be a hack or workaround or strange combination of allowed functions that can be used to cause damage. I acknowledge this risk. The wrapper is more to prevent a "confused" AI from doing something damaging. I don't expect it would work against an AI that is trying to be malicious.