]> git.eshelyaron.com Git - sweep.git/commitdiff
ENHANCED: also update highlighting between sub terms
authorEshel Yaron <me@eshelyaron.com>
Sun, 25 Sep 2022 11:48:44 +0000 (14:48 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sun, 25 Sep 2022 12:13:05 +0000 (15:13 +0300)
sweep.el
sweep.pl

index 9cb6b1a35de2f8fd175efccc5edfe9947d8d3fc2..8297f5262bb2f7a63cc534738603d787f2eee3b7 100644 (file)
--- a/sweep.el
+++ b/sweep.el
@@ -911,20 +911,6 @@ module name, F is a functor name and N is its arity."
   (:weight bold)
   "Dict separators.")
 
-(sweep-defface
-  type-error
-  (:inherit font-lock-warning-face)
-  (:foreground "orange")
-  (:foreground "orange")
-  "Type errors.")
-
-(sweep-defface
-  instantiation-error
-  (:inherit font-lock-warning-face)
-  (:foreground "orange")
-  (:foreground "orange")
-  "Instantiation errors.")
-
 (sweep-defface
   file
   (:inherit button)
@@ -1040,17 +1026,66 @@ module name, F is a functor name and N is its arity."
 (sweep-defface
   error
   (:inherit font-lock-warning-face)
-  (:foreground "orange")
-  (:foreground "orange")
+  (:background "orange")
+  (:background "orange")
   "Unspecified errors.")
 
+(sweep-defface
+  type-error
+  (:inherit font-lock-warning-face)
+  (:background "orange")
+  (:background "orange")
+  "Type errors.")
+
+(sweep-defface
+  instantiation-error
+  (:inherit font-lock-warning-face)
+  (:background "orange")
+  (:background "orange")
+  "Instantiation errors.")
+
 (sweep-defface
   syntax-error
   (:inherit error)
-  (:foreground "orange")
-  (:foreground "orange")
+  (:background "orange")
+  (:background "orange")
   "Syntax errors.")
 
+(sweep-defface
+  around-syntax-error
+  (:inherit default)
+  (:inherit default)
+  (:inherit default)
+  "Text around a syntax error.")
+
+(sweep-defface
+  clause
+  (:inherit default)
+  (:inherit default)
+  (:inherit default)
+  "Predicate clauses.")
+
+(sweep-defface
+  grammar-rule
+  (:inherit default)
+  (:inherit default)
+  (:inherit default)
+  "DCG grammar rules.")
+
+(sweep-defface
+  term
+  (:inherit default)
+  (:inherit default)
+  (:inherit default)
+  "Top terms.")
+
+(sweep-defface
+  directive
+  (:inherit default)
+  (:inherit default)
+  (:inherit default)
+  "Directives.")
+
 (sweep-defface
   structured-comment
   (:inherit font-lock-doc-face)
@@ -1083,7 +1118,11 @@ module name, F is a functor name and N is its arity."
     (`("goal",(rx "imported(") . ,_) (sweep-imported-face))
     (`("goal",(rx "global(") . ,_) (sweep-global-face))
     (`("goal",(rx "local(") . ,_) (sweep-local-face))
-    (`("syntax_error" ,_message ,_eb ,_ee) (sweep-syntax-error-face))
+    (`("syntax_error" ,_message ,eb ,ee)
+     (with-silent-modifications
+       (put-text-property eb ee 'font-lock-face
+                          (sweep-around-syntax-error-face)))
+     (sweep-syntax-error-face))
     ("unused_import"       (sweep-unused-import-face))
     ("undefined_import"    (sweep-undefined-import-face))
     ("html_attribute"      (sweep-html-attribute-face))
@@ -1120,6 +1159,10 @@ module name, F is a functor name and N is its arity."
     ("file_no_depend"      (sweep-file-no-depend-face))
     ("nofile"              (sweep-no-file-face))
     ("op_type"             (sweep-op-type-face))
+    ("directive"           (sweep-directive-face))
+    ("clause"              (sweep-clause-face))
+    ("term"                (sweep-term-face))
+    ("grammar_rule"        (sweep-grammar-rule-face))
     ("method"              (sweep-method-face))
     ("class"               (sweep-class-face))))
 
index 3556a752f4b6c15b54d7c4b0640ac3d74f606f37..a161694a6b01a73ec1c42b49fbb96f673bfe8f09 100644 (file)
--- a/sweep.pl
+++ b/sweep.pl
@@ -126,9 +126,14 @@ sweep_colourise_buffer_(Path0, Contents, []) :-
     asserta(sweep_source_time(Path, Time), Ref1),
     xref_source(Path, []),
     seek(Contents, 0, bof, _),
+    retractall(sweep_current_comment(_, _, _)),
     prolog_colourise_stream(Contents,
                             Path,
-                            sweep_handle_query_color(1)),
+                            sweep_handle_color(1)),
+    forall(sweep_current_comment(Kind, Start, Len),
+           ( atom_string(Kind, String),
+             user:sweep_funcall("sweep--colourise", [Start,Len,"comment"|String], _)
+           )),
     erase(Ref0),
     erase(Ref1).
 
@@ -311,10 +316,15 @@ sweep_colourise_some_terms_(Path0, Offset, Contents, []) :-
     set_stream(Contents, file_name(Path)),
     seek(Contents, 0, bof, _),
     findall(Op, xref_op(Path, Op), Ops),
+    retractall(sweep_current_comment(_, _, _)),
     prolog_colourise_stream(Contents,
                             Path,
-                            sweep_handle_query_color(Offset),
-                            [operators(Ops)]).
+                            sweep_handle_color(Offset),
+                            [operators(Ops)]),
+    forall(sweep_current_comment(Kind, Start, Len),
+           ( atom_string(Kind, String),
+             user:sweep_funcall("sweep--colourise", [Start,Len,"comment"|String], _)
+           )).
 
 sweep_documentation([Path, Functor, Arity], Docs) :-
     atom_string(P, Path),
@@ -589,6 +599,12 @@ sweep_pack_info(pack(Name0, _, Desc0, Version0, URLS0), [Name, Desc, Version, UR
 sweep_pack_install(PackName, []) :-
     atom_string(Pack, PackName), pack_install(Pack, [silent(true), upgrade(true), interactive(false)]).
 
+sweep_handle_color(Offset, comment(Kind), Beg, Len) :-
+    !,
+    Start is Beg + Offset,
+    asserta(sweep_current_comment(Kind, Start, Len)).
+sweep_handle_color(Offset, Col, Beg, Len) :-
+    sweep_handle_query_color(Offset, Col, Beg, Len).
 
 sweep_colourise_query([String|Offset], _) :-
     prolog_colourise_query(String, module(sweep), sweep_handle_query_color(Offset)).