emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/sweeprolog a369e46143 160/166: ENHANCED: underline occurre


From: ELPA Syncer
Subject: [nongnu] elpa/sweeprolog a369e46143 160/166: ENHANCED: underline occurrences of the variable at point
Date: Fri, 30 Sep 2022 04:59:35 -0400 (EDT)

branch: elpa/sweeprolog
commit a369e461439c3f6ff4ae5a8289b157fa75bf815e
Author: Eshel Yaron <me@eshelyaron.com>
Commit: Eshel Yaron <me@eshelyaron.com>

    ENHANCED: underline occurrences of the variable at point
---
 sweeprolog.el | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/sweeprolog.el b/sweeprolog.el
index 2e9d322956..937e62164c 100644
--- a/sweeprolog.el
+++ b/sweeprolog.el
@@ -992,6 +992,13 @@ module name, F is a functor name and N is its arity."
   (:inherit font-lock-keyword-face)
   "The empty list.")
 
+(sweeprolog-defface
+  variable-at-point
+  (:underline t)
+  (:underline t)
+  (:underline t)
+  "Variables.")
+
 (sweeprolog-defface
   variable
   (:inherit font-lock-variable-name-face)
@@ -1111,6 +1118,8 @@ module name, F is a functor name and N is its arity."
   (:inherit font-lock-doc-face :foreground "green")
   "Structured comments.")
 
+(defvar-local sweeprolog--variable-at-point nil)
+
 (defun sweeprolog--colour-term-to-faces (beg end arg)
   (pcase arg
     (`("comment" . "structured")
@@ -1202,7 +1211,14 @@ module name, F is a functor name and N is its arity."
     ("control"
      (list (list beg end (sweeprolog-control-face))))
     ("var"
-     (list (list beg end (sweeprolog-variable-face))))
+     (let ((var (buffer-substring-no-properties beg end)))
+       (with-silent-modifications
+         (put-text-property beg end 'cursor-sensor-functions
+                            (sweeprolog-cursor-sensor-functions var)))
+       (cons (list beg end (sweeprolog-variable-face))
+             (and sweeprolog--variable-at-point
+                  (string= sweeprolog--variable-at-point var)
+                  (list (list beg end (sweeprolog-variable-at-point-face)))))))
     ("fullstop"
      (list (list beg end (sweeprolog-fullstop-face))))
     ("functor"
@@ -1296,11 +1312,11 @@ module name, F is a functor name and N is its arity."
     (with-silent-modifications
       (font-lock-unfontify-region beg end))
     (sweeprolog-open-query "user"
-                      "sweep"
-                      "sweep_colourise_some_terms"
-                      (list contents
-                            (buffer-file-name)
-                            beg))
+                           "sweep"
+                           "sweep_colourise_some_terms"
+                           (list contents
+                                 (buffer-file-name)
+                                 beg))
     (let ((sol (sweeprolog-next-solution)))
       (sweeprolog-close-query)
       (when (sweeprolog-true-p sol)
@@ -2166,6 +2182,15 @@ Interactively, POINT is set to the current point."
                   (cancel-timer sweeprolog--timer))))))
 
 
+(defun sweeprolog-cursor-sensor-functions (var)
+  (list
+   (lambda (_win old dir)
+     (if (eq dir 'entered)
+         (let ((sweeprolog--variable-at-point var))
+           (font-lock-fontify-region (point) (point)))
+       (let ((sweeprolog--variable-at-point nil))
+         (font-lock-fontify-region old old))))))
+
 (provide 'sweeprolog)
 
 ;;; sweeprolog.el ends here



reply via email to

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