@@ -479,10 +479,15 @@ You can pass BUFFER-OR-NAME to replace current buffer."
479479 (with-current-buffer (or buffer-or-name (current-buffer ))
480480 (goto-char (point-min ))
481481 (while (not (eobp ))
482- (let ((line (buffer-substring-no-properties (line-beginning-position ) (line-end-position ))))
483- (cond ((string-match-p " [: ][Ee]rror: " line) (eask-error line))
484- ((string-match-p " [: ][Ww]arning: " line) (eask-warn line))
485- (t (eask-log line))))
482+ (let ((line (buffer-substring-no-properties (line-beginning-position )
483+ (line-end-position ))))
484+ ; ; The variable `line' can contains format specifier, avoid it with `%s' !
485+ (cond ((string-match-p " [: ][Ee]rror: " line)
486+ (eask-error " %s" line))
487+ ((string-match-p " [: ][Ww]arning: " line)
488+ (eask-warn " %s" line))
489+ (t
490+ (eask-log " %s" line))))
486491 (forward-line 1 ))))
487492
488493(defun eask-delete-file (filename )
@@ -1821,49 +1826,48 @@ Execute forms BODY limit by the verbosity level (SYMBOL)."
18211826(defun eask--ansi (symbol string )
18221827 " Paint STRING with color defined by log level (SYMBOL)."
18231828 (if-let* ((ansi-function (cdr (assq symbol eask-level-color))))
1824- (funcall ansi-function string)
1829+ ; ; The `%s` is use to avoid `not enough arguments for string` error.
1830+ (funcall ansi-function " %s" string)
18251831 string))
18261832
18271833(defun eask--format (prefix fmt &rest args )
18281834 " Format Eask messages.
18291835
18301836Argument PREFIX is a string identify the type of this messages. Arguments FMT
18311837and ARGS are used to pass through function `format' ."
1832- (apply #'format
1833- (concat (when eask-timestamps (format-time-string " %Y-%m-%d %H:%M:%S " ))
1834- (when eask-log-level (concat prefix " " ))
1835- fmt)
1836- args))
1838+ (concat (when eask-timestamps (format-time-string " %Y-%m-%d %H:%M:%S " ))
1839+ (when eask-log-level (concat prefix " " ))
1840+ (apply #'format fmt args)))
18371841
1838- (defun eask--msg (symbol prefix msg &rest args )
1842+ (defun eask--msg (symbol prefix fmt &rest args )
18391843 " If level (SYMBOL) is at or below `eask-verbosity' ; then, log the message.
18401844
1841- For arguments PREFIX, MSG and ARGS, please see funtion `eask--format' for the
1845+ For arguments PREFIX, FMT and ARGS, please see funtion `eask--format' for the
18421846detials."
18431847 (eask-with-verbosity symbol
1844- (let* ((string (apply #'eask--format prefix msg args))
1845- (output (eask--ansi symbol string ))
1848+ (let* ((output (apply #'eask--format prefix fmt args))
1849+ (output (eask--ansi symbol output ))
18461850 (output (eask--msg-displayable-kwds output)) ; Don't color, but replace it!
18471851 (func (cl-case symbol
18481852 ((or error warn) symbol)
1849- (t #'message ))))
1853+ (t #'message ))))
18501854 (funcall func " %s" output))))
18511855
1852- (defun eask-debug (msg &rest args )
1853- " Send debug message; see function `eask--msg' for arguments MSG and ARGS."
1854- (apply #'eask--msg 'debug " [DEBUG]" msg args))
1855- (defun eask-log (msg &rest args )
1856- " Send log message; see function `eask--msg' for arguments MSG and ARGS."
1857- (apply #'eask--msg 'log " [LOG]" msg args))
1858- (defun eask-info (msg &rest args )
1859- " Send info message; see function `eask--msg' for arguments MSG and ARGS."
1860- (apply #'eask--msg 'info " [INFO]" msg args))
1861- (defun eask-warn (msg &rest args )
1862- " Send warn message; see function `eask--msg' for arguments MSG and ARGS."
1863- (apply #'eask--msg 'warn " [WARNING]" msg args))
1864- (defun eask-error (msg &rest args )
1865- " Send error message; see function `eask--msg' for arguments MSG and ARGS."
1866- (apply #'eask--msg 'error " [ERROR]" msg args))
1856+ (defun eask-debug (fmt &rest args )
1857+ " Send debug message; see function `eask--msg' for arguments FMT and ARGS."
1858+ (apply #'eask--msg 'debug " [DEBUG]" fmt args))
1859+ (defun eask-log (fmt &rest args )
1860+ " Send log message; see function `eask--msg' for arguments FMT and ARGS."
1861+ (apply #'eask--msg 'log " [LOG]" fmt args))
1862+ (defun eask-info (fmt &rest args )
1863+ " Send info message; see function `eask--msg' for arguments FMT and ARGS."
1864+ (apply #'eask--msg 'info " [INFO]" fmt args))
1865+ (defun eask-warn (fmt &rest args )
1866+ " Send warn message; see function `eask--msg' for arguments FMT and ARGS."
1867+ (apply #'eask--msg 'warn " [WARNING]" fmt args))
1868+ (defun eask-error (fmt &rest args )
1869+ " Send error message; see function `eask--msg' for arguments FMT and ARGS."
1870+ (apply #'eask--msg 'error " [ERROR]" fmt args))
18671871
18681872(defun eask--msg-char-displayable (char replacement s )
18691873 " Ensure CHAR is displayable in S; if not, we fallback to REPLACEMENT
@@ -1963,6 +1967,12 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
19631967(defvar eask-inhibit-error-message nil
19641968 " Non-nil to stop error/warning message." )
19651969
1970+ (defvar eask--has-error-p nil
1971+ " Non-nil if an error has occurred." )
1972+
1973+ (defvar eask--has-warn-p nil
1974+ " Non-nil if a warning has occurred." )
1975+
19661976(defmacro eask-ignore-errors (&rest body )
19671977 " Execute BODY without killing the process."
19681978 (declare (indent 0 ) (debug t ))
@@ -1981,15 +1991,16 @@ Argument ARGS are direct arguments for functions `eask-error' or `eask-warn'."
19811991(defun eask--trigger-error ()
19821992 " Trigger error event."
19831993 (when (and (not eask--ignore-error-p)
1984- (not (eask-checker-p))) ; ignore when checking Eask-file
1985- (if (eask-allow-error-p) ; Trigger error at the right time
1994+ (not (eask-checker-p))) ; Ignore when checking Eask-file.
1995+ (if (eask-allow-error-p) ; Trigger error at the right time.
19861996 (add-hook 'eask-after-command-hook #'eask--exit )
19871997 (eask--exit))))
19881998
19891999(defun eask--error (fnc &rest args )
19902000 " On error.
19912001
19922002Arguments FNC and ARGS are used for advice `:around' ."
2003+ (setq eask--has-error-p t )
19932004 (let ((msg (eask--ansi 'error (apply #'format-message args))))
19942005 (unless eask-inhibit-error-message
19952006 (eask--unsilent (eask-msg " %s" msg)))
@@ -2001,6 +2012,7 @@ Arguments FNC and ARGS are used for advice `:around'."
20012012 " On warn.
20022013
20032014Arguments FNC and ARGS are used for advice `:around' ."
2015+ (setq eask--has-warn-p t )
20042016 (let ((msg (eask--ansi 'warn (apply #'format-message args))))
20052017 (unless eask-inhibit-error-message
20062018 (eask--unsilent (eask-msg " %s" msg)))
0 commit comments