与 AUCTeX 一起使用时,在 $0 之后以 % 结束行的 yasnippets 行为很奇怪
Yasnippet 片段有一个百分号 %
,以片段的最后一个点 $0
结束一行,百分号之前的行为很奇怪,因为光标被放置在之后百分号而不是百分号之前。我想知道如何才能避免这种奇怪的行为。
考虑以下代码片段:
# -*- mode: snippet -*-
# name: test snippet
# key: ts
# --
{
$0%
}
我认为当它被激活时,它应该插入三行,其中第一行包含{
,最后一行包含}
,第二行 %
并将光标放在第二行的 %
之前,如下例所示:
{
[cursor]%
}
但会发生以下情况:
{
% [cursor]
}
如何使代码片段表现良好正如我认为应该的那样?
我的猜测是,这是由于 AUCTeX 中的某些原因造成的,因为它发生在 AUCTeX 激活的情况下,但不是在主要模式 Lisp Interaction 中。
Yasnippet snippets that has a percent sign, %
, ending a line with the last point of the snippet, $0
, before the percent sign acts strange in that the cursor gets placed after the percent sign and not before it. I wonder how I can avoid this strange behavior.
Consider the following snippet:
# -*- mode: snippet -*-
# name: test snippet
# key: ts
# --
{
$0%
}
I take it that as it's activated it should insert three lines where the first contains {
, the last line }
and the second line %
and place the cursor before %
on the second line as in the following example:
{
[cursor]%
}
But what happens is the following:
{
% [cursor]
}
How can I make it so that the snippet behaves as I think it should?
My guess is that this is due to something in AUCTeX because it happens with AUCTeX activated but not in the major mode Lisp Interaction.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它适用于我的配置,但我怀疑它与自动缩进有关(我的配置是经过大量定制的,因此可能有所不同)。 您仍然会看到问题吗
如果将或
添加到代码片段的标题中, ?您还可以尝试将
$>
添加到您想要缩进的行中,看看这是否会产生影响(如果确实如此,则会大大缩小范围)。 yasnippet 代码中有一条关于标记更改位置的一些问题的注释,但看起来几年前已修复。您还应该检查
indent-line-function
是否具有正确的值,即LaTeX-indent-line
。您可以在 yas/indent-according-to-mode 的定义中添加一些
sit-for
来查看不同阶段的点。例如,将以下内容放入临时缓冲区中,将光标置于其末尾并键入Cx Ce
。然后照常插入您的代码片段,代码中每当您看到(sit-for 1)
时,它就会暂停 1 秒。因此,如果光标从错误的位置开始,那么您就知道问题出在缩进之前,等等。您必须监视缩进的每一行,因此您可能希望通过 < 关闭有问题的行之外的缩进代码>$>。添加或删除sit-for
可以让您缩小范围。It works right with my configuration, but I suspect it has to do with auto indenting (mine is heavily customized so that may be the difference). Do you still see the problem if you add
or
to the snippet's header? You can also try adding
$>
to the line(s) that you want indented to see if that makes a difference (if it does that would narrow things down a lot). There is a note in the yasnippet code about some problems with markers changing places, but that looks like it was fixed a few years ago.You should also check that
indent-line-function
has the proper value namelyLaTeX-indent-line
.You could add some
sit-for
's to the definition ofyas/indent-according-to-mode
to see where point is at different stages. For example put the following in a scratch buffer, position your cursor after the end of it and typeC-x C-e
. Then insert your snippet as usual and it will pause for 1 second every where in the code you see a(sit-for 1)
. So if the cursor starts out in the wrong place, then you know the problem is before indentation, etc. You will have to watch it for every line that is indented, so you may wish to turn off indentation except for the problematic line via$>
. Adding or removingsit-for
's will allow you to narrow it down.