Keep Your init.el and .emacs.d Tidy
It’s been about a month since I started this series, that is, since I initialized my Emacs configuration. While considering coding productivity, I felt it was time to integrate LSP into my setup. But…
When I gave it a try, I saw unwanted generated codes appearing in my init.el
.
I need to find a way to change the destination of these generated codes.
Separating Custom Settings
One of the most common issues with Emacs configuration is the automatic insertion of custom settings into init.el
.
This can make your carefully crafted configuration file messy and hard to maintain.
Picture this: you’re writing a research paper, methodically validating every logical progression, when someone reaches over and scribbles ‘Source: Trust me bro’ in your citations section──what the heck are you doing?
Let’s fix this:
(leaf cus-edit
:doc "tools for customizing Emacs and Lisp packages"
:custom
`((custom-file . ,(locate-user-emacs-file "custom.el"))))
Note: You might need to create the custom.el
file manually if it doesn’t exist:
touch ~/.emacs.d/custom.el
Now our init.el
is kept organized because cus-edit.el
redirects custom settings to a separate file (custom.el
).
As a similar problem, we have the problem with .emacs.d
:
The default paths used to store configuration files and persistent data are inconsistent across Emacs packages. This isn’t just a problem with third-party packages but even with built-in packages. (ref: no-littering website)
I want to avoid this because my .emacs.d/
is git-managed:
(leaf no-littering
:doc "Keep .emacs.d/ clean"
:url "https://github.com/emacscollective/no-littering"
:ensure t)
And now our .emacs.d/
and init.el
are kept as tidy!
The state of init.el at the conclusion of this article can be found here 🚀
Related Emacs Functions
custom-file
locate-user-emacs-file
References
comments powered by Disqus