update
This commit is contained in:
commit
0e2d84d360
@ -3,7 +3,7 @@
|
|||||||
;; Author: Rongsong Shen<rshen@shenrs.eu>
|
;; Author: Rongsong Shen<rshen@shenrs.eu>
|
||||||
;;
|
;;
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
;;
|
||||||
;; This package will enable us to use multiple EMACS startup
|
;; This package will enable us to use multiple EMACS startup
|
||||||
;; configuration(startkit in this package) and switch between
|
;; configuration(startkit in this package) and switch between
|
||||||
;; these configuration just by change a single environment
|
;; these configuration just by change a single environment
|
||||||
@ -23,134 +23,153 @@
|
|||||||
(require 'cl-lib)
|
(require 'cl-lib)
|
||||||
(require 'comint)
|
(require 'comint)
|
||||||
|
|
||||||
(defvar emacs-start-kit "The name of emacs startkit we will use")
|
(defvar emacs-start-kit
|
||||||
(defvar emacs-config-name "The directory name of emacs startkit")
|
(split-string
|
||||||
(defvar emacs-config-directory "The based directory of emacs start configuration")
|
(let ((start-kit (getenv "EMACS_STARTKIT")))
|
||||||
(defvar emacs-init-file "The full path of emacs start file")
|
(if start-kit
|
||||||
(defvar startkit-info "Information to install emacs startkit")
|
start-kit
|
||||||
|
"easy-emacs"))
|
||||||
|
":")
|
||||||
|
"The name of emacs startkit we will use")
|
||||||
|
|
||||||
(setq emacs-start-kit
|
(defvar startkit-name
|
||||||
(let ((start-kit (getenv "EMACS_STARTKIT")))
|
(car emacs-start-kit)
|
||||||
(if start-kit
|
"The name of Emacs startkit")
|
||||||
start-kit
|
|
||||||
"spacemacs")))
|
|
||||||
|
|
||||||
(setq emacs-config-name emacs-start-kit)
|
(defvar startkit-branch
|
||||||
|
(let ((branch (cadr emacs-start-kit)))
|
||||||
|
(if branch
|
||||||
|
branch
|
||||||
|
"master"))
|
||||||
|
"The branch of emacs startkit")
|
||||||
|
|
||||||
|
(defvar emacs-config-name
|
||||||
|
startkit-name
|
||||||
|
"The directory name of emacs startkit")
|
||||||
|
|
||||||
|
(defvar emacs-config-directory
|
||||||
|
(let ((config-dir (getenv "EMACS_CONFIG_DIR")))
|
||||||
|
(if config-dir
|
||||||
|
(format "%s/%s.%s"
|
||||||
|
config-dir
|
||||||
|
startkit-name
|
||||||
|
startkit-branch)
|
||||||
|
(format "%s/.config/emacs/%s.%s"
|
||||||
|
(getenv "HOME")
|
||||||
|
startkit-name
|
||||||
|
startkit-branch)))
|
||||||
|
"The based directory of emacs start configuration")
|
||||||
|
|
||||||
|
(defvar startkit-info nil
|
||||||
|
"Information to install emacs startkit")
|
||||||
|
|
||||||
|
(defvar emacs-base-directory
|
||||||
|
(format "%s/Emacs/%s.%s"
|
||||||
|
(getenv "HOME")
|
||||||
|
startkit-name
|
||||||
|
startkit-branch)
|
||||||
|
"The base directory which Emacs startkit will be put")
|
||||||
|
|
||||||
|
(defvar emacs-init-file
|
||||||
|
(concat emacs-base-directory "/"
|
||||||
|
"/init.el")
|
||||||
|
"The full path of emacs start file")
|
||||||
|
|
||||||
(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)
|
(unless (file-exists-p emacs-config-directory)
|
||||||
(make-directory emacs-config-directory t))
|
(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)
|
;; setup customization directory for emacs (custom.el)
|
||||||
(unless custom-file
|
(unless custom-file
|
||||||
(setq custom-file (expand-file-name "custom.el" user-emacs-directory)))
|
(setq custom-file (expand-file-name "custom.el" emacs-config-directory)))
|
||||||
|
|
||||||
;; Setup default directory which package will be installed
|
;; Setup default directory which package will be installed
|
||||||
(setq package-user-dir
|
(setq package-user-dir
|
||||||
(concat user-emacs-directory "/elpa"))
|
(concat emacs-config-directory "/elpa"))
|
||||||
|
|
||||||
;; setup directory of spacemacs customization
|
;; setup directory of spacemacs customization
|
||||||
(when (or (string= emacs-start-kit "spacemacs")
|
(when (string= startkit-name "spacemacs")
|
||||||
(string= emacs-start-kit "spacemacs.develop"))
|
|
||||||
(let ((spacemacs-dir (concat emacs-config-directory "/.local/etc")))
|
(let ((spacemacs-dir (concat emacs-config-directory "/.local/etc")))
|
||||||
(progn
|
(progn
|
||||||
(setenv "SPACEMACSDIR" spacemacs-dir))))
|
(setenv "SPACEMACSDIR" spacemacs-dir))))
|
||||||
|
|
||||||
(setq startkit-info
|
(defun gen-doom-install-script (branch install-dir config-dir)
|
||||||
'((doom-emacs .
|
(if (string= branch "master")
|
||||||
(lambda (dir)
|
(list
|
||||||
(list
|
(format
|
||||||
(concat "git clone git@github.com:shen390s/doom-emacs.git " dir)
|
"git clone https://github.com/hlissner/doom-emacs.git %s"
|
||||||
(concat "cd " dir)
|
install-dir)
|
||||||
"cp init.example.el init.el"
|
(format "cd %s" install-dir)
|
||||||
"make install"
|
(format "DOOMDIR=%s ./bin/doom install"
|
||||||
"y")))
|
config-dir))
|
||||||
(frontmacs .
|
(list
|
||||||
(lambda (dir)
|
(format
|
||||||
(list
|
"git clone -b %s https://github.com/hlissner/doom-emacs.git %s"
|
||||||
(concat "mkdir -p " dir )
|
branch install-dir)
|
||||||
(concat "cd " dir)
|
(format "cd %s" install-dir)
|
||||||
"wget https://raw.githubusercontent.com/shen390s/frontmacs/master/scripts/init-frontmacs.el"
|
(format "DOOMDIR=%s ./bin/doom install"
|
||||||
"echo \"(load (expand-file-name \\\"init-frontmacs.el\\\" user-emacs-directory))\" >>init.el")))
|
config-dir))))
|
||||||
(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))))
|
|
||||||
(spacemacs.develop .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone -b develop https://github.com/syl20bnr/spacemacs.git " dir))))
|
|
||||||
(radian-emacs .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone -b radian https://github.com/shen390s/straight-emacs.git " dir))))
|
|
||||||
(hell-emacs .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone -b doom-emacs https://github.com/shen390s/straight-emacs.git " dir))))
|
|
||||||
(doom-emacs.develop .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone -b develop https://github.com/hlissner/doom-emacs.git " dir)
|
|
||||||
(concat "cd " dir)
|
|
||||||
"cp init.example.el init.el"
|
|
||||||
"make install"
|
|
||||||
"y")))
|
|
||||||
(easy-emacs .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone git@shenrs.eu:rshen/easy-emacs.git " dir))))
|
|
||||||
(castlemacs .
|
|
||||||
(lambda (dir)
|
|
||||||
(list
|
|
||||||
(concat "git clone https://github.com/freetonik/castlemacs.git " dir))))))
|
|
||||||
|
|
||||||
(defun install-emacs-startkit (name location)
|
(defun doom-load (install-dir config-dir)
|
||||||
|
(progn
|
||||||
|
(setenv "DOOMDIR" config-dir)
|
||||||
|
(load-file emacs-init-file)))
|
||||||
|
|
||||||
|
(defun gen-easy-install-script (branch install-dir config-dir)
|
||||||
|
(if (string= branch "master")
|
||||||
|
(list
|
||||||
|
(format
|
||||||
|
"git clone git@shenrs.eu:rshen/easy-emacs.git %s"
|
||||||
|
install-dir))
|
||||||
|
(list
|
||||||
|
(format
|
||||||
|
"git clone -b %s git@shenrs.eu:rshen/easy-emacs.git %s"
|
||||||
|
branch install-dir))))
|
||||||
|
|
||||||
|
(defun easy-emacs-load (install-dir config-dir)
|
||||||
|
(progn
|
||||||
|
(setenv "EASYEMACSDATA" config-dir)
|
||||||
|
(setenv "EASYEMACSDIR" install-dir)
|
||||||
|
(load-file emacs-init-file)))
|
||||||
|
|
||||||
|
(setq startkit-info
|
||||||
|
'((doom-emacs . (gen-doom-install-script . doom-load))
|
||||||
|
(easy-emacs . (gen-easy-install-script . easy-emacs-load))))
|
||||||
|
|
||||||
|
(defun get-startkit-installer-gen-fn (name startkit-info)
|
||||||
|
(car (cdr (assoc name startkit-info))))
|
||||||
|
|
||||||
|
(defun get-startkit-loader (name startkit-info)
|
||||||
|
(cdr (cdr (assoc name startkit-info))))
|
||||||
|
|
||||||
|
(defun load-emacs ()
|
||||||
|
;; use emacs config directory as user-emacs-directory
|
||||||
|
(setq user-emacs-directory emacs-config-directory)
|
||||||
|
(funcall (get-startkit-loader (intern startkit-name)
|
||||||
|
startkit-info)
|
||||||
|
emacs-base-directory
|
||||||
|
emacs-config-directory))
|
||||||
|
|
||||||
|
(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-emacs))
|
||||||
|
(t (message "Event %s has been ignored" event))))
|
||||||
|
|
||||||
|
|
||||||
|
(defun install-emacs-startkit (name branch location config-dir)
|
||||||
"Function to install EMACS startkit. NAME is the name of EMACS startkit.
|
"Function to install EMACS startkit. NAME is the name of EMACS startkit.
|
||||||
LOCATION is the target directory which startkit will be installed."
|
LOCATION is the target directory which startkit will be installed."
|
||||||
(progn (let* ((shell-buffer (make-comint-in-buffer "installer" nil "/bin/sh"))
|
(progn (let* ((shell-buffer (make-comint-in-buffer "installer" nil "/bin/sh"))
|
||||||
(shell-process (get-buffer-process shell-buffer)))
|
(shell-process (get-buffer-process shell-buffer)))
|
||||||
(progn
|
(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)
|
(set-process-sentinel shell-process 'on-installer-finished)
|
||||||
(display-buffer shell-buffer)
|
(display-buffer shell-buffer)
|
||||||
(comint-simple-send shell-process
|
(cl-loop for cmd in
|
||||||
(concat "PS1=\">\"\n"
|
(funcall (get-startkit-installer-gen-fn (intern name)
|
||||||
"PS2=\">\"\n"
|
startkit-info)
|
||||||
"PROMPT=\">\"\n"
|
branch location config-dir)
|
||||||
"export PS1 PS2 PROMPT\n"))
|
|
||||||
(cl-loop for cmd in (funcall (cdr (assoc (intern name) startkit-info))
|
|
||||||
location)
|
|
||||||
do (comint-simple-send shell-process
|
do (comint-simple-send shell-process
|
||||||
(concat cmd "\n")))
|
(concat cmd "\n")))
|
||||||
(comint-simple-send shell-process
|
(comint-simple-send shell-process
|
||||||
@ -158,9 +177,11 @@ We use this function to load startkit initialization file"
|
|||||||
|
|
||||||
(if (not (file-exists-p emacs-init-file))
|
(if (not (file-exists-p emacs-init-file))
|
||||||
(progn
|
(progn
|
||||||
(install-emacs-startkit emacs-start-kit
|
(install-emacs-startkit startkit-name
|
||||||
|
startkit-branch
|
||||||
|
emacs-base-directory
|
||||||
emacs-config-directory))
|
emacs-config-directory))
|
||||||
(load-file emacs-init-file))
|
(load-emacs))
|
||||||
|
|
||||||
(provide 'multi-emacs-config)
|
(provide 'multi-emacs-config)
|
||||||
;;; multi-emacs-config.el ends here
|
;;; multi-emacs-config.el ends here
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user