我重新构建了我的Emacs init文件,将它们置于版本控制之下.文件系统布局如下所示:
/home/axel/.user_config/emacs
??? development.el
??? general.el
??? init.el
??? packages.el
??? writing.el
Run Code Online (Sandbox Code Playgroud)
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")
Run Code Online (Sandbox Code Playgroud)
该文件~/.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")
Run Code Online (Sandbox Code Playgroud)
该文件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)))
Run Code Online (Sandbox Code Playgroud)
And*_*ham 17
在我的~/.emacs.d目录中,我有init.el以下内容:
(load "~/.emacs.d/init-packages")
Run Code Online (Sandbox Code Playgroud)
在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)))
Run Code Online (Sandbox Code Playgroud)
希望这是你想要的!