关于把custom.el独立出来的一个问题

大部分的emacs config都会把emacs自己生成的custom使用下面的代码独立成一个单独的文件custom.el

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

今天在写自己的配置时,发现这样子似乎会使一些设置回档,就是写不进配置文件,每次emacs重启都会消失不见。问,有人遇见过这种情况吗,你是怎么解决的。

你的custom.el 不会是locale-variable设置为只读了吧

我也不太确定

请教下怎么查看这个

检查一下你的custom.el 文件的开头有没有 这句注释:

-*- buffer-read-only: t -*-

我看了一下发现没有这个注释

再者这个问题我觉得很可能是你在设置完了变量后,你没有选择 以 ‘future using’ 的方式保存变量设置,而是选择只为本 session保存这个变量, 也就是设置界面应该选择 Apply-and-save 而不是 仅仅 Apply

额 我选得的确是future using的方式,同时 许多的setq 方式的变量设置似乎也会失效。我之前在用purcell的配置加自己的一些org-capture的的时候也会出现这种问题,就是custom无法保存

你的配置能否贴一下 看一下

我怀疑是配置问题!

(when (version< emacs-version "24.4")
  (error "This requires Emacs 24.4 and above!"))

(defvar default-file-name-handler-alist file-name-handler-alist)
(setq file-name-handler-alist nil)
(setq gc-cons-threshold 30000000)
(add-hook 'emacs-startup-hook
          (lambda ()
            "Restore defalut values after init."
            (setq file-name-handler-alist default-file-name-handler-alist)
            (setq gc-cons-threshold 800000)
            (add-hook 'focus-out-hook 'garbage-collect)))

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

(setq package-archives '(("gnu"   . "http://elpa.emacs-china.org/gnu/")
                          ("melpa" . "http://elpa.emacs-china.org/melpa/")
                          ("org"   . "http://elpa.emacs-china.org/org/")))

(setq package-enable-at-startup nil)    ; To prevent initialising twice
(package-initialize)

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

;; Required by `use-package'
(use-package diminish 
  :ensure t)
(use-package use-package-chords
  :ensure t
  :config (key-chord-mode 1))

(use-package paradox
  :ensure t
  :init
  (setq paradox-token t)
  :config
  (paradox-enable)
  :bind
  ([f1] . paradox-list-packages))

(load custom-file) 是不是这个。我在C-h v 里面找到似乎是要加这么一句。我之前是没有加这个的

发现有可能是在这里

(load custom-file) 是要加的。

1 个赞

嗯嗯 多谢诶

借楼问一下,使用use-package,用ensure t后会安装新的包并保存相关配置的custom到init.el中中,那我单独出来的custom要怎么处理呢,请问大家是如何处理 的

用这行代码默认把customize的代码存到指定文件。

custom-file在文档里是这么说的:

Documentation: File used for storing customization information. The default is nil, which means to use your init file as specified by ‘user-init-file’. If the value is not nil, it should be an absolute file name.

You can set this option through Custom, if you carefully read the last paragraph below. However, usually it is simpler to write something like the following in your init file:

(setq custom-file "~/.emacs-custom.el")
(load custom-file)

Note that both lines are necessary: the first line tells Custom to save all customizations in this file, but does not load it.

When you change this variable outside Custom, look in the previous custom file (usually your init file) for the forms ‘(custom-set-variables …)’ and ‘(custom-set-faces …)’, and copy them (whichever ones you find) to the new custom file. This will preserve your existing customizations.

If you save this option using Custom, Custom will write all currently saved customizations, including the new one for this option itself, into the file you specify, overwriting any ‘custom-set-variables’ and ‘custom-set-faces’ forms already present in that file. It will not delete any customizations from the old custom file. You should do that manually if that is what you want. You also have to put something like (load “CUSTOM-FILE”) in your init file, where CUSTOM-FILE is the actual name of the file. Otherwise, Emacs will not load the file when it starts up, and hence will not set ‘custom-file’ to that file either.

2 个赞