Skip to content

Commit

Permalink
feat(compile): Improve compile messages on error (#285)
Browse files Browse the repository at this point in the history
* feat(compile): Improve compile messages on error

* changelog

* don't provide
  • Loading branch information
jcs090218 authored Nov 23, 2024
1 parent 30b5878 commit ab187d4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
* fix(test): ERT test fails on Emacs 30+ (cc1f4e15b7b40b986ad1a93f6e40d121340598de)
* fix(test): eask options should not be passed to buttercup (#281)
* feat(core): Lazy install on required packages (#284)
* feat(compile): Improve compile messages on error (#285)

## 0.10.x
> Released Jun 13, 2024
Expand Down
4 changes: 2 additions & 2 deletions lisp/_prepare.el
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ scope of the dependencies (it's either `production' or `development')."
If the argument FORCE is non-nil, force initialize packages in this session."
(when (or (not package--initialized) (not package-archive-contents) force
;; XXX we need to initialize once in global scope since most Emacs
;; XXX: we need to initialize once in global scope since most Emacs
;; configuration would likely to set `package-archives' variable
;; themselves.
(and (eask-config-p) (not eask--package-initialized)))
Expand Down Expand Up @@ -697,7 +697,7 @@ Argument BODY are forms for execution."
(eask-with-progress
(format " - %sInstalling %s (%s)... " eask--action-prefix name version)
(eask-with-verbosity 'debug
;; XXX Without ignore-errors guard, it will trigger error
;; XXX: Without ignore-errors guard, it will trigger error
;;
;; Can't find library xxxxxxx.el
;;
Expand Down
24 changes: 16 additions & 8 deletions lisp/core/compile.el
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,21 @@
;;
;;; Core

(defconst eask-compile--log-buffer-name "*Compile-Log*"
"Byte-compile log buffer name.")
(require 'bytecomp)

;; XXX: The function `byte-compile-warn' last modified is 2015;
;; I'll say it's safe to override this function.
(advice-add 'byte-compile-warn :override
(lambda (format &rest args)
(setq format (apply #'format-message format args))
(byte-compile-log-warning format t (if byte-compile-error-on-warn
:error
:warning))))

(defun eask-compile--print-log ()
"Print `*Compile-Log*' buffer."
(when (get-buffer eask-compile--log-buffer-name)
(with-current-buffer eask-compile--log-buffer-name
(when (get-buffer byte-compile-log-buffer)
(with-current-buffer byte-compile-log-buffer
(if (and (eask-clean-p) (eask-strict-p))
(eask-error (buffer-string)) ; Exit with error code!
(eask-print-log-buffer))
Expand Down Expand Up @@ -85,14 +93,14 @@ The CMD is the command to start a new Emacs session."
(content (eask-compile--byte-compile-file-external-content filename cmd)))
(if (string-empty-p content)
t ; no error, good!
(with-current-buffer (get-buffer-create eask-compile--log-buffer-name)
(with-current-buffer (get-buffer-create byte-compile-log-buffer)
(insert content)))))

(defun eask-compile--byte-compile-file (filename)
"Byte compile FILENAME."
;; *Compile-Log* does not kill itself. Make sure it's clean before we do
;; next byte-compile task.
(ignore-errors (kill-buffer eask-compile--log-buffer-name))
(ignore-errors (kill-buffer byte-compile-log-buffer))
(let* ((filename (expand-file-name filename))
(result))
(eask-with-progress
Expand All @@ -102,7 +110,7 @@ The CMD is the command to start a new Emacs session."
(eask-compile--byte-compile-file-external filename)
(byte-compile-file filename))
result (eq result t)))
(if result "done ✓" "skipped ✗"))
(unless byte-compile-verbose (if result "done ✓" "skipped ✗")))
(eask-compile--print-log)
result))

Expand All @@ -112,7 +120,7 @@ The CMD is the command to start a new Emacs session."
(compiled (length compiled))
(skipped (- (length files) compiled)))
;; XXX: Avoid last newline from the log buffer!
(unless (get-buffer eask-compile--log-buffer-name)
(unless (get-buffer byte-compile-log-buffer)
(eask-msg ""))
(eask-info "(Total of %s file%s compiled, %s skipped)" compiled
(eask--sinr compiled "" "s")
Expand Down
2 changes: 1 addition & 1 deletion lisp/core/exec.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

(eask-start
(eask-defvc< 27 (eask-pkg-init)) ; XXX: remove this after we drop 26.x
;; XXX This is the hack by adding all `bin' folders from local elpa.
;; XXX: This is the hack by adding all `bin' folders from local elpa.
(eask-setup-paths)
(if (eask-argv 1)
(eask-with-progress
Expand Down
1 change: 0 additions & 1 deletion test/commands/test/buttercup/test-ok/buttercup-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
(it "contains a spec with an expectation"
(expect t :to-be t)))

(provide 'buttercup-test)
;;; buttercup-test.el ends here

0 comments on commit ab187d4

Please sign in to comment.