emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] scratch/flymake-refactor 3dfe11c 03/12: Simplify flymake l


From: João Távora
Subject: [Emacs-diffs] scratch/flymake-refactor 3dfe11c 03/12: Simplify flymake logging and erroring.
Date: Wed, 27 Sep 2017 13:47:28 -0400 (EDT)

branch: scratch/flymake-refactor
commit 3dfe11c78babb0b045ab56015d4b908842eff305
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>

    Simplify flymake logging and erroring.
    
    Use display-warning and a dedicated *Flymake log* buffer.
    
    To ease readability, flymake log messages are now prefixed with a
    common prefix and the buffer that originated them.
    
    Some situations of over-zealous logging are fixed.
    
    * lisp/progmodes/flymake-proc.el
    (flymake-proc--diagnostics-for-pattern): Improve log message.
    (flymake-proc--panic): Always flymake-log an error
    (flymake-proc--safe-delete-file)
    (flymake-proc--safe-delete-directory):
    Downgrade warning
    (flymake-proc-start-syntax-check): Simplify slightly.
    (flymake-proc--start-syntax-check-process): Simplify.
    (flymake-proc--init-find-buildfile-dir)
    (flymake-proc--init-create-temp-source-and-master-buffer-copy):
    No need to warn twice.
    
    * lisp/progmodes/flymake-ui.el (flymake-log): Use display-warning.
    (flymake-log-level): Deprecate.
    (flymake-error): New helper.
    (flymake-ler-make-ler, flymake--handle-report, flymake-mode):
    Use flymake-error.
    (flymake--handle-report, flymake-mode-on)
    (flymake-mode-off, flymake-find-file-hook): Simplify log message.
    (flymake-after-save-hook): Simplify logging.
---
 lisp/progmodes/flymake-proc.el | 29 ++++++++++++-------------
 lisp/progmodes/flymake-ui.el   | 48 ++++++++++++++++++++++++++++--------------
 2 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/lisp/progmodes/flymake-proc.el b/lisp/progmodes/flymake-proc.el
index 8992b1d..0050a44 100644
--- a/lisp/progmodes/flymake-proc.el
+++ b/lisp/progmodes/flymake-proc.el
@@ -440,7 +440,7 @@ Create parent directories as needed."
                       (guess-type flymake-proc-diagnostic-type-pred message)
                       message)))
          else
-         do (flymake-log 2 "No buffer found for diagnosed file %s" fname))
+         do (flymake-log 2 "Reference to file %s is out of scope" fname))
       (error
        (flymake-log 1 "Error parsing process output for pattern %s: %s"
                     pattern err)
@@ -531,7 +531,7 @@ May only be called in a dynamic environment where
            flymake-proc--report-fn)
       (funcall flymake-proc--report-fn :panic
                :explanation (format "%s: %s" problem explanation))
