Emacs: Highlight Parenthesis, show-paren-mode

By Xah Lee. Date: . Last updated: .

show-paren-mode will highlight matching brackets when your cursor is on one of the bracket.

;; turn on highlight matching brackets when cursor is on one
(show-paren-mode 1)

show-paren-mode has 2 styles of highlighting brackets.

emacs show-paren-mode 1
Highligh just the brackets.
emacs show-paren-mode 2
Highligh the whole expression.

By default, emacs highlights just the brackets. You can change it with the following code:

(setq show-paren-style 'parenthesis) ; highlight brackets

(setq show-paren-style 'expression) ; highlight entire expression

(setq show-paren-style 'mixed) ; highlight brackets if visible, else entire expression

Note: show-paren-mode will highlight any brackets, including () [] {} 「」 『』 【】 〖〗 〈〉 《》 ‹› «» ….

Change Paren Match Background Color

emacs 24.3 customize-face screen 2014-03-10
emacs 24.3 customize-face screen

You can change the default background color for highlighting the paren. Alt+x customize-face, then type “show-paren-match”. Change settings, click the button “Apply and Save” at the top. This will save the lisp code in your emacs init file. For example, the following shows in my emacs init file:

  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(show-paren-match ((((class color) (background light)) (:background "azure2")))))

To see a list of available colors and their names, Alt+x list-colors-display.

Like it? Buy Xah Emacs Tutorial. Thanks.