From 4e89ea1bbfdd8d9d0d4c55e8439c20e0d19d4415 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Thu, 17 Mar 2016 14:16:08 +0100 Subject: Emacs: Improve tangling --- tag-emacs/emacs.d/init.org | 54 +++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 29 deletions(-) (limited to 'tag-emacs') diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org index fb6eec6..ccf726a 100644 --- a/tag-emacs/emacs.d/init.org +++ b/tag-emacs/emacs.d/init.org @@ -2369,44 +2369,40 @@ the =org=-document after changes. :commands (async-start) :defer 2) + (defun tangle-if-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)) + (tangle-init))) + (defun tangle-init-sync () (interactive) - (when (string-suffix-p "init.org" (buffer-file-name)) - (message "Tangling init") - ;; Avoid running hooks when tangling. - (let ((prog-mode-hook nil) - (dest (expand-file-name "init.el" user-emacs-directory))) - (require 'ob-tangle) - (org-babel-tangle-file (buffer-file-name) dest) - (if (byte-compile-file dest) - (byte-compile-dest-file dest) - (with-current-buffer byte-compile-log-buffer - (buffer-string)))))) + (message "Tangling init") + ;; Avoid running hooks when tangling. + (let ((prog-mode-hook nil) + (src (expand-file-name "init.org" user-emacs-directory)) + (dest (expand-file-name "init.el" user-emacs-directory))) + (require 'ob-tangle) + (org-babel-tangle-file src dest) + (if (byte-compile-file dest) + (byte-compile-dest-file dest) + (with-current-buffer byte-compile-log-buffer + (buffer-string))))) (defun tangle-init () - "If the current buffer is 'init.org' the code-blocks are - tangled, and the tangled file is compiled." + "Tangle init.org asynchronously." (interactive) - (when (string-suffix-p "init.org" (buffer-file-name)) - (message "Tangling init") - (async-start - `(lambda () - ;; Avoid running hooks when tangling. - (let ((prog-mode-hook nil) - (dest (expand-file-name "init.el" user-emacs-directory))) - (require 'ob-tangle) - (org-babel-tangle-file ,(buffer-file-name) dest) - (if (byte-compile-file dest) - (byte-compile-dest-file dest) - (with-current-buffer byte-compile-log-buffer - (buffer-string))))) - (lambda (result) - (message "Init tangling completed: %s" result))))) + (message "Tangling init") + (async-start + (symbol-function #'tangle-init-sync) + (lambda (result) + (message "Init tangling completed: %s" result)))) #+END_SRC # Local Variables: -# eval: (when (fboundp #'tangle-init) (add-hook 'after-save-hook #'tangle-init)) +# eval: (when (fboundp #'tangle-if-init) (add-hook 'after-save-hook #'tangle-if-init)) # End: * End -- cgit 1.4.1