0

Emacs has list-packages and related functions to manage packages. That's great. However, packages installed via this command changes my .emacs and does a custom-set-variables.

So is the preferred method to use this packages capability to use it via customize, or still write elisp for everything else, or something else?

The problem with customize is that not everything can be done there.

The problem with writing elisp for everything else is that custom-set-variables goes to the end of .emacs and is in the "wrong order" if I need to configure the packages.

What's the best way to do this?

  • Maybe it's just me, but this question sounds very broad and subjective and difficult to answer concisely and concretely. Perhaps you can try to narrow its scope? FWIW, you can override package--save-selected-packages so as not to write package-selected-packages when installing packages. – Basil Feb 28 '18 at 1:55
  • IIRC the custom-set-variables is put at the end when first added, but after that Emacs is careful to keep it where it is, so if it's not in the right order you can fix it just once and Emacs should "understand" and not mess it up again. – Stefan Feb 28 '18 at 2:49
2

Here is how I solved this.

At the very beginning of my ~/.emacs.d/init.el file, I set a dedicated file where customize will store its configuration without messing up my handcrafted init file (you can use any file here, so tweak as you like):

(add-to-list 'load-path "~/.emacs.d/config")
(setq-default custom-file "~/.emacs.d/config/custom-parameters.el")

Then, I rely on use-package directives to automatically download and configure packages I want to use. The :ensure t keyword is what automatically takes care of installation.

I only need this short snippet to make sure use-package is installed before everything else (because it takes care of the rest), so this comes immediately after the configuration of package.el repositories and parameters:

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

With that, I only need to copy my ~/.emacs.d directory to a new system, and at the first startup Emacs will automatically install everything.

My entire Emacs configuration is here, if you want some inspiration (and, as the license already says, use at your own risk :-).

  • Is there a way to completely prevent customize to store configuration? – Name Feb 28 '18 at 8:36
  • Not that I know. But if you don't use it and make it save its configuration in a dedicated file, it's pretty much invisible to you. You can even deliberately not load the custom-file, so whatever customize writes there is never loaded when you start a fresh instance of Emacs. – Guillaume Feb 28 '18 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.