From c824d1f19805d90c8f01d3518d9dd5b7db99c625 Mon Sep 17 00:00:00 2001 From: Rongsong Shen Date: Sat, 15 Dec 2018 12:52:17 +0800 Subject: [PATCH] use process sentinel --- init/dot.emacs.el | 80 ++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/init/dot.emacs.el b/init/dot.emacs.el index 31a3872..f6c77c4 100644 --- a/init/dot.emacs.el +++ b/init/dot.emacs.el @@ -1,6 +1,35 @@ (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)) -(setq installation-done-stat-file "/tmp/.emacs.install.ok") (setq startkit-info '((doom-emacs . (lambda (dir) @@ -34,54 +63,27 @@ (list (concat "git clone https://github.com/syl20bnr/spacemacs.git " dir)))))) +(defun on-installer-finished (process event) + "Callback function when uinstaller process has finished." + (cond + ((string= event "finished\n") (load-file emacs-init-file)) + (t (message "Event %s has been ignored" event)))) + (defun install-emacs-startkit (name location) - (progn (require 'comint) - (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))) (progn + (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 (concat "touch " installation-done-stat-file "\n")) (comint-simple-send shell-process "exit\n"))))) -(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)) - -(defun load-emacs-init-idle () - (if (file-exists-p installation-done-stat-file) - (when (file-exists-p emacs-init-file) - (load-file emacs-init-file) - (delete-file installation-done-stat-file)) - (progn - (run-with-idle-timer 5 nil #'load-emacs-init-idle)))) - (if (not (file-exists-p emacs-init-file)) (progn - (if (file-exists-p installation-done-stat-file) - (delete-file installation-done-stat-file)) - (run-with-idle-timer 5 nil #'load-emacs-init-idle) (install-emacs-startkit emacs-start-kit emacs-config-directory)) (load-file emacs-init-file)) - + +(provide 'dot.emacs) +;;; dot.emacs.el ends here