我重构了我的Emacs init文件,将它们置于版本控制之下。文件系统布局如下所示:
/home/axel/.user_config/emacs
├── development.el
├── general.el
├── init.el
├── packages.el
└── writing.el
packages.el
包含Emacs在启动时应安装的软件包列表(如果尚未安装)。执行rm -rf ~/.emacs.d/*
后,这可以正常工作。当我之后启动Emacs时,会安装packages.el
中列出的所有软件包。但是,当我手动将包(例如markdown-mode+
)添加到pfl-packages
中的列表packages.el
时,重新启动Emacs时未安装新包。删除~/.emacs.d/
的内容再次解决了这个问题,但我希望能够将包名添加到列表中,然后Emacs会在启动时自动安装。我错过了关于Emacs初始化过程的重要内容吗?
请参阅以下相关文件的内容。
文件~/.emacs
包含以下内容:
(add-to-list 'load-path "~/.user_config/emacs/")
(load-library "init")
文件~/.user_config/emacs/init.el
包含:
;;;; loads the different libraries to set up Emacs accordingly
;; load the library that sets up package repositories and syncing
(load-library "packages")
;; load the library that sets up the general behavior of Emacs
(load-library "general")
(load-library "writing")
(load-library "development")
文件packages.el
包含以下内容:
;;;; this library sets up package repositories and allows for syncing packages
;;;; between different machines
;;;; to add packages to the syncing, add their repository names to the list `pfl-packages'
;;; set up package repositories from which additional packages can be installed
;; set up ELPA and MELPA repositories
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/"))
;;; set up package syncing to allow for syncing between different machines
;; list of packages to sync
(setq pfl-packages
'(
color-theme-sanityinc-solarized
company
company-auctex
company-c-headers
company-irony
company-quickhelp
elpy
ess
flycheck-irony
irony
magit
markdown-mode
markdown-mode+
rainbow-delimiters
smart-tabs-mode
yasnippet
))
;; refresh package list if it is not already available
(when (not package-archive-contents) (package-refresh-contents))
;; install packages from the list that are not yet installed
(dolist (pkg pfl-packages)
(when (and (not (package-installed-p pkg)) (assoc pkg package-archive-contents))
(package-install pkg)))
答案 0 :(得分:15)
在我的~/.emacs.d
目录中,我的init.el
内容如下:
(load "~/.emacs.d/init-packages")
在init-packages.el
中,我完全按照您的要求进行操作:启动时,emacs会检查列出的每个软件包是否已安装,如果没有安装,则会进行安装。如果要安装新软件包,只需将其添加到列表中即可。
值得注意的是,在添加相关的包存档后必须调用package-initialize
,以便实际可以获取它们然后再安装。
以下是init-packages.el
的内容:
(require 'package)
(add-to-list 'package-archives
'("elpy" . "http://jorgenschaefer.github.io/packages/"))
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa-stable" . "http://melpa-stable.milkbox.net/packages/") t)
(add-to-list 'load-path "~/.emacs.d/site-lisp/")
; list the packages you want
(setq package-list
'(python-environment deferred epc
flycheck ctable jedi concurrent company cyberpunk-theme elpy
yasnippet pyvenv highlight-indentation find-file-in-project
sql-indent sql exec-path-from-shell iedit
auto-complete popup let-alist magit git-rebase-mode
git-commit-mode minimap popup))
; activate all the packages
(package-initialize)
; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
; install the missing packages
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
希望这就是你要找的东西!