Modifying autocomplete to handle values which haven't been specified

Bug #1073816 reported by Kartik Shenoy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
UltiSnips
Fix Committed
Medium
Unassigned

Bug Description

This is the snippet that I have

  snippet '^#?inc' "#include <>" !r
  #include <$1`!p snip.rv = complete(t[1], ['cassert', 'cstdio', 'cstdlib', 'cstring', 'fstream', 'iostream', 'sstream'])`>
  endsnippet

and the global complete function

  global !p
  def complete(t, opts):
    if t:
      opts = [ m[len(t):] for m in opts if m.startswith(t) ]
    if len(opts) == 1:
      return opts[0]
    elif len(opts) > 1:
      return "(" + "|".join(opts) + ")"
    else:
      return ""
  endglobal

which I'm trying to modify to return an empty string when there's no match.

But the problem is when I try to input something which hasn't been specified ( for eg. 'vector' ), the cursor jumps from the tabstop to the start of the line.

Revision history for this message
SirVer (sirver) wrote : Re: [Bug 1073816] [NEW] Modifying autocomplete to handle values which haven't been specified

Cannot reproduce, seems to work good for me:

inc<tab>v -> #include <v>
inc<tab>f -> #include <fstream>

cursor is not jumping for me. Please provide Ultisnips version, vim
version, OS and a minimal .vim an vimrc to reproduce the problem.

  status incomplete

Changed in ultisnips:
status: New → Incomplete
Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

I'm using the version of Ultisnips available on github currently. The version of Vim is 7.3 and the OS is Ubuntu 12.04.

I tried using a completely fresh vim setup ( no .vimrc, only Ultisnips present in the .vim folder ) to rule out interference from other plugins or even possibly from settings present in .vimrc and captured some images to show what's happening ( http://imgur.com/imJSG,eJs57 )

Revision history for this message
SirVer (sirver) wrote : Re: [Bug 1073816] Re: Modifying autocomplete to handle values which haven't been specified

I see what's happening, but I cannot reproduce it here, also with Vim
7.3. Could you upload the vim config/snippet definition you used for
your minimal reproduction step?

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

I've modified only the inc snippet in the default c.snippets provided.
The contents of my c.snippets file are:-

###########################################################################
# TextMate Snippets #
###########################################################################
#===========================================================================
# Global functions
#
global !p
def complete(t, opts):
  if t:
    opts = [ m[len(t):] for m in opts if m.startswith(t) ]
  if len(opts) == 1:
    return opts[0]
  elif len(opts) > 1:
    return "(" + "|".join(opts) + ")"
  else:
    return ""
endglobal

snippet '^#?in?c?l?u?d?e?' "#include <>" r
#include <$1`!p snip.rv = complete(t[1], ['stdio.h', 'stdlib.h'])`>
endsnippet

snippet def "#ifndef ... #define ... #endif"
#ifndef ${1/([A-Za-z0-9_]+).*/$1/}
#define ${1:SYMBOL} ${2:value}
#endif
endsnippet

snippet #if "#if #endif" !b
#if ${1:0}
${VISUAL:code}$0
#endif
endsnippet

#snippet inc "#include local header (inc)"
##include "${1:`!p snip.rv = snip.basename + '.h'`}"
#endsnippet

snippet Inc "#include <> (Inc)"
#include <${1:.h}>
endsnippet

snippet mark "#pragma mark (mark)"
#if 0
${1:#pragma mark -
}#pragma mark $2
#endif

$0
endsnippet

snippet main "main() (main)"
int main(int argc, char const *argv[])
{
 ${0:/* code */}
 return 0;
}
endsnippet

snippet for "for int loop (fori)"
for (${4:size_t} ${2:i} = 0; $2 < ${1:count}; ${3:++$2})
{
 ${0:/* code */}
}
endsnippet

snippet enum "Enumeration"
enum ${1:name} { $0 };
endsnippet

snippet once "Include header once only guard"
#ifndef ${1:`!p
if not snip.c:
 import random, string
 name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper()
 rand = ''.join(random.sample(string.ascii_letters+string.digits, 8))
 snip.rv = ('%s_%s' % (name,rand)).upper()
