branch: externals/async
commit 04e1a2c40bef305450389da540ffe7594964e430
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Add async-byte-compile-file
* async-bytecomp.el (async-byte-compile-file): New.
---
async-bytecomp.el | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/async-bytecomp.el b/async-bytecomp.el
index 7c113d5..7bb2d46 100644
--- a/async-bytecomp.el
+++ b/async-bytecomp.el
@@ -173,6 +173,47 @@ Async compilation of packages can be controlled by
(ad-activate 'package--compile)
(ad-deactivate 'package--compile)))
+;;;###autoload
+(defun async-byte-compile-file (file)
+ "Byte compile Lisp code FILE asynchronously.
+
+Same as `byte-compile-file' but asynchronous."
+ (interactive "fFile: ")
+ (let ((call-back
+ (lambda (&optional _ignore)
+ (let ((bn (file-name-nondirectory file)))
+ (if (file-exists-p async-byte-compile-log-file)
+ (let ((buf (get-buffer-create byte-compile-log-buffer))
+ start)
+ (with-current-buffer buf
+ (goto-char (setq start (point-max)))
+ (let ((inhibit-read-only t))
+ (insert-file-contents async-byte-compile-log-file)
+ (compilation-mode))
+ (display-buffer buf)
+ (delete-file async-byte-compile-log-file)
+ (save-excursion
+ (goto-char start)
+ (if (re-search-forward "^.*:Error:" nil t)
+ (message "Failed to compile `%s'" bn)
+ (message "`%s' compiled asynchronously with warnings"
bn)))))
+ (message "`%s' compiled asynchronously with success" bn))))))
+ (async-start
+ `(lambda ()
+ (require 'bytecomp)
+ ,(async-inject-variables "\\`load-path\\'")
+ (let ((default-directory ,(file-name-directory file)))
+ (add-to-list 'load-path default-directory)
+ (byte-compile-file ,file)
+ (when (get-buffer byte-compile-log-buffer)
+ (setq error-data (with-current-buffer byte-compile-log-buffer
+ (buffer-substring-no-properties (point-min)
(point-max))))
+ (unless (string= error-data "")
+ (with-temp-file ,async-byte-compile-log-file
+ (erase-buffer)
+ (insert error-data))))))
+ call-back)))
+
(provide 'async-bytecomp)
;;; async-bytecomp.el ends here