ultisnips icon indicating copy to clipboard operation
ultisnips copied to clipboard

Wrong tabstop position with non-latin characters

Open SirVer opened this issue 10 years ago • 17 comments

I have the following snippet:

snippet se "" b
,{
  'AUTHOR': '${1:Williams}',
  'TEXT': '${VISUAL}$2',
}
endsnippet

When I skip first tabstop without changing default text, the second tabstop shows itself beyond single quotes as if we would have ...'$2,... instead of ...$2',... But when default text in the first tabstop is changed the second tabstop appears in the right place.

Launchpad Details: #LP1256451 Andrei - 2013-11-30 00:11:05 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

I cannot reproduce this. I copy and pasted your snippet, unintended it, so that ,{ is starting at the begging of the line. In an empty file I type:

sehello worldblub

output is as expected:

------------------- SNIP ------------------- ,{ 'AUTHOR': 'Williams', 'TEXT': 'hello world', }blub ------------------- SNAP -------------------

Launchpad Details: #LPC SirVer - 2013-12-01 14:42:58 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

what version of ultisnips are you using (and from where)? Which version of Vim and which OS are you using? Also, gvim or vim on console. Please try to reproduce the bug in a simple fashion and describe your steps similar to what I just did.

Launchpad Details: #LPC SirVer - 2013-12-01 14:44:01 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

I use vim v7.4 (not gvim) on console. My OS is Ubuntu 13.10 64-bit. Ultisnips v2.2 (according to ChangeLog).

------------------- SNIP ------------------- $ vim --version VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 12 2013 00:23:19) Modified by

------------------- SNIP ------------------- $ uname -a Linux insula 3.11.0-13-generic #20-Ubuntu SMP Wed Oct 23 07:38:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux ------------------- SNAP -------------------

Launchpad Details: #LPC Andrei - 2013-12-01 17:43:55 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

From where did you install this version of UltiSnips?

Launchpad Details: #LPC SirVer - 2013-12-01 18:20:30 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

I used Vundle to install and update it from github.

Launchpad Details: #LPC Andrei - 2013-12-01 19:05:26 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

Where on github - there are 192 forks :)

Launchpad Details: #LPC SirVer - 2013-12-01 19:17:47 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

https://github.com/SirVer/ultisnips

I've tried to minimize the number of plugins and reduced my .vimrc to the following (see below), but the problem still persists. The exact look of the snippet is the following:

------------------- SNIP ------------------- snippet sse "" b ,{ 'AUTHOR': '${1:Williams}', 'TEXT': '${VISUAL}$2', } endsnippet ------------------- SNAP -------------------

I select a sentence with <vis>, than <tab>sse<tab><c-j>hello world<c-j> and the 3rd line of my snippet looks like that:

'TEXT': ''hello world,

My reduced .vimrc: ------------------- SNIP ------------------- set nocompatible set encoding=UTF-8

" VUNDLE filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc()

Bundle 'gmarik/vundle' Bundle 'SirVer/ultisnips'

filetype plugin indent on " VUNDLE END ------------------- SNAP -------------------

Launchpad Details: #LPC Andrei - 2013-12-01 19:46:25 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

I still cannot reproduce the problem. With the same vimrc everything works nicely for me. Can you try doing a screencapture of your vimsession or something? Maybe it has to do with the sentence you copy in your visual selection.

Launchpad Details: #LPC SirVer - 2013-12-02 06:43:18 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

I suppose you are right. My sentences are in cyrillic script. If they are in latin, everything works pretty fine. You can try this one to reproduce the bug:

------------------- SNIP ------------------- Так в доме кроме кота и ежа стала жить третья живая душа — Желтухин. ------------------- SNAP -------------------

And here is a video record with reproducing the bug: http://www.youtube.com/watch?v=YU5FdfxUTgA Thank you very much for Ultisnips and for being responsive and cooperative.

Launchpad Details: #LPC Andrei - 2013-12-02 09:47:38 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

May be it is a bug related to the variable width of a unicode character in bytes in UTF-8?

Launchpad Details: #LPC Andrei - 2013-12-02 11:12:06 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

Yep, that seems to be the issue. I can reproduce the problem using the cyrillic script and I guess that you are right about the width of unicode characters. Theoretically, UltiSnips should deal fine with that (there is a bunch of code that deals with the details and ugliness of Vims internal encoding stuff), but I only speak latin based languages, so there was not enough testing apparently.

If you have the option, you can try a Vim that supports python3 - there the situation is less difficult and it could maybe work. Otherwise this bug needs careful inspection to get fixed.

Launchpad Details: #LPC SirVer - 2013-12-03 07:21:46 +0100

SirVer avatar Feb 15 '14 11:02 SirVer

This problem also occur if there is non-latin character in your snippet. Using the example above, if I define a snippet like:

snippet sse "" b
{
'AUTHOR': '${1:Williams}',
'TEXT': 'Так в доме$2',
}

when you jump forward to $2, the position will also be wrong position. So it's nothing to do with VISUAL mode but the non-latin words causes ultisnips getting wrong on tabstop. I found this error is very very very strange one:

  • The error only happen if $1 has default text (williams in this case), if $1 has no default text, the position of $2 tabstop will be correct.
  • The error only happen with $2, if replace $2 with $0, the error not happen.
  • The most strange one: the following snippet doesn't have this problem.
snippet sse "" b
,{
'AUTHOR': '${1:Williams}',
'TEXT': 'Так в доме$2',abcdefg
}
endsnippet

with 'a', 'ab' ... 'abcdef', the error occurs, but abcdefg or longer string eliminate this error.

yodalee avatar Sep 09 '14 06:09 yodalee

currently track, both the correct and wrong snippet set _vim.select at same position (snippet_manager.py:392), ntab.start and ntab.end are identical in both cases. So I think the problem may lies in _vim.select?

yodalee avatar Sep 09 '14 09:09 yodalee

Can still reproduce in 324a4f8ffc491b05346c284fcbbb6f77318d6b82.

SirVer avatar Jul 11 '15 16:07 SirVer

I though this might have been fixed with https://github.com/SirVer/ultisnips/commit/9c73ce948abf035b04575dbd6706431b92f6454e, but I can still repro the error there.

SirVer avatar Nov 21 '15 16:11 SirVer

Still exists in 943156d, both in python2 and python3.

SirVer avatar Apr 12 '18 20:04 SirVer

The behavior is still buggy in 3a8b0548b3efd01bff0393f8f32228786149806c, but much less so. I can only reproduce a off-by-one error with the ${VISUAL} example and no error using the example with non-ascii text in the snippet definition.

I was completely unable to trigger any bug by typing Так в доме кроме кота и ежа стала жить третья живая душа — Желтухин. in any placeholder position.

SirVer avatar Dec 13 '19 11:12 SirVer