]> code.delx.au - gnu-emacs/commitdiff
Make blink-matching-paren perform blinking without moving the cursor
authorDmitry Gutov <dgutov@yandex.ru>
Fri, 13 Dec 2013 04:14:17 +0000 (06:14 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 13 Dec 2013 04:14:17 +0000 (06:14 +0200)
* lisp/faces.el (paren-showing-faces, show-paren-match)
(show-paren-mismatch): Move from paren.el.

* lisp/simple.el (blink-matching--overlay): New variable.
(blink-matching-open): Instead of moving point, highlight the
matching paren with an overlay
(http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00333.html).

lisp/ChangeLog
lisp/faces.el
lisp/paren.el
lisp/simple.el

index 5a0718bc3deb91a2e14485df17e343a33840fc4b..7b0e00d02514b21925eb1bcbd450df34192e4306 100644 (file)
@@ -1,3 +1,13 @@
+2013-12-13  Dmitry Gutov  <dgutov@yandex.ru>
+
+       * simple.el (blink-matching--overlay): New variable.
+       (blink-matching-open): Instead of moving point, highlight the
+       matching paren with an overlay
+       (http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00333.html).
+
+       * faces.el (paren-showing-faces, show-paren-match)
+       (show-paren-mismatch): Move from paren.el.
+
 2013-12-13  Leo Liu  <sdl.web@gmail.com>
 
        * indent.el (indent-region): Disable progress reporter in
index 0e965a89ba73fa4eb13e3e4c71658872a4768230..3797056b167d21f140137fc8412051d43263d217 100644 (file)
@@ -2573,6 +2573,30 @@ It is used for characters of no fonts too."
   "Face for displaying the currently selected item in TTY menus."
   :group 'basic-faces)
 
+(defgroup paren-showing-faces nil
+  "Faces used to highlight paren matches."
+  :group 'paren-showing
+  :group 'faces
+  :version "22.1")
+
+(defface show-paren-match
+  '((((class color) (background light))
+     :background "turquoise")          ; looks OK on tty (becomes cyan)
+    (((class color) (background dark))
+     :background "steelblue3")         ; looks OK on tty (becomes blue)
+    (((background dark))
+     :background "grey50")
+    (t
+     :background "gray"))
+  "Face used for a matching paren."
+  :group 'paren-showing-faces)
+
+(defface show-paren-mismatch
+  '((((class color)) (:foreground "white" :background "purple"))
+    (t (:inverse-video t)))
+  "Face used for a mismatching paren."
+  :group 'paren-showing-faces)
+
 \f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Manipulating font names.
index 6f386573b01946e9bce0ea199ade0e86c9039b65..5db5878ccf5e774fecbc5311677df84db47615a4 100644 (file)
@@ -72,30 +72,8 @@ active, you must toggle the mode off and on again for this to take effect."
   :group 'paren-showing
   :version "20.3")
 
-(defgroup paren-showing-faces nil
-  "Group for faces of Show Paren mode."
-  :group 'paren-showing
-  :group 'faces
-  :version "22.1")
-
-(defface show-paren-match
-  '((((class color) (background light))
-     :background "turquoise")          ; looks OK on tty (becomes cyan)
-    (((class color) (background dark))
-     :background "steelblue3")         ; looks OK on tty (becomes blue)
-    (((background dark))
-     :background "grey50")
-    (t
-     :background "gray"))
-  "Show Paren mode face used for a matching paren."
-  :group 'paren-showing-faces)
 (define-obsolete-face-alias 'show-paren-match-face 'show-paren-match "22.1")
 
-(defface show-paren-mismatch
-  '((((class color)) (:foreground "white" :background "purple"))
-    (t (:inverse-video t)))
-  "Show Paren mode face used for a mismatching paren."
-  :group 'paren-showing-faces)
 (define-obsolete-face-alias 'show-paren-mismatch-face
   'show-paren-mismatch "22.1")
 
index 4c6c836b70062007a680c1feb18f78ba304622c0..78fb12f8c9c25ef788c7a1c63323d562d7bbfb16 100644 (file)
@@ -6308,8 +6308,15 @@ position just before the opening token and END is the position right after.
 START can be nil, if it was not found.
 The function should return non-nil if the two tokens do not match.")
 
+(defvar blink-matching--overlay
+  (let ((ol (make-overlay (point) (point) nil t)))
+    (overlay-put ol 'face 'show-paren-match)
+    (delete-overlay ol)
+    ol)
+  "Overlay used to highlight the matching paren.")
+
 (defun blink-matching-open ()
-  "Move cursor momentarily to the beginning of the sexp before point."
+  "Momentarily highlight the beginning of the sexp before point."
   (interactive)
   (when (and (not (bobp))
             blink-matching-paren)
@@ -6351,13 +6358,17 @@ The function should return non-nil if the two tokens do not match.")
             (message "No matching parenthesis found"))))
        ((not blinkpos) nil)
        ((pos-visible-in-window-p blinkpos)
-        ;; Matching open within window, temporarily move to blinkpos but only
-        ;; if `blink-matching-paren-on-screen' is non-nil.
+        ;; Matching open within window, temporarily highlight char
+        ;; after blinkpos but only if `blink-matching-paren-on-screen'
+        ;; is non-nil.
         (and blink-matching-paren-on-screen
              (not show-paren-mode)
-             (save-excursion
-               (goto-char blinkpos)
-               (sit-for blink-matching-delay))))
+             (unwind-protect
+                 (progn
+                   (move-overlay blink-matching--overlay blinkpos (1+ blinkpos)
+                                 (current-buffer))
+                   (sit-for blink-matching-delay))
+               (delete-overlay blink-matching--overlay))))
        (t
         (save-excursion
           (goto-char blinkpos)