在与AUCTeX一起使用时,以$ 0结束行的yasnippets行为奇怪 [英] yasnippets with % ending the line after $0 acts strange when used with AUCTeX

查看:160
本文介绍了在与AUCTeX一起使用时,以$ 0结束行的yasnippets行为奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具有百分比符号的Yasnippet片段,结束与片段最后一点的一行, $ 0 ,在百分号表示奇怪之前,光标位于百分号之后而不在之前。我想知道如何避免这种奇怪的行为。

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.

考虑以下代码段:

# -*- 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]%
}

但是会发生以下情况:

{
  % [cursor]
}

如何使代码段按照我的想法行事?

How can I make it so that the snippet behaves as I think it should?

我的猜测是,这是由于AUCTeX中的某些事情,因为它发生在AUCTeX激活但不是在主要模式Lisp交互中。

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.

推荐答案

它与我的配置正常,但我怀疑它与自动缩进有关(我的定制很大,这可能是有区别的)。如果您添加了

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

# expand-env: ((yas/indent-line 'fixed))

# expand-env: ((yas/indent-line t))

头?您还可以尝试向要缩进的行添加 $> ,看看是否有所作为(如果这样做会使事情缩小) 。在yasnippet代码中有一个注释关于标记更改位置的一些问题,但看起来像几年前已经修复了。

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.

您还应该检查 indent-line-function 具有适当的值,即 LaTeX-indent-line

You should also check that indent-line-function has the proper value namely LaTeX-indent-line.

您可以为 yas / indent-on-mode sit $ c>来看看点在不同阶段。例如,将以下内容放在暂存缓冲区中,将光标放在结尾处,然后键入 C-x C-e 。然后像往常一样插入你的代码段,它将暂停1秒,每个代码中你看到一个(坐在1)。因此,如果光标在错误的地方开始,那么您知道在缩进之前的问题等等。您将不得不对每个缩进的行进行查看,因此除了有问题的行以外,您可能希望关闭缩进, code> $> 。添加或删除 sit-for 将允许您缩小。

You could add some sit-for's to the definition of yas/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 type C-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 removing sit-for's will allow you to narrow it down.

(defun yas/indent-according-to-mode (snippet-markers)
  "Indent current line according to mode, preserving
SNIPPET-MARKERS."
  (sit-for 1)
  (goto-char (yas/real-line-beginning))
  (sit-for 1)
  (let ((trouble-markers (remove-if-not #'(lambda (marker)
                                            (= marker (point)))
                                        snippet-markers)))
    (save-restriction
      (widen)
      (sit-for 1)
      (condition-case err
          (indent-according-to-mode)
        (error (message "[yas] warning: yas/indent-according-to-mode habing problems running %s" indent-line-function)
               nil)))
    (sit-for 1)
    (mapc #'(lambda (marker)
              (set-marker marker (point)))
          trouble-markers)))

这篇关于在与AUCTeX一起使用时,以$ 0结束行的yasnippets行为奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