custom-set-variables在一份配置中只能用一次?

custom.el里面,在custom-set-variables下面自动生成的注释说:

 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.

那我除了自动生成的那份之外就不能手动调用custom-set-variables了?

据说大部分的custom都可以用setq解决

这个功能只用于自动配置,手动用setq

不要手动更改custom-file里的(custom-set-variables ...). 因为可能会造成很奇怪的bug。

如果有变量需要设置,用setq

可是setq和custom-set-variables效果是不一样的啊,视package作者defvar时的内容,后者可能可以触发一些额外的操作

custom-set-variables

e.g. (来自purcell的函数):

(defun reapply-themes ()
  "Forcibly load the themes listed in `custom-enabled-themes'."
  (dolist (theme custom-enabled-themes)
    (unless (custom-theme-p theme)
      (load-theme theme)))
  (custom-set-variables `(custom-enabled-themes (quote ,custom-enabled-themes))))
1 个赞

我觉得当然不是了,亲自试下应该就清楚了(我没试过)

完整的注释是:

 ;; 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.

可能是因为 Custom 要管理 custom.el 中的 (custom-set-variables ...) 这个表达式,如果有不止一个这样的表达式,可能会出问题。另外,“Your init file” 有可能是指没设置 custom-file 的情况。

1 个赞

有道理!custom知道是哪个文件的话,别的文件里出现custom-set-variables不会造成混乱。

我倒觉得这里的“手动”指的是“手动编辑”custom-file里的custom-set-variables这个sexp里的内容。而不是调用custom-set-variables.

但是下面这两句似乎又否定了我的认识……但是我也确实看到有人在函数里调用custom-set-variables.……

事实上 Emacs 自带的程序也有调用它的。而且它还真的有一个文档

我现在配置rime的时候遇到类似的疑问,在这请教一下:

如图,custom和setq都不能改变customize group: rime里面的路径。rime在启动的时候读取的是customize group里面的设置。在use-package rime 的配置里定义custom和setq都无效。

那么,这三个custom setq 和 customize group有什么区别?平时我们在配置package的时候应该用那种方式呢?

刚入门,对emacs的很多概念和使用方式都不了解,不知道我表达清楚了没~

use-package的文档说:custom

Functionally, the only benefit over using setq in a :config block is that customizations might execute code when values are assigned.

所以猜测:custom的时机是和:config一样的,你这里要在启动前设置好要用:init

另外回到本帖本来的问题,customize-set-variable似乎是可以尽管用,不存在上面说的和自动生成的段落冲突的问题。

大致理解了一点。那这个自动在init.el文件里的customize-set-variable段落可以删除或者禁止生成吗?每次删掉这个段落以后新装一个package,它又自动生成了,里面的内容就是一些package的手动写的配置语句。感觉这些语句重复了,看着难受,想要删掉那个自动生成的,或是阻止它自动生成。

from Purcell’s config:

(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(unless (file-exists-p custom-file)
  (write-region "" nil custom-file))
(when (file-exists-p custom-file)
  (load custom-file))
1 个赞

帮大忙了,谢谢🙏