Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Brace and Bracket Highlighting?

When entering code Emacs transiently highlights the matching brace or bracket. With existing code however is there a way to ask it to highlight a matching brace or bracket if I highlight its twin?

I am often trying to do a sanity check when dealing with compiler errors and warnings. I do enter both braces usually when coding before inserting the code in between, but have on occasion unintentionally commented out one brace when commenting out code while debugging.

Any advice with dealing with brace and bracket matching with Emacs?

OS is mostly Linux/Unix, but I do use it also on OS X and Windows.

like image 573
haziz Avatar asked Feb 26 '12 15:02

haziz


2 Answers

If you're dealing with a language that supports it, give ParEdit a serious look. If you're not using with a Lisp dialect, it's not nearly as useful though.

For general brace/bracket/paren highlighting, look into highlight-parentheses mode (which color codes multiple levels of braces whenever point is inside them). You can also turn on show-paren-mode through customizations (that is M-x customize-variable show-paren-mode); that one strongly highlights the brace/bracket/paren matching one at point (if the one at point doesn't match anything, you get a different color).

my .emacs currently contains (among other things)

(require 'highlight-parentheses)

(define-globalized-minor-mode global-highlight-parentheses-mode highlight-parentheses-mode
  (lambda nil (highlight-parentheses-mode t)))

(global-highlight-parentheses-mode t)

as well as that show-paren-mode customization, which serves me well (of course, I also use paredit when lisping, but these are still marginally useful).

like image 127
Inaimathi Avatar answered Sep 24 '22 15:09

Inaimathi


Apart from the answer straight from the manual or wiki, also have a look at autopair.

like image 42
Roland Smith Avatar answered Sep 23 '22 15:09

Roland Smith