From 24b0e724617427c40fbe74bcb58e36ee490207a8 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Thu, 4 Aug 2016 16:37:18 +0200 Subject: init: Separate tangle and load This way I can load the config without having org-mode loaded. org-mode is only required once to tangle the elisp code blocks from the org-mode file. This also adds a startup timer. --- init.el | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/init.el b/init.el index 902642d..427291c 100644 --- a/init.el +++ b/init.el @@ -1,5 +1,26 @@ -(let ((file-name-handler-alist nil)) - (package-initialize nil) - (setq package-enable-at-startup nil - org-babel-use-quick-and-dirty-noweb-expansion t) - (org-babel-load-file "~/.emacs.d/init.d/main.org")) +(setq alex/startup-time (current-time) + alex/config (concat user-emacs-directory "init.d/main.org")) + +(defun alex/untangle-file-name (file) + (let ((base (file-name-sans-extension file))) + (concat base ".el"))) + +(defun alex/tangle-config (orgfile elfile) + (let ((org-babel-use-quick-and-dirty-noweb-expansion t)) + (message "Generating %s from %s. This may need some time..." elfile orgfile) + (let ((inhibit-message t)) + (require 'org) + (org-babel-tangle-file orgfile elfile 'emacs-lisp)) + (message "Done."))) + +(let ((elfile (alex/untangle-file-name alex/config))) + (when (or (not (file-exists-p elfile)) + (file-newer-than-file-p alex/config elfile)) + (alex/tangle-config alex/config elfile)) + + (let ((file-name-handler-alist nil)) + (package-initialize nil) + (setq package-enable-at-startup nil) + (load-file elfile))) + +(message "Startup finished in %.2fs" (float-time (time-subtract (current-time) alex/startup-time))) -- cgit v1.2.3