Skip to content

Commit 5a1a2dd

Browse files
DRY in async-bytecomp callbacks
New function async-bytecomp--file-to-comp-buffer, use it in async-byte-recompile-directory and async-byte-compile-file.
1 parent f365589 commit 5a1a2dd

File tree

1 file changed

+26
-37
lines changed

1 file changed

+26
-37
lines changed

async-bytecomp.el

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ all packages are always compiled asynchronously."
6060
(defvar async-bytecomp-load-variable-regexp "\\`load-path\\'"
6161
"The variable used by `async-inject-variables' when (re)compiling async.")
6262

63+
(defun async-bytecomp--file-to-comp-buffer (file-or-dir &optional quiet)
64+
(let ((bn (file-name-nondirectory file-or-dir)))
65+
(if (file-exists-p async-byte-compile-log-file)
66+
(let ((buf (get-buffer-create byte-compile-log-buffer))
67+
(n 0))
68+
(with-current-buffer buf
69+
(goto-char (point-max))
70+
(let ((inhibit-read-only t))
71+
(insert-file-contents async-byte-compile-log-file)
72+
(compilation-mode))
73+
(display-buffer buf)
74+
(delete-file async-byte-compile-log-file)
75+
(unless quiet
76+
(save-excursion
77+
(goto-char (point-min))
78+
(while (re-search-forward "^.*:Error:" nil t)
79+
(cl-incf n)))
80+
(if (> n 0)
81+
(message "Failed to compile %d files in directory `%s'" n bn)
82+
(message "Directory `%s' compiled asynchronously with warnings"
83+
bn)))))
84+
(unless quiet
85+
(message "Directory `%s' compiled asynchronously with success" bn)))))
86+
6387
;;;###autoload
6488
(defun async-byte-recompile-directory (directory &optional quiet)
6589
"Compile all *.el files in DIRECTORY asynchronously.
@@ -73,26 +97,7 @@ All *.elc files are systematically deleted before proceeding."
7397
(load "async")
7498
(let ((call-back
7599
(lambda (&optional _ignore)
76-
(if (file-exists-p async-byte-compile-log-file)
77-
(let ((buf (get-buffer-create byte-compile-log-buffer))
78-
(n 0))
79-
(with-current-buffer buf
80-
(goto-char (point-max))
81-
(let ((inhibit-read-only t))
82-
(insert-file-contents async-byte-compile-log-file)
83-
(compilation-mode))
84-
(display-buffer buf)
85-
(delete-file async-byte-compile-log-file)
86-
(unless quiet
87-
(save-excursion
88-
(goto-char (point-min))
89-
(while (re-search-forward "^.*:Error:" nil t)
90-
(cl-incf n)))
91-
(if (> n 0)
92-
(message "Failed to compile %d files in directory `%s'" n directory)
93-
(message "Directory `%s' compiled asynchronously with warnings" directory)))))
94-
(unless quiet
95-
(message "Directory `%s' compiled asynchronously with success" directory))))))
100+
(async-bytecomp--file-to-comp-buffer directory quiet))))
96101
(async-start
97102
`(lambda ()
98103
(require 'bytecomp)
@@ -170,23 +175,7 @@ Same as `byte-compile-file' but asynchronous."
170175
(interactive "fFile: ")
171176
(let ((call-back
172177
(lambda (&optional _ignore)
173-
(let ((bn (file-name-nondirectory file)))
174-
(if (file-exists-p async-byte-compile-log-file)
175-
(let ((buf (get-buffer-create byte-compile-log-buffer))
176-
start)
177-
(with-current-buffer buf
178-
(goto-char (setq start (point-max)))
179-
(let ((inhibit-read-only t))
180-
(insert-file-contents async-byte-compile-log-file)
181-
(compilation-mode))
182-
(display-buffer buf)
183-
(delete-file async-byte-compile-log-file)
184-
(save-excursion
185-
(goto-char start)
186-
(if (re-search-forward "^.*:Error:" nil t)
187-
(message "Failed to compile `%s'" bn)
188-
(message "`%s' compiled asynchronously with warnings" bn)))))
189-
(message "`%s' compiled asynchronously with success" bn))))))
178+
(async-bytecomp--file-to-comp-buffer file))))
190179
(async-start
191180
`(lambda ()
192181
(require 'bytecomp)

0 commit comments

Comments
 (0)