-    (error "Trouble telling flymake-ui about problem %s(%s)"
+    (flymake-error "Trouble telling flymake-ui about problem %s(%s)"
                    problem explanation)))
 
 (defun flymake-proc-reformat-err-line-patterns-from-compile-el (original-list)
@@ -675,13 +675,13 @@ expression. A match indicates `:warning' type, otherwise
 (defun flymake-proc--safe-delete-file (file-name)
   (when (and file-name (file-exists-p file-name))
     (delete-file file-name)
-    (flymake-log 1 "deleted file %s" file-name)))
+    (flymake-log 2 "deleted file %s" file-name)))
 
 (defun flymake-proc--safe-delete-directory (dir-name)
   (condition-case-unless-debug nil
       (progn
        (delete-directory dir-name)
-       (flymake-log 1 "deleted dir %s" dir-name))
+       (flymake-log 2 "deleted dir %s" dir-name))
     (error
      (flymake-log 1 "Failed to delete dir %s, error ignored" dir-name))))
 
@@ -757,15 +757,11 @@ expression. A match indicates `:warning' type, otherwise
                      default-directory)
         process)
     (error
-     (let* ((err-str
-             (format-message
-              "Failed to launch syntax check process `%s' with args %s: %s"
-              cmd args (error-message-string err)))
-            (source-file-name buffer-file-name)
-            (cleanup-f        (flymake-proc--get-cleanup-function 
source-file-name)))
-       (flymake-log 0 err-str)
-       (funcall cleanup-f)
-       (flymake-proc--panic :make-process-error err-str)))))
+     (flymake-proc--panic :make-process-error
+                          (format-message
+                           "Failed to launch syntax check process `%s' with 
args %s: %s"
+                           cmd args (error-message-string err)))
+     (funcall (flymake-proc--get-cleanup-function buffer-file-name)))))
 
 (defun flymake-proc-stop-all-syntax-checks (&optional reason)
   "Kill all syntax check processes."
@@ -916,7 +912,6 @@ Return full-name.  Names are real, not patched."
                                         (file-name-directory 
source-file-name))))
     (if buildfile-dir
         (setq flymake-proc--base-dir buildfile-dir)
-      (flymake-log 1 "no buildfile (%s) for %s" buildfile-name 
source-file-name)
       (flymake-proc--panic
        "NOMK" (format "No buildfile (%s) found for %s"
                       buildfile-name source-file-name)))))
