ChatGPT Emacs Integration Course

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. 📝


👤 About Me

💡 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.


🗣️ What Others Are Saying

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)


🎯 Who This Course is For

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.

✅ If You:

🎉 Then This Course is for You!

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. 💡


🏆 What You’ll Achieve

By the end of this course, you’ll:


🛠️ Build Your Own chatgpt.el Package

In 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.

✨ Key Features of chatgpt.el

Beyond its simplicity, chatgpt.el offers these key features:


📋 Let's go!

... 📄 PDF of the course and chatgpt.el codeAvailable Soon

0. 🏁 Kickoff: Building Your Own chatgpt.el Package ― 3m39s

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.

1. 📨 First Request to OpenAI Using the Chat Completion API ― 6m31s

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.

2. 🌊 Chat Completion Streaming API ― 2m56s

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. ✨

3. 🛠️ Developer and System Messages ― 4m11sAvailable Soon

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.

4. 💬 Assistant Messages ― 3m54sAvailable Soon

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!

5. 🖥️ The Basics of make-process ― 12m50sAvailable Soon

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.

6. 📤 First Request to OpenAI From Emacs Lisp ― 8m29s

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.

7. 🔄 Refactoring chatgpt-send and Introducing chatgpt-api-key ― 6m03sAvailable Soon

Let’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.

8. 🔧 Making the Prompt Dynamic in Requests ― 8m32sAvailable Soon

No 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.

9. 🖋️ Formatting Requests and Responses in Markdown ― 9m41sAvailable Soon

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!

10. 💾 Saving Requests to Disk ― 12m08sAvailable Soon

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.

11. 🗂️ The Prompt Buffer ― 16m57sAvailable Soon

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.

12. 📥 Making the Response Buffer Pop Up Upon Receipt ― 11m22sAvailable Soon

Now 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.

13. 🛠️ Handling API Errors ― 11m10sAvailable Soon

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.

14. 🕒 Timestamp Files ― 9m21sAvailable Soon

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.

15. 🔄 Overview of the Ring Package ― 7m16s

Enter 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.

16. 📜 Implementing Prompt History Feature ― 17m43sAvailable Soon

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.

17. ⏳ The Waiting Widget ― 3m56sAvailable Soon

Who 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!

18. 🔐 Managing the API Key ― 4m16sAvailable Soon

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.