From: Dmitry Gutov Date: Fri, 13 Dec 2013 04:14:17 +0000 (+0200) Subject: Make blink-matching-paren perform blinking without moving the cursor X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~432 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=84c73ba09921f0918d98a5f5784d35d2db9a7577;p=emacs.git Make blink-matching-paren perform blinking without moving the cursor * 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). --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5a0718bc3de..7b0e00d0251 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2013-12-13 Dmitry Gutov + + * 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 * indent.el (indent-region): Disable progress reporter in diff --git a/lisp/faces.el b/lisp/faces.el index 0e965a89ba7..3797056b167 100644 --- a/lisp/faces.el +++ b/lisp/faces.el @@ -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) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Manipulating font names. diff --git a/lisp/paren.el b/lisp/paren.el index 6f386573b01..5db5878ccf5 100644 --- a/lisp/paren.el +++ b/lisp/paren.el @@ -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") diff --git a/lisp/simple.el b/lisp/simple.el index 4c6c836b700..78fb12f8c9c 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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)