branch: externals/async commit 1eeb24b5893a6dae648b0b033f38d7704313156f Author: Thierry Volpiatto <thie...@posteo.net> Commit: Thierry Volpiatto <thie...@posteo.net>
DRY new function async-bytecomp--file-to-comp-buffer-1 Use it in async-packages. --- async-bytecomp.el | 42 +++++++++++++++++++++++------------------- async-package.el | 9 +-------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/async-bytecomp.el b/async-bytecomp.el index bf12265604..882bf9bc7f 100644 --- a/async-bytecomp.el +++ b/async-bytecomp.el @@ -70,30 +70,34 @@ of variable `temporary-file-directory' in async processes.") (defvar async-bytecomp-load-variable-regexp "\\`load-path\\'" "The variable used by `async-inject-variables' when (re)compiling async.") +(defun async-bytecomp--file-to-comp-buffer-1 (log-file) + (let ((buf (get-buffer-create byte-compile-log-buffer))) + (with-current-buffer buf + (goto-char (point-max)) + (let ((inhibit-read-only t)) + (insert-file-contents log-file) + (compilation-mode)) + (display-buffer buf) + (delete-file log-file)))) + (defun async-bytecomp--file-to-comp-buffer (file-or-dir &optional quiet type log-file) (let ((bn (file-name-nondirectory file-or-dir)) (action-name (pcase type ('file "File") - ('directory "Directory")))) + ('directory "Directory"))) + (n 0)) (if (and log-file (file-exists-p log-file)) - (let ((buf (get-buffer-create byte-compile-log-buffer)) - (n 0)) - (with-current-buffer buf - (goto-char (point-max)) - (let ((inhibit-read-only t)) - (insert-file-contents log-file) - (compilation-mode)) - (display-buffer buf) - (delete-file log-file) - (unless quiet - (save-excursion - (goto-char (point-min)) - (while (re-search-forward "^.*:Error:" nil t) - (cl-incf n))) - (if (> n 0) - (message "Failed to compile %d files in directory `%s'" n bn) - (message "%s `%s' compiled asynchronously with warnings" - action-name bn))))) + (progn + (async-bytecomp--file-to-comp-buffer-1 log-file) + (unless quiet + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^.*:Error:" nil t) + (cl-incf n))) + (if (> n 0) + (message "Failed to compile %d files in directory `%s'" n bn) + (message "%s `%s' compiled asynchronously with warnings" + action-name bn)))) (unless quiet (message "%s `%s' compiled asynchronously with success" action-name bn))))) diff --git a/async-package.el b/async-package.el index fb23558b1a..41c2e20702 100644 --- a/async-package.el +++ b/async-package.el @@ -134,14 +134,7 @@ Argument ERROR-FILE is the file where errors are logged, if some." str (length lst))) packages action-string) (when (and log-file (file-exists-p log-file)) - (let ((buf (get-buffer-create byte-compile-log-buffer))) - (with-current-buffer buf - (goto-char (point-max)) - (let ((inhibit-read-only t)) - (insert-file-contents log-file) - (compilation-mode)) - (display-buffer buf) - (delete-file log-file))))))) + (async-bytecomp--file-to-comp-buffer-1 log-file))))) (run-hooks 'async-pkg-install-after-hook))) 'async-pkg-install t) (async-package--modeline-mode 1)))