3

In my init.el, I have the following line

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))

which is supposed to set the file custom.el into .emacs.d config folder for getting all customization tidy. Over the years, emacs populated this file with various things.

I ran customization with M-x customize-variable and made some change and saved them. Afterwards, I discovered that emacs added the new custom into custom.el, overwriting the previous version of the file.

What's the mistake? Should I put (load custom-file) after the line above? Can this be the problem?

2
  • Please add that info to your question. Comments can be deleted at any time. Thx.
    – Drew
    Commented Apr 28, 2021 at 20:23
  • I'm not sure I understand the question, but you should carefully read all of C-h v custom-file if you haven't done that already.
    – phils
    Commented Apr 28, 2021 at 22:36

1 Answer 1

4

You used M-x customize-variable, edited the option value, and then saved it. When you save your changes they're written to your custom-file (or your init file, if you have no custom-file defined). So yes, it's normal that custom-file was overwritten.

Yes, in your init file, somewhere after you define the value of option custom-file, you need to load that file, if you want Emacs to recognize its customizations.

And it's generally better to use customize-save-variable or customize-set-variable than just setq, to change the value of a user option. It's not critical here, but it's a good habit to have.

For example, in your init file:

;; Possibly some stuff...

(customize-save-variable 'custom-file  (expand-file-name "custom.el" user-emacs-directory))

;; Possibly some other stuff...

(load-file custom-file)

;; Possibly some other stuff...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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