0

我对 UltiSnip doc 给出的示例进行了修改:

snippet "be(gin)?( (\S+))?" "begin{} / end{}" br
\begin{${1:`!p
snip.rv = match.group(3) if match.group(2) is not None else "something"`}}${2:`!p
if match.group(2) is not None and match.group(3) != "proof":
    snip.rv = "\label{"+t[1]+":}"`}
    ${3:${VISUAL}}
\end{$1}$0
endsnippet

其中,与原来的相比,添加一个\label{envname:},如果envname是,proof那么我们没有添加它。这在我们编写环境时会很有帮助thm,例如

be lem<tab>会给

\begin{lem}\label{lem:} <c-j> \end{lem} 唯一的缺点是,我不知道如何在位置添加占位符\label{lem:$4}。任何想法?

4

1 回答 1

0

我得到一个工作版本,但代码不干净:

snippet "be(gin)?( (\S+))?" "begin{} / end{}" br \begin{${1:`!p snip.rv = match.group(3) if match.group(2) is not None else "something"`}}${2:`!p if match.group(2) is not None and match.group(3) != "proof": snip.rv = '\label{'+t[1]+':'`$4`!p if match.group(2) is not None and match.group(3) != "proof": snip.rv ='}'`} ${3:${VISUAL}} \end{$1}$0 endsnippet

于 2016-10-06T01:39:39.163 回答