是否存在emacs智能括号匹配插件/配置?

时间:2023-01-23 20:32:44

In emacs is there a mode where if I type ( it autocloses it like so (), but if I put it infront of a word like so (word it doesnt do ()word, but just intelligently stays like (word? I've tried smartparens and autopair to no avail, but maybe i haven't configured them correctly?

在emacs中有一种模式,如果我输入(它就像so()那样自动关闭它,但如果我把它放在一个像这样的单词的前面(单词它不做()单词,但只是聪明地保持(单词?我是尝试smartparens和autopair无济于事,但也许我还没有正确配置它们?

2 个解决方案

#1


Use the built-in (as of version 24.something) electric-pair-mode with conservative pairing:

使用带有保守配对的内置(版本24.something)电对模式:

(setq-default electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)
(electric-pair-mode 1)

#2


For programming, I find paredit to give me all I need. It preserves balancedness.

对于编程,我发现paredit给了我所需要的一切。它保持平衡。

Entering an opening parenthesis will also enter the closing one after points:

输入左括号也将在点后输入结束括号:

(()

(→()

You can directly enclose the expression after point with a new pair of parenthesis:

您可以使用一对新括号直接用点括起表达式:

Meta-((expr)

Meta-(→(expr)

There are many other commands that slurp and barf sub-expressions to/from the front and rear, exchange expressions, moving on the different levels, etc., all preserving balancedness of parentheses.

还有许多其他命令可以在前后交替使用slurp和barf子表达式,交换表达式,在不同级别上移动等等,这些都保持括号的平衡性。

For example, if you have some expressions (| denotes point):

例如,如果你有一些表达式(|表示点):

|expr1 expr0 expr2 expr3

Meta-(

(|expr1) expr0 expr2 expr3

Ctrl-Shift-)

(|expr1 expr0) expr2 expr3

Ctrl-Shift-)

(|expr1 expr0 expr2) expr3

Meta-f

(expr1| expr0 expr2) expr3

Ctrl-Meta-t

(expr0 expr1| expr2) expr3

Ctrl-{

expr0 (expr1| expr2) expr3

Ctrl-Meta-u

expr0 |(expr1 expr2) expr3

Ctrl-Meta-f

expr0 (expr1 expr2) |expr3

#1


Use the built-in (as of version 24.something) electric-pair-mode with conservative pairing:

使用带有保守配对的内置(版本24.something)电对模式:

(setq-default electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit)
(electric-pair-mode 1)

#2


For programming, I find paredit to give me all I need. It preserves balancedness.

对于编程,我发现paredit给了我所需要的一切。它保持平衡。

Entering an opening parenthesis will also enter the closing one after points:

输入左括号也将在点后输入结束括号:

(()

(→()

You can directly enclose the expression after point with a new pair of parenthesis:

您可以使用一对新括号直接用点括起表达式:

Meta-((expr)

Meta-(→(expr)

There are many other commands that slurp and barf sub-expressions to/from the front and rear, exchange expressions, moving on the different levels, etc., all preserving balancedness of parentheses.

还有许多其他命令可以在前后交替使用slurp和barf子表达式,交换表达式,在不同级别上移动等等,这些都保持括号的平衡性。

For example, if you have some expressions (| denotes point):

例如,如果你有一些表达式(|表示点):

|expr1 expr0 expr2 expr3

Meta-(

(|expr1) expr0 expr2 expr3

Ctrl-Shift-)

(|expr1 expr0) expr2 expr3

Ctrl-Shift-)

(|expr1 expr0 expr2) expr3

Meta-f

(expr1| expr0 expr2) expr3

Ctrl-Meta-t

(expr0 expr1| expr2) expr3

Ctrl-{

expr0 (expr1| expr2) expr3

Ctrl-Meta-u

expr0 |(expr1 expr2) expr3

Ctrl-Meta-f

expr0 (expr1 expr2) |expr3