Emacs-helper installer
1 简介
这个文件是tumashu个人专用的emacs配置文件,emacs中文用户可以参考。
2 代码
(require 'package)
(defun eh-current-directory () (file-name-directory (buffer-file-name)))
(setq package-archives `(("eh-elpa" . ,(concat (eh-current-directory) "elpa/"))))
(package-initialize)
(defun eh-packages-install (packages) (let ((refreshed nil)) (when (not package-archive-contents) (package-refresh-contents) (setq refreshed t)) (dolist (pkg packages) (when (and (not (package-installed-p pkg)) (assoc pkg package-archive-contents)) (unless refreshed (package-refresh-contents) (setq refreshed t)) (package-install pkg)))))
(defun eh-get-mirror-packages (mirror-directory) "Return all package's name in a mirror directory: MIRROR-DIRECTROY." (when (and mirror-directory (stringp mirror-directory)) (let ((file (concat (file-name-as-directory mirror-directory) "archive-contents"))) (when (file-exists-p file) (mapcar #'car (cdr (read (with-temp-buffer (insert-file-contents file) (buffer-string)))))))))
(defvar eh-config-template " %% ------------------------------------ %% Add by emacs-helper installer (add-to-list 'load-path %S) (require 'emacs-helper) %% ------------------------------------ ")
(defun eh-installer () (interactive) ;; 安装 elpa 目录下的所有包 (eh-packages-install (eh-get-mirror-packages (concat (eh-current-directory) "elpa/"))) ;; 在 "~/.emacs" 文件中插入配置片断 (append-to-file (format (replace-regexp-in-string "%%" ";;" eh-config-template) (eh-current-directory)) nil "~/.emacs") (message "Emacs-helper 安装完成,请重新启动 Emacs"))
(eh-installer)