Subject: Re: bug#14395: 24.3; [PATCH] new feature smie-highlight-matching-block

From: Leo Liu <[email-masked]>
Date: Fri, 17 May 2013 09:30:34 +0800

On 2013-05-17 08:40 +0800, Stefan Monnier wrote:
> But in terms of functionality, your minor mode provides a behavior
> comparable to show-paren-mode, I think.

I agree.

> So maybe the better thing to do now is to try and see how to integrate
> so that it "just works" for people who use show-paren-mode.  Just like
> smie-blink-matching-open makes blink-matching-paren "just work".

Would it be OK if we let show-paren-mode turn on
smie-highlight-matching-block-mode?

I just realised that it doesn't clean up the overlays when
smie-highlight-matching-block-mode is turned off.

Should I install something like this? An alternative fix might be not to
make smie--highlight-matching-block-overlay buffer-local which is easier
to clean up.

diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index 21134578..3e78b76b 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1095,10 +1095,17 @@ (define-minor-mode smie-highlight-matching-block-mode nil
   (when (timerp smie--highlight-matching-block-timer)
     (cancel-timer smie--highlight-matching-block-timer))
   (setq smie--highlight-matching-block-timer nil)
-  (when smie-highlight-matching-block-mode
-    (remove-hook 'post-self-insert-hook #'smie-blink-matching-open 'local)
-    (setq smie--highlight-matching-block-timer
-          (run-with-idle-timer 0.2 t #'smie-highlight-matching-block))))
+  (if smie-highlight-matching-block-mode
+      (progn
+        (remove-hook 'post-self-insert-hook #'smie-blink-matching-open 'local)
+        (setq smie--highlight-matching-block-timer
+              (run-with-idle-timer 0.2 t #'smie-highlight-matching-block)))
+    ;; Clean up.
+    (dolist (b (buffer-list))
+      (with-current-buffer b
+        (when (overlayp smie--highlight-matching-block-overlay)
+          (delete-overlay smie--highlight-matching-block-overlay)
+          (kill-local-variable smie--highlight-matching-block-overlay))))))
 
 ;;; The indentation engine.