]> git.eshelyaron.com Git - dict.git/commitdiff
ENHANCED: emit Prolog messages with color coding
authorEshel Yaron <me@eshelyaron.com>
Wed, 7 Sep 2022 15:08:28 +0000 (18:08 +0300)
committerEshel Yaron <me@eshelyaron.com>
Wed, 7 Sep 2022 15:14:46 +0000 (18:14 +0300)
sweep.el
sweep.pl

index a1d08b0491412bbce17965924ede4615b9223680..e6790d52c2915f6b909e8f7569d2351e52b9cd24 100644 (file)
--- a/sweep.el
+++ b/sweep.el
@@ -122,6 +122,47 @@ is used to find a the swipl executable."
           (require 'sweep-module))
       (error "Sweep will not work until `sweep-module' is compiled!"))))
 
+
+(defface sweep-debug-prefix-face
+  '((default :inherit shadow))
+  "Face used to highlight the \"DEBUG\" message prefix."
+  :group 'sweep-faces)
+
+(defvar sweep-debug-prefix-face 'sweep-debug-prefix-face
+  "Name of the face used to highlight the \"DEBUG\" message prefix.")
+
+(defface sweep-debug-topic-face
+  '((default :inherit shadow))
+  "Face used to highlight the topic in debug messages."
+  :group 'sweep-faces)
+
+(defvar sweep-debug-topic-face 'sweep-debug-topic-face
+  "Name of the face used to highlight the topic in debug messages.")
+
+(defface sweep-info-prefix-face
+  '((default :inherit default))
+  "Face used to highlight the \"INFO\" message prefix."
+  :group 'sweep-faces)
+
+(defvar sweep-info-prefix-face 'sweep-info-prefix-face
+  "Name of the face used to highlight the \"INFO\" message prefix.")
+
+(defface sweep-warning-prefix-face
+  '((default :inherit font-lock-warning-face))
+  "Face used to highlight the \"WARNING\" message prefix."
+  :group 'sweep-faces)
+
+(defvar sweep-warning-prefix-face 'sweep-warning-prefix-face
+  "Name of the face used to highlight the \"WARNING\" message prefix.")
+
+(defface sweep-error-prefix-face
+  '((default :inherit error))
+  "Face used to highlight the \"ERROR\" message prefix."
+  :group 'sweep-faces)
+
+(defvar sweep-error-prefix-face 'sweep-error-prefix-face
+  "Name of the face used to highlight the \"ERROR\" message prefix.")
+
 (defun sweep-view-messages ()
   "View the log of recent Prolog messages."
   (interactive)
@@ -147,7 +188,27 @@ is used to find a the swipl executable."
   (with-current-buffer (get-buffer-create sweep-messages-buffer-name)
     (save-excursion
       (goto-char (point-max))
-      (insert message)
+      (let ((kind (car message))
+            (content (cdr message)))
+        (pcase kind
+          (`("debug" . ,topic)
+           (insert (propertize "DEBUG" 'face sweep-debug-prefix-face))
+           (insert "[")
+           (insert (propertize topic 'face sweep-debug-topic-face))
+           (insert "]: ")
+           (insert content))
+          ("informational"
+           (insert (propertize "INFO" 'face sweep-info-prefix-face))
+           (insert ": ")
+           (insert content))
+          ("warning"
+           (insert (propertize "WARNING" 'face sweep-warning-prefix-face))
+           (insert ": ")
+           (insert content))
+          ("error"
+           (insert (propertize "ERROR" 'face sweep-error-prefix-face))
+           (insert ": ")
+           (insert content))))
       (newline))))
 
 (defun sweep-start-prolog-server ()
index 7b97502b38624e16b1e1cb5c1f9f74b306294528..8afce756b98b86636cf5018812139d586c0174e0 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -593,12 +593,13 @@ sweep_setup_message_hook(_, _) :-
              sweep_message_hook(Term, Kind, Lines)
              )).
 
-sweep_message_hook(Term, Kind, _Lines) :-
-    should_handle_message_kind(Kind),
+sweep_message_hook(Term, Kind0, _Lines) :-
+    should_handle_message_kind(Kind0, Kind),
     !,
     message_to_string(Term, String),
-    sweep_funcall("sweep-message", String, _).
+    sweep_funcall("sweep-message", [Kind|String], _).
 
-should_handle_message_kind(error).
-should_handle_message_kind(warning).
-should_handle_message_kind(debug(_)).
+should_handle_message_kind(error, "error").
+should_handle_message_kind(warning, "warning").
+should_handle_message_kind(informational, "informational").
+should_handle_message_kind(debug(Topic0), ["debug"|Topic]) :- atom_string(Topic0, Topic).