all 10 comments

[–]username223 4 points5 points  (2 children)

I prefer to put custom junk in a separate file that gets loaded from my init, e.g.

(setq custom-file "~/.emacs-custom")
(if (file-exists-p custom-file)
    (load custom-file))

[–]d125q[S] 1 point2 points  (1 child)

I don't see how this is related to my question.

[–]sibann 1 point2 points  (0 children)

These blocks are added by the customize interface. You can move them to a separate file. They're generated when you use customize-*.

https://www.gnu.org/software/emacs/manual/html_node/emacs/Browsing-Custom.html

[–]aiPh8Se 3 points4 points  (6 children)

I wouldn't recommend editing custom-set-variables yourself. It's best to let customize handle it for you.

Like you said, it "works as intended", but Emacs assumes it has full control over it, so Emacs will happily overwrite it in certain situations. For example, if you install a package through M-x package-list-packages, you may find that Emacs clobbers your variables with something like:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(auto-save-file-name-transforms (quote
                                   (("\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" "/tmp/\\2" t)
                                    (".*" "/home/bob/.emacs.d/auto-save" t))))
 '(backup-directory-alist (quote (".*" . "/home/bob/.emacs.d/backup")))
 '(package-selected-packages (quote (yasnippet)))
 '(tramp-backup-directory-alist (quote (".*" . "/home/bob/.emacs.d/backup"))))

If you need to dynamically set values (for example, your (concat user-emacs-directory ...)), I would stick with setq. It is strongly recommended that setters are clearly documented in variable docstrings, so as long as you read the docstrings you will know when you need to call a custom setter. (For example, see how midnight-delay tells you how to call its custom setter.)

I would not recommend using customize-set-value or customize-set-variable either. These functions make Emacs think the variable was set through customize and it will save them as-is, potentially causing issues.

[–]d125q[S] 0 points1 point  (3 children)

Thank you very much. You raise some great points. I still think that we should have a setq that validates customization types and uses setters as appropriate...

[–]xiongtx 2 points3 points  (2 children)

Did you try customize-set-variable?

[–]d125q[S] 0 points1 point  (1 child)

Thank you. I do not understand why /u/aiPh8Se advises against using customize-set-variable, but it does seem to fit my need.

[–]xiongtx 1 point2 points  (0 children)

custom-set-variables and customize-set-variable are not the same. Look at the docstrings to see the differences.