ShowParenMode

show-paren-mode allows one to see matching pairs of parentheses and other characters. When point is on the opening character of one of the paired characters, the other is highlighted. When the point is after the closing character of one of the paired characters, the other is highlighted. Activate it once by running

    M-x show-paren-mode RET

or make it permanent by putting the following into your .emacs file:

    (show-paren-mode 1)

By default, there’s a small delay before showing a matching parenthesis. It can be deactivated with the following (which you have to do before activating show-paren-mode in your .emacs):

    (setq show-paren-delay 0)

To make this mode local to the buffer, use (make-variable-buffer-local 'show-paren-mode) and add something like this to your .emacs:

    (defun lispy-parens ()
      "Setup parens display for lisp modes"
      (setq show-paren-delay 0)
      (setq show-paren-style 'parenthesis)
      (make-variable-buffer-local 'show-paren-mode)
      (show-paren-mode 1)
      (set-face-background 'show-paren-match-face (face-background 'default))
      (if (boundp 'font-lock-comment-face)
          (set-face-foreground 'show-paren-match-face 
     			   (face-foreground 'font-lock-comment-face))
        (set-face-foreground 'show-paren-match-face 
     			 (face-foreground 'default)))
      (set-face-attribute 'show-paren-match-face nil :weight 'extra-bold))

To change the color/face:

    (require 'paren)
    (set-face-background 'show-paren-match (face-background 'default))
    (set-face-foreground 'show-paren-match "#def")
    (set-face-attribute 'show-paren-match nil :weight 'extra-bold)

How to show the matching paren when it is offscreen

See ‘blink-matching-paren’ and ‘blink-matching-paren-distance’.

Note this change in etc/NEWS:

* Editing Changes in Emacs 24.4

** `blink-matching-paren' now only highlights the matching open-paren
by default, instead of moving the cursor.  Set this variable to `jump' to
restore the old behavior.

Links


CategoryParentheses CategoryModes ParenthesesAppearance