GNU bug report logs - #14395
24.3; [PATCH] new feature smie-highlight-matching-block

Previous Next

Package: emacs;

Reported by: Leo Liu <sdl.web <at> gmail.com>

Date: Tue, 14 May 2013 02:51:03 UTC

Severity: wishlist

Tags: patch

Found in version 24.3

Done: Leo Liu <sdl.web <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Leo Liu <sdl.web <at> gmail.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#14395: closed (24.3; [PATCH] new feature smie-highlight-matching-block)
Date: Thu, 16 May 2013 23:11:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 17 May 2013 07:09:48 +0800
with message-id <m1vc6i8qtf.fsf <at> gmail.com>
and subject line Re: bug#14395: 24.3; [PATCH] new feature smie-highlight-matching-block
has caused the debbugs.gnu.org bug report #14395,
regarding 24.3; [PATCH] new feature smie-highlight-matching-block
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
14395: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14395
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Leo Liu <sdl.web <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; [PATCH] new feature smie-highlight-matching-block
Date: Tue, 14 May 2013 10:49:20 +0800
[Message part 3 (text/plain, inline)]
Hi Stefan,

I want something for octave mode that looks like something in the
attached screenshot. But since this is generic I would like to put it in
smie.el. Do you have any objections or comments?

It doesn't make sense for this feature and smie-blink-matching-open to
be on at the same time. So in the patch nothing is enabled.


diff --git a/lisp/emacs-lisp/smie.el b/lisp/emacs-lisp/smie.el
index bbdd9f83..ad23f78c 100644
--- a/lisp/emacs-lisp/smie.el
+++ b/lisp/emacs-lisp/smie.el
@@ -1021,6 +1021,61 @@ (defun smie-blink-matching-open ()
             (let ((blink-matching-check-function #'smie-blink-matching-check))
               (blink-matching-open))))))))
 
+(defface smie-matching-block-highlight (:inherit highlight)
+  "Face used to highlight matching block."
+  :group 'smie)
+
+(defvar-local smie-highlight-matching-block-overlay nil)
+(defvar-local smie-highlight-matching-block-lastpos -1)
+
+(defun smie-highlight-matching-block ()
+  (when (and (bound-and-true-p smie-closer-alist)
+             (/= (point) smie-highlight-matching-block-lastpos))
+    (unless (overlayp smie-highlight-matching-block-overlay)
+      (setq smie-highlight-matching-block-overlay
+            (make-overlay (point) (point))))
+    (setq smie-highlight-matching-block-lastpos (point))
+    (let ((open-re (concat "\\_<"
+                           (regexp-opt (mapcar 'car smie-closer-alist))
+                           "\\_>"))
+          (close-re (concat "\\_<"
+                            (regexp-opt (mapcar 'cdr smie-closer-alist))
+                            "\\_>"))
+          (beg-of-tok
+           (lambda (re)
+             "Move to the beginning of current token if matching RE."
+             (or (looking-at-p re)
+                 (let* ((start (point))
+                        (beg (progn
+                               (funcall smie-backward-token-function)
+                               (and (looking-at-p re) (point))))
+                        (end (and beg
+                                  (progn
+                                    (funcall smie-forward-token-function)
+                                    (point)))))
+                   (if (and beg (<= beg start) (<= start end))
+                       (goto-char beg)
+                     (goto-char start)
+                     nil)))))
+          (highlight (lambda (beg end)
+                       (move-overlay smie-highlight-matching-block-overlay
+                                     beg end)
+                       (overlay-put smie-highlight-matching-block-overlay
+                                    'face 'smie-matching-block-highlight))))
+      (save-excursion
+        (cond
+         ((funcall beg-of-tok open-re)
+          (with-demoted-errors
+            (forward-sexp 1)
+            (when (looking-back close-re)
+              (funcall highlight (match-beginning 0) (match-end 0)))))
+         ((funcall beg-of-tok close-re)
+          (funcall smie-forward-token-function)
+          (forward-sexp -1)
+          (when (looking-at open-re)
+            (funcall highlight (match-beginning 0) (match-end 0))))
+         (t (overlay-put smie-highlight-matching-block-overlay 'face nil)))))))
+
 ;;; The indentation engine.
 
 (defcustom smie-indent-basic 4


[smie-highlight.png (image/png, attachment)]
[Message part 5 (message/rfc822, inline)]
From: Leo Liu <sdl.web <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 14395-done <at> debbugs.gnu.org
Subject: Re: bug#14395: 24.3; [PATCH] new feature smie-highlight-matching-block
Date: Fri, 17 May 2013 07:09:48 +0800
Fixed in trunk.

On 2013-05-17 01:51 +0800, Stefan Monnier wrote:
> I know, but removing it where you remove it has mostly no effect (it's
> normally run from a major-mode body, so all the vars have been set
> back to their global value).

OK, corrected as suggested.

>> I am not sure there is.
>
> Doesn't show-paren-mode do that?

I didn't do anything to integrate with show-paren-mode. Not sure what to
do. There are packages outside emacs that replace show-paren-mode.

> OK.
> BTW, feel free to commit your current code in the mean time.

OK, committed and thanks for all the help.

Leo


This bug report was last modified 12 years and 58 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.