我正在尝试整理我的 init.el 文件,该文件目前一团糟。我在网上查看了其他人的文件以获取一些灵感,但这些示例中没有一个具有这个特定的块:
(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.
'(ispell-dictionary nil)
'(package-selected-packages
'(sonic-pi browse-kill-ring sclang-extensions async magit avy csv-mode company ein conda perspective buffer-move pdf-tools which-key helpful use-package sudo-edit))
'(send-mail-function 'mailclient-send-it))
(custom-set-faces
;; custom-set-faces 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.
)
因此,我不知道从哪里开始,而且网络上也没有太多信息。我有兴趣用 use-package 重新组织我的文件,因为它看起来是一种非常整洁的方式,但我不知道这段代码应该放在哪里??
正如文字指出的那样,您正在显示的块是由
customize
界面添加的(另请参见this答案)。要将 Emacs 指向任何其他初始化文件,请参阅文档。
如果您希望总体上整理 Emacs 配置,我强烈建议您采用 文学编程方法。这意味着您在
~/.emacs.d/config.org
中编写 Emacs 配置并包含由 org-babel-tangle
: 纠缠的块
#+begin_src emacs-lisp :tangle yes
(all-your-config-stuff ...)
#+end_src
org-babel
。当使用的 Emacs 版本 >=24~/.emacs.d/init.el
的内容
(org-babel-load-file "~/.emacs.d/config.org")
每次重启 Emacs 时,最新版本的
config.org
将“纠缠”到 config.el
中,并且 init 文件将被正确加载。当您不想在弄乱您的配置时重新启动 Emacs 时,只需使用 M-x org-babel-tangle-file
缠绕文件并通过打开加载 config.el
的缓冲区并执行 config.el
.来评估您的
M-x eval-buffer
这里是我个人配置
~/.emacs.d/config.org
的例子。它是负责use-package
初始化的部分。请注意在 Org-mode 中添加的附加说明。由于此解释不在(待)纠结的源代码块之外,因此它不会出现在您的config.el
.中
First we need to use the built-in package manager to actually download
=use-package= when it is not available.
#+begin_src emacs-lisp :tangle yes
;; Use the built-in package manager and specify archive
(require 'package)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
;; Initialize built-in package management
(package-initialize)
;; Install use-package if not available
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
#+end_src
Then we can actually load =use-package=
#+begin_src emacs-lisp :tangle yes
;; Load use-package by requiring it, to ensure it has been loaded
(eval-when-compile
(require 'use-package))
#+end_src
所以我可以在找到关于stack exchange的解释后回答我自己的问题
引用 emacs 的文档“这个变量在安装新包时由 Emacs 自动提供。”。但是我还没有看到有人的初始化文件中有这个块,或者像
(setq custom-file (make-temp-file "emacs-custom"))
.这样的行
我很困惑
如前所述,这些表格是由
customize
界面编写的。您可以通过设置变量 customize
来控制 custom-file
存储此信息的位置。请参阅带有C-h v custom-file RET
的文档。解释这些文档,您可以在 ~/.emacs.d/init.el
文件中放入类似以下内容:
;; don't let customize add stuff to my init.el
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)
你把它放在哪里取决于你。就我个人而言,我将
custom-file
设置在我的init文件的开头附近,然后在最后加载它。