126 lines
4.6 KiB
EmacsLisp
126 lines
4.6 KiB
EmacsLisp
;;; dot.emacs --- Summary
|
|
;;; This package will enable us to use multiple emacs startup
|
|
;;; configuration(startkit in this package) and switch between
|
|
;;; these configuration just by change a single environment
|
|
;;; variable (EMACS_STARTKIT).
|
|
;;;
|
|
;;; Currently, we have test it with following:
|
|
;;; - doom-emacs
|
|
;;; - spacemacs
|
|
;;; - frontmacs
|
|
;;; - ohai-emacs
|
|
;;; - graphene
|
|
;;; - prelude
|
|
;;;
|
|
;;; Commentary:
|
|
;;; Code:
|
|
(require 'cl-lib)
|
|
(require 'comint)
|
|
|
|
(defvar emacs-start-kit "The name of emacs startkit we will use")
|
|
(defvar emacs-config-name "The directory name of emacs startkit")
|
|
(defvar emacs-config-directory "The based directory of emacs start configuration")
|
|
(defvar emacs-init-file "The full path of emacs start file")
|
|
(defvar startkit-info "Information to install emacs startkit")
|
|
|
|
(setq emacs-start-kit
|
|
(let ((start-kit (getenv "EMACS_STARTKIT")))
|
|
(if start-kit
|
|
start-kit
|
|
"spacemacs")))
|
|
|
|
(setq emacs-config-name emacs-start-kit)
|
|
|
|
(setq emacs-config-directory
|
|
(let ((config-dir (getenv "EMACS_CONFIG_DIR")))
|
|
(if config-dir
|
|
(concat config-dir "/"
|
|
emacs-config-name "/")
|
|
(concat (substitute-in-file-name "~/.config/emacs/")
|
|
emacs-config-name "/"))))
|
|
|
|
(unless (file-exists-p emacs-config-directory)
|
|
(make-directory emacs-config-directory t))
|
|
|
|
(setq user-emacs-directory emacs-config-directory)
|
|
|
|
(setq emacs-init-file
|
|
(expand-file-name "init.el" user-emacs-directory))
|
|
|
|
;; setup customization directory for emacs (custom.el)
|
|
(unless custom-file
|
|
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)))
|
|
|
|
;; Setup default directory which package will be installed
|
|
(setq package-user-dir
|
|
(concat user-emacs-directory "/elpa"))
|
|
|
|
;; setup directory of spacemacs customization
|
|
(when (string= emacs-start-kit "spacemacs")
|
|
(let ((spacemacs-dir (concat emacs-config-directory "/.local/etc")))
|
|
(progn
|
|
(setenv "SPACEMACSDIR" spacemacs-dir))))
|
|
|
|
(setq startkit-info
|
|
'((doom-emacs .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "git clone git@github.com:shen390s/doom-emacs.git " dir)
|
|
(concat "cd " dir)
|
|
"cp init.example.el init.el"
|
|
"make install"
|
|
"y")))
|
|
(frontmacs .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "mkdir -p " dir )
|
|
(concat "cd " dir)
|
|
"wget https://raw.githubusercontent.com/shen390s/frontmacs/master/scripts/init-frontmacs.el"
|
|
"echo \"(load (expand-file-name \\\"init-frontmacs.el\\\" user-emacs-directory))\" >>init.el")))
|
|
(graphene .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "git clone git@github.com:shen390s/dotfiles-emacs.git " dir))))
|
|
(ohai-emacs .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "git clone git@github.com:shen390s/ohai-emacs.git " dir))))
|
|
(prelude .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "git clone git@github.com:shen390s/prelude.git " dir))))
|
|
(spacemacs .
|
|
(lambda (dir)
|
|
(list
|
|
(concat "git clone https://github.com/syl20bnr/spacemacs.git " dir))))))
|
|
|
|
|
|
(defun install-emacs-startkit (name location)
|
|
(progn (let* ((shell-buffer (make-comint-in-buffer "installer" nil "/bin/sh"))
|
|
(shell-process (get-buffer-process shell-buffer)))
|
|
(progn
|
|
(defun on-installer-finished (process event)
|
|
"Callback function when uinstaller process has finished.
|
|
We use this function to load startkit initialization file"
|
|
(cond
|
|
((string= event "finished\n") (load-file emacs-init-file))
|
|
(t (message "Event %s has been ignored" event))))
|
|
|
|
(set-process-sentinel shell-process 'on-installer-finished)
|
|
(display-buffer shell-buffer)
|
|
(cl-loop for cmd in (funcall (cdr (assoc (intern name) startkit-info))
|
|
location)
|
|
do (comint-simple-send shell-process
|
|
(concat cmd "\n")))
|
|
(comint-simple-send shell-process
|
|
"exit\n")))))
|
|
|
|
(if (not (file-exists-p emacs-init-file))
|
|
(progn
|
|
(install-emacs-startkit emacs-start-kit
|
|
emacs-config-directory))
|
|
(load-file emacs-init-file))
|
|
|
|
(provide 'dot.emacs)
|
|
;;; dot.emacs.el ends here
|