else:
    snip.rv = snip.c`}
#define $1

${0}

#endif /* end of include guard: $1 */

endsnippet

snippet td "Typedef"
typedef ${1:int} ${2:MyCustomType};
endsnippet

snippet do "do...while loop (do)"
do {
 ${0:/* code */}
} while(${1:/* condition */});
endsnippet

snippet fprintf "fprintf ..."
fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet

snippet if "if .. (if)"
if (${1:/* condition */})
{
 ${0:/* code */}
}
endsnippet

snippet ife "if .. else (ife)"
if (${1:/* condition */})
{
        ${2:/* code */}
}
else
{
        ${3:/* else */}
}
endsnippet

snippet printf "printf .. (printf)"
printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet

snippet st "struct"
struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`}
{
 ${0:/* data */}
};
endsnippet

# vim:ft=snippets:

Revision history for this message
SirVer (sirver) wrote :

Still cannot reproduce. Please attach the complete Vim config to this bug report.

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

Hi, I installed vim on a fresh install of Ubuntu VM and then just copied the contents of the download of Ultisnips v2.2 available here on launchpad. So, now I don't have any .vimrc, .gvimrc or any other rc file. The .vim folder contains just the contents of the Ultisnips plugin and my c.snippets file has the new inc snippet along with the global complete function.

However, I'm still facing this issue. I'm sorry for not being able to provide any more details. If there's anything in particular you'd like me to do, please let me know.

A couple of other things, when I'm using the complete function and only one object is matched, pressing Tab doesn't complete it but inserts <Tab> itself.

Also, whenever I create a regular expression snippet, I'm not able to see it in the list of snippets available on pressing <Ctrl+Tab> in insert mode. Is this intentional?

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

>> A couple of other things, when I'm using the complete function and only one object is matched, pressing Tab doesn't
>> complete it but inserts <Tab> itself.

Please ignore this. It works as mentioned.

Revision history for this message
SirVer (sirver) wrote :

still having trouble reproducing this. Could you try a current development snapshot from here:
http://bazaar.launchpad.net/~sirver/ultisnips/github_mirror/tarball/528

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

I'm sorry, but this doesn't help either. I'm running this on an Ubuntu 12.04 machine, Vim 7.3 and Python 2.7.3.
If you wish to try, you can insert a load of echom/print statements and I can give you the resulting output dump.

Revision history for this message
SirVer (sirver) wrote :

Okay, please attach the minimal config as a zip archive. I will try to reproduce this on a virtual machine on the weekend then.

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

Please find attached the requested config. The .vim folder contains only the contents of the Ultisnips addon and only c.snippets file has been modified.

Revision history for this message
SirVer (sirver) wrote :

Thanks!! I did not find the time to look into this on the weekend, but will do so eventually.

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

Hello, I think I was able to narrow the problem area. It seems, that the cursor jumps position if a #include statement is written before any comments. If there is a comment at the top then any #includes that follow it will behave as expected. I don't know if this is the case all the time but I hope this helps.

Revision history for this message
SirVer (sirver) wrote :

Still not able to reproduce. Haven't tried on Linux yet though.

I used the following file for testing:

---- snip ----
#include <stdio.h>
inc<tab>
---- snap ----

Does this show the problem for you?

Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

Hello SirVer,

---- snip ----
#include <stdio.h>
inc<tab>
---- snap ----

works fine for me. But when I do

---- snip ----
inc<tab>
---- snap ----

i.e. in an empty file, the cursor jumps back.

Revision history for this message
SirVer (sirver) wrote :

I can confirm the bug now, i.e. I was able to reproduce it. I'll start investigating when I have some time on my hands. Thanks for your persistence in helping triaging this problem.

Changed in ultisnips:
status: Incomplete → Confirmed
importance: Undecided → Medium
Revision history for this message
Kartik Shenoy (kartikshenoy) wrote :

Haha, thanks a lot for your patience. I was beginning to seriously doubt my vim-fu :)

Revision history for this message
SirVer (sirver) wrote :

I just pushed a fix for this to github.

Changed in ultisnips:
status: Confirmed → Fix Committed
Revision history for this message
SirVer (sirver) wrote :

I forgot - this will be mirrored to trunk in ~4 hours.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.