@@ -932,8 +927,10 @@ Return full-name.  Names are real, not patched."
 
     (if (not master-and-temp-master)
        (progn
-         (flymake-log 1 "cannot find master file for %s" source-file-name)
-          (flymake-proc--panic "NOMASTER" "")  ; NOMASTER
+          (flymake-proc--panic
+           "NOMASTER"
+           (format-message "cannot find master file for %s"
+                           source-file-name))
           nil)
       (setq flymake-proc--master-file-name (nth 0 master-and-temp-master))
       (setq flymake-proc--temp-master-file-name (nth 1 
master-and-temp-master)))))
diff --git a/lisp/progmodes/flymake-ui.el b/lisp/progmodes/flymake-ui.el
index 608a2b4..cd5ffe3 100644
--- a/lisp/progmodes/flymake-ui.el
+++ b/lisp/progmodes/flymake-ui.el
@@ -34,7 +34,7 @@
 
 (require 'cl-lib)
 (require 'thingatpt) ; end-of-thing
-(require 'warnings) ; warning-numeric-level
+(require 'warnings) ; warning-numeric-level, display-warning
 (eval-when-compile (require 'subr-x)) ; when-let*, if-let*
 
 (defgroup flymake nil
@@ -110,6 +110,9 @@ See `flymake-error-bitmap' and `flymake-warning-bitmap'."
 -1 = NONE, 0 = ERROR, 1 = WARNING, 2 = INFO, 3 = DEBUG"
   :group 'flymake
   :type 'integer)
+(make-obsolete-variable 'flymake-log-level
+                       "it is superseded by `warning-minimum-log-level.'"
+                        "26.1")
 
 (defvar-local flymake-timer nil
   "Timer for starting syntax check.")
@@ -126,9 +129,24 @@ If LEVEL is higher than `flymake-log-level', the message is
 ignored.  Otherwise, it is printed using `message'.
 TEXT is a format control string, and the remaining arguments ARGS
 are the string substitutions (see the function `format')."
-  (if (<= level flymake-log-level)
-      (let* ((msg (apply #'format-message text args)))
-       (message "%s" msg))))
+  (let* ((msg (apply #'format-message text args))
+         (warning-minimum-level :emergency))
+    (display-warning
+     'flymake
+     (format "%s: %s" (buffer-name) msg)
+     (if (numberp level)
+         (or (nth level
+                  '(:error :warning :debug :debug) )
+             :error)
+       level)
+     "*Flymake log*")))
+
+(defun flymake-error (text &rest args)
+  "Signal an error for flymake."
+  (let ((msg (format-message text args)))
+    (flymake-log :error msg)
+    (error (concat "[flymake] "
+                   (format text args)))))
 
 (cl-defstruct (flymake--diag
                (:constructor flymake--diag-make))
@@ -147,7 +165,7 @@ description of the problem detected in this region."
 (defun flymake-ler-make-ler (file line type text &optional full-file)
   (let* ((file (or full-file file))
          (buf (find-buffer-visiting file)))
-    (unless buf (error "No buffer visiting %s" file))
+    (unless buf (flymake-error "No buffer visiting %s" file))
     (pcase-let* ((`(,beg . ,end)
                   (with-current-buffer buf
                     (flymake-diag-region line nil))))
@@ -241,8 +259,7 @@ Or nil if the region is invalid."
               (let* ((beg (fallback-bol))
                      (end (fallback-eol beg)))
                 (cons beg end))))))
-    (error (flymake-log 4 "Invalid region for diagnostic %s")
-           nil)))
+    (error (flymake-error "Invalid region line=%s col=%s" line col))))
 
 (defvar flymake-diagnostic-functions nil
   "List of flymake backends i.e. sources of flymake diagnostics.
@@ -471,7 +488,7 @@ A backend is disabled if it reported `:panic'.")
   "Handle reports from flymake backend identified by BACKEND."
   (cond
    ((not (memq backend flymake--running-backends))
-    (error "Ignoring unexpected report from backend %s" backend))
+    (flymake-error "Ignoring unexpected report from backend %s" backend))
    ((eq action :progress)
     (flymake-log 3 "Backend %s reports progress: %s" backend explanation))
    ((eq :panic action)
@@ -560,7 +577,7 @@ sources."
    (flymake-mode
     (cond
      ((not flymake-diagnostic-functions)
-      (error "flymake cannot check syntax in buffer %s" (buffer-name)))
+      (flymake-error "No backends to check buffer %s" (buffer-name)))
      (t
       (add-hook 'after-change-functions 'flymake-after-change-function nil t)
       (add-hook 'after-save-hook 'flymake-after-save-hook nil t)
@@ -591,13 +608,13 @@ sources."
 (defun flymake-mode-on ()
   "Turn flymake mode on."
   (flymake-mode 1)
-  (flymake-log 1 "flymake mode turned ON for buffer %s" (buffer-name)))
+  (flymake-log 1 "flymake mode turned ON"))
 
 ;;;###autoload
 (defun flymake-mode-off ()
   "Turn flymake mode off."
   (flymake-mode 0)
-  (flymake-log 1 "flymake mode turned OFF for buffer %s" (buffer-name)))
+  (flymake-log 1 "flymake mode turned OFF"))
 
 (defun flymake-after-change-function (start stop _len)
   "Start syntax check for current buffer if it isn't already running."
@@ -609,10 +626,9 @@ sources."
     (setq flymake-last-change-time (float-time))))
 
 (defun flymake-after-save-hook ()
-  (if (local-variable-p 'flymake-mode (current-buffer))        ; (???) other 
way to determine whether flymake is active in buffer being saved?
-      (progn
-       (flymake-log 3 "starting syntax check as buffer was saved")
-       (flymake--start-syntax-check)))) ; no more mode 3. cannot start check 
if mode 3 (to temp copies) is active - (???)
+  (when flymake-mode
+    (flymake-log 3 "starting syntax check as buffer was saved")
+    (flymake--start-syntax-check))) ; no more mode 3. cannot start check if 
mode 3 (to temp copies) is active - (???)
 
 (defun flymake-kill-buffer-hook ()
   (when flymake-timer
@@ -624,7 +640,7 @@ sources."
   (unless (or flymake-mode
               (null flymake-diagnostic-functions))
     (flymake-mode)
-    (flymake-log 3 "automatically turned ON flymake mode")))
+    (flymake-log 3 "automatically turned ON")))
 
 (defun flymake-goto-next-error (&optional n interactive)
   "Go to next, or Nth next, flymake error in buffer."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]