开发者

How can I find missing or mismatched braces / parens in emacs?

When my cod开发者_C百科e fails to compile and tells me that I am likely missing a closed brace, is there an easy way to find it in emacs?


For languages like C, C++, and Java, the command check-parens will check parens (()), brackets ([]), and braces ({}):

M-x check-parens <RET>

The point will move to a bracketing character that is unmatched, and the status line will report the problem.

It's a good idea to use this in conjunction with show-paren-mode as others have said.


If you use following code in your .emacs then if you are before or after a bracket it will highlight all of the expression between them - might help you find mismatched brackets.

(show-paren-mode t)
(setq show-paren-style 'expression)


Show Paren Mode will highlight bad braces as you type them. I don't know how to find them after the fact.


I use the rainbow-delimiters package mode exactly for that reason.

My settings:

(require 'rainbow-delimiters)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(set-face-attribute 'rainbow-delimiters-unmatched-face nil
            :foreground "red"
            :inherit 'error
            :box t)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