1

I use this function for tangling my init.el file

(defun tangle-init ()
    "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled."
    (when (equal (buffer-file-name) (expand-file-name (concat user-emacs-directory "init.org")))
      (let ((prog-mode-hook nil)) ;; Avoid running hooks when tangling.
        (org-babel-tangle-file buffer-file-name (concat user-emacs-directory "init.el") "emacs-lisp")
        (byte-compile-file (concat user-emacs-directory "init.el")))))
(add-hook 'after-save-hook 'tangle-init)

That code works well but it take a lot of time. So I would like to execute this function with async librairie (https://github.com/jwiegley/emacs-async)

I tried something like this but doesn't work:

(require 'async)
  (defun tangle-init-async ()
    "If the current buffer is 'init.org' the code-blocks are tangled, and the tangled file is compiled."
    (when (equal (buffer-file-name) (expand-file-name (concat user-emacs-directory "init.org")))
      (async-start
       (lambda ()
         (let ((prog-mode-hook nil)) ;; Avoid running hooks when tangling.
           (org-babel-tangle-file buffer-file-name (concat user-emacs-directory "init.el") "emacs-lisp")
           (byte-compile-file (concat user-emacs-directory "init.el")))))))
  (add-hook 'after-save-hook 'tangle-init-async)

Any help appreciated.

0

I find a solution adapt from https://github.com/bixuanzju/emacs.d/blob/master/emacs-init.org

(add-to-list 'load-path "~/.emacs.d/emacs-async/")
  (require 'async)
  (defun tangle-init-async ()
    "If the current buffer is 'emacs-init.org' the code-blocks are tangled."
    (when (equal (buffer-file-name) (expand-file-name (concat user-emacs-directory "init.org")))
      (async-start
       `(lambda ()
          (require 'org)
          (org-babel-tangle-file (expand-file-name (concat user-emacs-directory "init.org")) (expand-file-name (concat user-emacs-directory "init.el") "emacs-lisp"))
          )
       (lambda (result)
         (byte-compile-file (expand-file-name (concat user-emacs-directory "init.el")))
         (message "Tangled file compiled.")))))
  (add-hook 'after-save-hook 'tangle-init-async)

Thanks to bixuanzju (Jeremy Bi)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.