Generating Documents Directly From Elisp

I’ve had this in my blog queue since April but it’s too good to let it fall into the bit bucket. Álvaro Ramírez has a problem with his chatgpt-shell package. He has some documentation in the form of tables, which are easy enough to generate but the package is still under development and the documentation is always changing.

Ramírez realized that Emacs is the self-documenting editor so it should be possible to generate the documentation directly from the Elisp. That way, every time he updates the code, the documentation can be automatically regenerated. He had no idea how to do that but the nice thing about Emacs is that there are no secrets. He checked how the apropos commands gathered this information.

It turned out not to be too hard. The secret is to use the mapatoms command to cycle through the obarray that contains all the symbols in the current Emacs instance. Then it’s just a matter of checking if the symbol is for chatgpt-shell and is a custom variable. Grabbing the documentation for functions is similar. You can check out the code for both in Ramírez’s post.

There’s nothing specific to chatgpt-shell in any of this. You can use the same code, mutatis mutandis, for any package so it’s a worthwhile technique to know. If you’re maintaining a package and have even minimal documentation, you should definitely take a look at Ramírez’s post.

UPDATE [2023-05-12 Fri]: Just noticed that I forgot the link to Ramírez’s post. Fixed.

This entry was posted in Programming and tagged , . Bookmark the permalink.