From: Eshel Yaron Date: Tue, 15 Nov 2022 20:55:32 +0000 (+0200) Subject: Add sweeprolog-analyze-some-terms to after-change-functions X-Git-Tag: V8.5.20-sweep-0.8.8~4 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5e6f85a0948f922f8946099c23e293f6b45c486a;p=sweep.git Add sweeprolog-analyze-some-terms to after-change-functions --- diff --git a/sweep.pl b/sweep.pl index 13933d8..233c7ef 100644 --- a/sweep.pl +++ b/sweep.pl @@ -463,7 +463,10 @@ sweep_color_normalized_(_, Goal0, [Kind0,Head|_], [Goal,Kind,F,N]) :- !, atom_string(Goal0, Goal), term_string(Kind0, Kind), - ( var(Head) + ( ( var(Head) + -> true + ; Head == [] + ) -> F = Head, N = 0 ; pi_head(F0/N, Head), atom_string(F0, F) diff --git a/sweeprolog.el b/sweeprolog.el index 519f18e..bc4a46f 100644 --- a/sweeprolog.el +++ b/sweeprolog.el @@ -1783,9 +1783,22 @@ resulting list even when found in the current clause." ("type_error" (list (list beg end (sweeprolog-type-error-face)))) (`("syntax_error" ,_ ,eb ,ee) - (list (list eb ee nil) - (list eb ee (sweeprolog-around-syntax-error-face)) - (list beg end (sweeprolog-syntax-error-face)))) + (save-excursion + (goto-char (min ee (point-max))) + (let ((ws nil) + (cur (point))) + (while (and (forward-comment 1) + (forward-comment -1)) + (push (list cur (point) nil) ws) + (forward-comment 1) + (setq cur (point))) + (skip-chars-forward " \t\n") + (push (list cur (point) nil) ws) + (cons (list beg (point) nil) + (append (list (list eb ee nil) + (list eb ee (sweeprolog-around-syntax-error-face)) + (list beg end (sweeprolog-syntax-error-face))) + ws))))) ("unused_import" (list (list beg end (sweeprolog-unused-import-face)))) ("undefined_import" @@ -1840,7 +1853,7 @@ resulting list even when found in the current clause." (push (list cur (point) nil) ws) (cons (list beg (point) nil) (cons (list beg end (sweeprolog-fullstop-face)) - ws))))) + ws))))) ("functor" (list (list beg end (sweeprolog-functor-face)))) ("arity" @@ -2073,24 +2086,26 @@ modified." (sweeprolog-analyze-region start (point) "true"))))) (defun sweeprolog-analyze-some-terms (beg end &optional _verbose) - (save-mark-and-excursion - (goto-char beg) - (sweeprolog-beginning-of-top-term) - (unless (bobp) - (forward-char -1) + (save-match-data + (save-mark-and-excursion + (goto-char beg) (sweeprolog-beginning-of-top-term) - (unless (bobp) (forward-char -1))) - (let ((start (point)) - (cur (point))) - (while (and (not (eobp)) - (< (point) end)) + (unless (bobp) + (forward-char -1) + (sweeprolog-beginning-of-top-term) + (unless (bobp) (forward-char -1))) + (let ((start (point)) + (cur (point))) + (while (and (not (eobp)) + (< (point) end)) + (setq cur (point)) + (sweeprolog-end-of-top-term) + (sweeprolog-analyze-term cur (point))) (setq cur (point)) (sweeprolog-end-of-top-term) - (sweeprolog-analyze-term cur (point))) - (setq cur (point)) - (sweeprolog-end-of-top-term) - (sweeprolog-analyze-term cur (point)) - `(jit-lock-bounds ,start . ,(point))))) + (skip-chars-forward " \t\n") + (sweeprolog-analyze-term cur (point)) + `(jit-lock-bounds ,start . ,(point)))))) (defun sweeprolog-syntax-propertize (start end) (goto-char start) @@ -3192,7 +3207,9 @@ certain contexts to maintain conventional Prolog layout." nil (font-lock-fontify-region-function . sweeprolog-analyze-some-terms))) (add-hook 'after-change-functions - #'sweeprolog--update-buffer-last-modified-time) + #'sweeprolog--update-buffer-last-modified-time nil t) + (add-hook 'after-change-functions + #'sweeprolog-analyze-some-terms nil t) (when sweeprolog-enable-eldoc (when (fboundp 'eldoc-documentation-default) (setq-local eldoc-documentation-strategy #'eldoc-documentation-default))