Incremental release for May/June 2025: new lessons published every few days!
Hi there! 👋 I’m Tony Aldon, a passionate Emacs enthusiast dedicated to helping you master Emacs and Emacs Lisp.
Join me on an exciting journey with the ChatGPT Emacs Integration Course and master the art of building a fully functional Emacs package from scratch.
🌟 Through
you’ll:
It can help if you know a little bit of Emacs Lisp, but this is not a requirement as we’ll meticulously write, review, and comment on each line of code. 📝
💡 With over 150 video tutorials and articles, and having spoken twice at EmacsConf, I’ve spent quite some time trying to make Emacs accessible and enjoyable for everyone. Whether you’re just starting or looking to deepen your expertise I hope this course will help you!
I'll be more than happy to engage with you; don't hesitate to contact me now! Life is too short to wait until tomorrow.
Nothing makes me happier than hearing how my tutorials have helped fellow Emacs users. 💬 Here are some of the awesome feedback I’ve received over the years:
“OK, Tony. I’ve just finished watching all 14 of your org table video, and they were fantastic. Very information-dense, little ceremony. I’ve been using org tables a lot for the last 13 years, and I learned many tricks I did not know about. Many thanks.” ― @danieldoherty5034 (Org Table Playlist)
“Thank you for posting these videos on Emacs-Lisp! I find them incredibly useful and they complement the built-in E-Lisp manual really well.” ― @cattmampbellvideo (Minibuffer Elisp Series)
“I’ve really enjoyed reading your posts lately. Thanks for making them, they’re exceptionally useful and I find myself exploring emacs functionality that I never would have found on my own.” ― @mattaccount (Emacs Lisp Articles)
“Thank you for the work you put into all of your posts. Always learning something new.” ― @Walheimat (Emacs Lisp Articles)
“Great video, I love the format: useful tips, straight to the point, increasing complexity. Well done!” ― @emodario (Inside Emacs Series)
“Thanks for your videos, they’re very useful to start playing around with elisp.” ― @francescorci6709 (Emacs Lisp Videos)
“Nice one! Your series really shows the spirit of Emacs, improving things with just a bit of code.” ― @georgH (Minibuffer Elisp Series)
“Your videos are fantastic! I’ve watched each one of them many times. Please keep up the great work! I look forward to your future content.” ― @bojinless (Inside Emacs Series)
“That was awesome, love the step by step explanation.” ― @DanGNU (Inside Emacs Series)
This course is perfect for any Emacs user who wants to dive into Emacs Lisp and start building their own custom packages. 🛠️ Whether you’re excited to integrate ChatGPT by hand or simply want more control over your Emacs setup, you’ll find everything you need here.
No deep Emacs Lisp knowledge? No problem! 🙌 If you know how to evaluate an expression and are willing to learn, you’re all set. You’ll not only gain the skills to customize Emacs to fit your exact needs but also get hands-on experience with ChatGPT, one of today’s most transformative technologies. 💡
By the end of this course, you’ll:
📚 Master Emacs Lisp: Gain a comprehensive understanding of Emacs Lisp by building a fully functional ChatGPT integration package from the ground up. This foundational knowledge will empower you to customize and extend Emacs confidently.
🔗 Seamlessly Integrate ChatGPT into Emacs: Learn how to incorporate ChatGPT into your Emacs workflow using the OpenAI API. Enhance your productivity with advanced AI functionalities directly within your favorite editor.
⚡ Handle Asynchronous Processes Efficiently: Understand how to manage asynchronous processes in Emacs, allowing you to interact with external APIs like OpenAI without disrupting your workflow. This skill ensures smooth and responsive integrations.
🔐 Securely Manage Your API Keys: Implement best practices for storing and handling your OpenAI API keys securely using Emacs’s ~/.authinfo
and ~/.authinfo.gpg
files. 🔒 Protect your sensitive information while leveraging powerful AI tools.
🛠️ Implement Robust Error Handling: Develop the ability to gracefully handle API errors and unexpected responses. 🛡️ Ensure your Emacs integrations are reliable and maintainable, providing a seamless user experience.
🎨 Customize and Enhance Your Emacs Environment: Create personalized buffers, mode-line widgets, and history features to tailor Emacs to your specific needs. 🖌️ Build a more intuitive and efficient workspace that adapts to your workflow.
📜 Maintain a Comprehensive Request History: Utilize Emacs’s ring
package to keep track of your interactions with ChatGPT. Easily navigate through previous prompts and responses, enhancing your ability to reference and build upon past conversations.
chatgpt.el
PackageIn this course, we’ll build chatgpt.el
, a package that lets you send prompts to ChatGPT directly from Emacs using the OpenAI API. 🖥️ Simply call the chatgpt
command, enter your prompt in the dedicated buffer, press C-c C-c
, and receive your response in an appended buffer seamlessly.
chatgpt.el
Beyond its simplicity, chatgpt.el
offers these key features:
~/.authinfo.gpg
for secure storage or from the plaintext ~/.authinfo
file, simplifying the setup process.M-p
and M-n
.Welcome aboard! 🎉 In this course, we’re diving into the awesome world of Emacs and ChatGPT by building our very own chatgpt.el
package. Over the next 18 lessons, we’ll take you step-by-step through the process, turning you into a pro at integrating ChatGPT right into your Emacs environment.
We kick things off by sending our very first request to OpenAI using the curl
command. 📡 It’s like chatting with ChatGPT right from your terminal! We’ll craft a simple JSON request, send it off, and see how ChatGPT responds. This gets us familiar with the basics of the Chat Completion API.
Next, we explore how to receive responses from OpenAI as a continuous stream. Instead of waiting for the full reply, we get it in real-time chunks ― perfect for creating more dynamic and responsive interactions. We’ll tweak our curl
commands to handle streaming and watch the magic happen. ✨
Here, we learn how to customize our interactions by tweaking developer and system messages. 📝 Want ChatGPT to respond in Spanish or follow specific guidelines? We’ve got you covered. It’s all about setting the right instructions to shape ChatGPT’s replies just the way you want them.
Maintaining a flowing conversation is key! In this lesson, we dive into using assistant messages to keep the context alive across multiple turns. 🔄 It’s like having a back-and-forth chat where ChatGPT remembers the conversation ― super handy for more natural and coherent dialogues!
Time to get our hands dirty with Emacs Lisp! 🧑💻 We introduce the make-process
function to run shell commands asynchronously within Emacs. This powers our ability to send requests to OpenAI without freezing up Emacs. We’ll learn how to execute commands and handle their output smoothly.
make-process
make-process
Building on what we’ve learned, we now send our first OpenAI request directly from Emacs Lisp. 🚀 No more switching to the terminal! We automate the curl
command inside Emacs, making our workflow seamless and integrated. Let’s see how Emacs can talk to ChatGPT effortlessly.
chatgpt-send
Command in chatgpt.el FileLet’s tidy up our code! 🧹 We refactor the chatgpt-send
function for better organization and introduce a dedicated variable for our OpenAI API key. Clean code is happy code, and keeping our API keys secure is a top priority. We’ll streamline our package for smoother operations.
chatgpt-send
with chatgpt-command
chatgpt-api-key
to hold OpenAI API Keychatgpt-command
Function SignatureNo more static prompts! 🔄 We make our requests dynamic by pulling prompts from the current buffer. Whether you’re brainstorming ideas or asking questions on the fly, ChatGPT’s got your back. We’ll adjust our functions to handle any input you throw its way.
chatgpt-send
Let’s make things look pretty. 🎨 We learn how to parse JSON responses and format them using Markdown within Emacs. Your chats with ChatGPT will be not only functional but also beautifully organized and easy to read. Markdown magic makes all the difference!
json-read
map-nested-elt
markdown-mode
Keeping a history is crucial! 📚 We set up our package to save every request and response to organized directories on disk. With timestamped files, we can easily browse through past interactions. It’s like having a personal chat log with ChatGPT right in Emacs.
chatgpt-send
with chatgpt-request
chatgpt-send
with chatgpt-callback
chatgpt-send
with chatgpt-json-encode
We set up the *chatgpt*
buffer to enter our prompts, positioning it neatly at the bottom of the frame for easy access. 🖥️ By defining chatgpt-mode
, we customize this buffer’s behavior and appearance, making it the perfect spot to interact with ChatGPT seamlessly within Emacs.
chatgpt
chatgpt-mode
chatgpt-model
Variablechatgpt-mode
Oncechatgpt-dir
in chatgpt-mode
chatgpt-mode-map
keymapNow that we can send prompts, we want to see responses immediately! 👀 We tweak our functions so that once ChatGPT replies, the *chatgpt[requests]*
buffer pops up automatically. No more hunting for responses ― we get them right where we need them, enhancing our workflow efficiency.
chatgpt-send
into chatgpt-send-request
Oops! 😅 Sometimes things go wrong. We equip our package to gracefully handle API errors from OpenAI. Whether it’s a wrong model or a connection hiccup, we catch these errors, display meaningful messages, and log them for future reference. This makes our integration robust and reliable.
To keep our history neat, we start using timestamp files for each request. 🕰️ These little helpers help us sort and manage our interactions chronologically without any hassle. It’s all about staying organized and making history navigation a breeze.
chatgpt-timestamp
Functionchatgpt-requests
FunctionEnter the world of rings! 💍 We explore Emacs’s built-in ring
package to manage our prompt history efficiently. Rings are perfect for handling recent interactions, allowing us to cycle through prompts effortlessly. It’s a neat way to keep track of our requests.
Now, we put rings into action by adding a prompt history feature. 🔄 With simple shortcuts like M-p
and M-n
, we can navigate through our past prompts with ease. It’s all about making our interactions with ChatGPT faster and more intuitive.
M-p
and M-n
in chatgpt-mode-map
chatgpt-history
and chatgpt-push
chatgpt-previous
Commandchatgpt-history
chatgpt-history
from DiskWho doesn’t love feedback? 😊 We create a nifty waiting widget in the mode line that flashes while we wait for ChatGPT’s response. It’s a visual cue that something awesome is happening in the background ― no more guessing if your request went through!
Security time! 🔐 We learn how to handle our OpenAI API key securely using Emacs’s ~/.authinfo
and ~/.authinfo.gpg
files. Keeping secrets safe is crucial, and we make sure our key is tucked away securely, accessible only when needed.
chatgpt-command
Function~/.authinfo
File