From fd72b1680ad33c4976c588471b03144655b62911 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 18 Jul 2015 12:04:38 +0200 Subject: Emacs: Tangle init file asynchronously --- tag-emacs/emacs.d/init.org | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org index 18a6f97..1f0dd1e 100644 --- a/tag-emacs/emacs.d/init.org +++ b/tag-emacs/emacs.d/init.org @@ -1,7 +1,7 @@ #+TITLE: Emacs Configuration for Alan Pearce #+PROPERTY: results silent #+PROPERTY: eval no-export -#+PROPERTY: header-args :tangle yes :comments link +#+PROPERTY: header-args :comments link * Introduction This is a living document, detailing my Emacs configuration using org-mode * Basics @@ -2464,7 +2464,8 @@ the buffer for me. * Tangling Taken from [[https://github.com/larstvei/dot-emacs/blob/master/init.org][larstvei/dot-emacs]]. I changed it so that it would work with -my current dotfiles repository structure. +my current dotfiles repository structure and work asynchronously, +thanks to [[https://github.com/jwiegley/emacs-async][jwiegley/emacs-async]]. We can use =C-c C-v t= to run =org-babel-tangle=, which extracts the code blocks from the current file into a source-specific file (in this @@ -2475,15 +2476,25 @@ to the =after-save-hook= ensuring to always tangle and byte-compile the =org=-document after changes. #+BEGIN_SRC emacs-lisp + (req-package async) + (defun tangle-init () "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled." (when (string-suffix-p "init.org" (buffer-file-name)) - ;; Avoid running hooks when tangling. - (let ((prog-mode-hook nil)) - (org-babel-tangle) - (byte-compile-file (concat user-emacs-directory "init.el"))))) + (async-start + `(lambda () + ;; Avoid running hooks when tangling. + (let ((prog-mode-hook nil) + (dest (concat user-emacs-directory "init.el"))) + (find-file ,(buffer-file-name)) + (require 'ob-tangle) + (org-babel-tangle nil dest) + (byte-compile-file dest) + dest)) + (lambda (result) + (message "Init tangling completed: %s" result))))) #+END_SRC # Local Variables: -- cgit 1.4.1