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

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

[nongnu] elpa/highlight-parentheses 59ff08a 23/49: Merge pull request #1


From: ELPA Syncer
Subject: [nongnu] elpa/highlight-parentheses 59ff08a 23/49: Merge pull request #11 from tsdh/master
Date: Sun, 15 Aug 2021 03:57:46 -0400 (EDT)

branch: elpa/highlight-parentheses
commit 59ff08a07f25a8e571632207b3d48fda1f6cad27
Merge: f3b1acc 5e1fa9d
Author: Nikolaj Schumacher <me@nschum.de>
Commit: Nikolaj Schumacher <me@nschum.de>

    Merge pull request #11 from tsdh/master
    
    Fix slowdown by moving overlays less often.
---
 highlight-parentheses.el | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/highlight-parentheses.el b/highlight-parentheses.el
index 0597721..1159b0f 100644
--- a/highlight-parentheses.el
+++ b/highlight-parentheses.el
@@ -96,6 +96,9 @@ Color attributes might be overriden by `hl-paren-colors' and
 This is used to prevent analyzing the same context over and over.")
 (make-variable-buffer-local 'hl-paren-last-point)
 
+(defvar hl-paren-timer nil
+  "A timer initiating the movement of the `hl-paren-overlays'.")
+
 (defun hl-paren-highlight ()
   "Highlight the parentheses around point."
   (unless (= (point) hl-paren-last-point)
@@ -109,13 +112,18 @@ This is used to prevent analyzing the same context over 
and over.")
                         (cdr overlays))
               (move-overlay (pop overlays) pos1 (1+ pos1))
               (when (setq pos2 (scan-sexps pos1 1))
-                (move-overlay (pop overlays) (1- pos2) pos2)
-                ))
+                (move-overlay (pop overlays) (1- pos2) pos2)))
           (error nil))
         (goto-char pos))
       (dolist (ov overlays)
         (move-overlay ov 1 1)))))
 
+(defun hl-paren-initiate-highlight ()
+  "Move the `hl-paren-overlays' after a short fraction of time."
+  (when hl-paren-timer
+    (cancel-timer hl-paren-timer))
+  (setq hl-paren-timer (run-at-time 0.23 nil #'hl-paren-highlight)))
+
 ;;;###autoload
 (define-minor-mode highlight-parentheses-mode
   "Minor mode to highlight the surrounding parentheses."
@@ -123,10 +131,10 @@ This is used to prevent analyzing the same context over 
and over.")
   (mapc 'delete-overlay hl-paren-overlays)
   (kill-local-variable 'hl-paren-overlays)
   (kill-local-variable 'hl-paren-last-point)
-  (remove-hook 'post-command-hook 'hl-paren-highlight t)
+  (remove-hook 'post-command-hook 'hl-paren-initiate-highlight t)
   (when highlight-parentheses-mode
     (hl-paren-create-overlays)
-    (add-hook 'post-command-hook 'hl-paren-highlight nil t)))
+    (add-hook 'post-command-hook 'hl-paren-initiate-highlight nil t)))
 
 ;;;###autoload
 (define-globalized-minor-mode global-highlight-parentheses-mode
@@ -148,7 +156,7 @@ This is used to prevent analyzing the same context over and 
over.")
         (setq attributes (plist-put attributes :background (car bg))))
       (pop bg)
       (dotimes (i 2) ;; front and back
-        (push (make-overlay 0 0) hl-paren-overlays)
+        (push (make-overlay 0 0 nil t) hl-paren-overlays)
         (overlay-put (car hl-paren-overlays) 'face attributes)))
     (setq hl-paren-overlays (nreverse hl-paren-overlays))))
 



reply via email to

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