summary refs log tree commit diff stats
path: root/tag-emacs
diff options
context:
space:
mode:
authorAlan Pearce2016-03-17 14:16:08 +0100
committerAlan Pearce2016-03-17 14:16:08 +0100
commit4e89ea1bbfdd8d9d0d4c55e8439c20e0d19d4415 (patch)
tree44f658cddec7e40e156bd0bff7104f9a4708c3a6 /tag-emacs
parent2d2b313e264ee81af022046adf7cd8fec96cc5f3 (diff)
downloadnixfiles-4e89ea1bbfdd8d9d0d4c55e8439c20e0d19d4415.tar.lz
nixfiles-4e89ea1bbfdd8d9d0d4c55e8439c20e0d19d4415.tar.zst
nixfiles-4e89ea1bbfdd8d9d0d4c55e8439c20e0d19d4415.zip
Emacs: Improve tangling
Diffstat (limited to 'tag-emacs')
-rw-r--r--tag-emacs/emacs.d/init.org54
1 files changed, 25 insertions, 29 deletions
diff --git a/tag-emacs/emacs.d/init.org b/tag-emacs/emacs.d/init.org
index fb6eec6c..ccf726a5 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