From: Eshel Yaron Date: Wed, 9 Nov 2022 20:23:26 +0000 (+0200) Subject: FIXED: simplify & make variable highlighting more reliable X-Git-Tag: V8.5.20-sweep-0.8.4~5 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c1882b93d1cfe8def6f201740e71cb876070cf0e;p=sweep.git FIXED: simplify & make variable highlighting more reliable --- diff --git a/sweeprolog.el b/sweeprolog.el index a4dd6dd..8dbaf44 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -420,12 +420,6 @@ clause." (defvar-local sweeprolog--module-term nil) -(defvar-local sweeprolog--variable-at-point nil) - -(defvar-local sweeprolog--variable-at-point-point nil) - -(defvar-local sweeprolog--variable-at-point-occurrences nil) - (defvar-local sweeprolog--diagnostics nil) (defvar-local sweeprolog--diagnostics-report-fn nil) @@ -1876,29 +1870,13 @@ When non-nil, only predicates whose name contains PREFIX are returned." (setq sweeprolog--module-term (cons beg end))))) (defun sweeprolog-analyze-fragment-variable (beg end arg) - (cond - ((member arg (list "var" - (list "goal_term" "meta" 'variable 0))) - (let ((var (buffer-substring-no-properties beg end))) - (with-silent-modifications - (put-text-property beg end 'cursor-sensor-functions - (sweeprolog-cursor-sensor-functions var)) - (when (and sweeprolog--variable-at-point - (string= sweeprolog--variable-at-point var)) - (push (cons beg end) sweeprolog--variable-at-point-occurrences))))) - ((and (stringp arg) - (string= arg "fullstop") - sweeprolog--variable-at-point-point - (< end sweeprolog--variable-at-point-point)) - (setq sweeprolog--variable-at-point-occurrences nil)))) - -(defun sweeprolog-analyze-end-variable (&rest _) - (dolist (occurence sweeprolog--variable-at-point-occurrences) - (font-lock--add-text-property (car occurence) - (cdr occurence) - 'font-lock-face - (sweeprolog-variable-at-point-face) - (current-buffer) nil))) + (pcase arg + ((or "var" + `("goal_term" "meta" variable 0)) + (let ((var (buffer-substring-no-properties beg end))) + (with-silent-modifications + (put-text-property beg end 'cursor-sensor-functions + (sweeprolog-cursor-sensor-functions var))))))) (defvar sweeprolog-analyze-region-start-hook '(sweeprolog-analyze-start-font-lock)) @@ -2028,9 +2006,21 @@ variable at point, if any." (symbol-name v)))) (symbol-name v)))))) sweeprolog-mode sweeprolog-top-level-mode) - (let ((sweeprolog--variable-at-point-point (point)) - (sweeprolog--variable-at-point var)) - (font-lock-fontify-region point point))) + (save-excursion + (goto-char point) + (sweeprolog-analyze-term-at-point + (lambda (beg end arg) + (pcase arg + ((or "var" + `("goal_term" "meta" variable 0)) + (let ((cur (buffer-substring-no-properties beg end))) + (when (and var (string= cur var)) + (with-silent-modifications + (font-lock--add-text-property beg + end + 'font-lock-face + (sweeprolog-variable-at-point-face) + (current-buffer) nil)))))))))) (defun sweeprolog-cursor-sensor-functions (var) (list @@ -3086,8 +3076,6 @@ if-then-else constructs in SWI-Prolog." (when sweeprolog-enable-cursor-sensor (add-hook 'sweeprolog-analyze-region-fragment-hook #'sweeprolog-analyze-fragment-variable nil t) - (add-hook 'sweeprolog-analyze-region-end-hook - #'sweeprolog-analyze-end-variable nil t) (cursor-sensor-mode 1))) (add-to-list 'auto-insert-alist