garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.

Home Page:www.vim.org/scripts/script.php?script_id=2540

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Defaulting value to another value bug

bogdan opened this issue · comments

Let's say we have the following skippet:

k.snippet:

:${1:} => ${2:$1}

Key sequence: ik<Tab>hello<Tab> should:

  • enter insert mode
  • expand the snippet
  • fill in first value
  • set second value default to first value
  • highlight second value, but it is not

I don't know whether this is even supported - neither do I think I would
support it because my feeling is that the engine behind xptemplate
already supports this all (give it a try and report your results,
please).
So I'd change this issue into "let's merge xptemplate and snipmate" -
but I don't have time to work on it at the moment :(

About your description:
Its not accurate enough because you don't know what the current state
is. So I've tested it and report my results:
I don't even get the second placeholder to jump to by using tab.
The second place holder appears if you replace the $1 within ${2:$1} by
a value such as "word".

I'm quite sure that current vim-snipmate implementation doesn't provide this feature. So, if we agree I could label this issue as a feature request and change the title to "support for using placeholders for default values" or something better you could sugget. We can leave it open until we find a good way to do it.

P.S. @MarcWeber What Do you think about labeling issues? I can do it if you like the idea.

I use the following snippet with original repo and this fork without any problem for ages:

let(:${1:}) do
  Factory.create(:${2:$1})
end

If it is working and was working than this issue is bug.

let(:${1:}) do
  Factory.create(:${2:$1})
end

is working (I confirm) - at least partially: The cursor is put before
the ${2 but the word is not selected in any way.

:${1:} => ${2:$1}
is not.

So can you describe in more detail what broke exactly?

Broken thing is:

${2 but the word is not selected in any way.

This was working before.

Excerpts from Bogdan Gusiev's message of Tue Oct 18 10:25:41 +0200 2011:

This was working before.
which commit?

Did a little more investigation and found out that not selected second value bug appear only when ${1} do not have default value.
And it doesn't work even with msanders's version.

So the following:

let(:${1:name}) do
  Factory.create(:${2:$1})
end

Works

And the following:

let(:${1:}) do
  Factory.create(:${2:$1})
end

Doesn't work.

Sorry for messing you, Marc.
If you consider this not a bug - you may close it - as it is behavior of the original version.

Excerpts from Bogdan Gusiev's message of Tue Oct 18 11:12:41 +0200 2011:

Sorry for messing you, Marc.
If you consider this not a bug - you may close it - as it is behavior of the original version.
You're kidding. Of course its a bug :)
I checked an older version and saw it doesn't work either. That's why I
had to ask. Your investigation however gives more details. Would you
mind adding a bug section the README describing the problem for now?
Eventually somebody with the given skill level required picks it up and
solves it. I don't want to dive into the details of the snipmate engine
at this point in time - and before doing so I'd like to investigate
xpemplate as well which I talked about earlier.

I'd prefer the README because its more likely that people read it and
its distributed compared to the github bug tracker.

This happens because of the way SnipMate keeps track of and updates everything. It simply stores the line number and column number of where tab stops and variables start and end. This simplistic way means that there's no real way to tell that in ${2:$1} the second tabstop starts before that variable. SnipMate updates the variable just fine, but can't tell that it needs to also update where the tabstop ends.

There is no easy way to fix this using the current implementation. However, I'm going to leave this issue open in case I manage to think of something clever.

This seems to have been fixed along with the work on allowing nested stops.

Note: This is only fixed for g:snipMate.snippet_version = 1.