garbas / vim-snipmate

snipMate.vim aims to be a concise vim script that implements some of TextMate's snippets features in Vim.
www.vim.org/scripts/script.php?script_id=2540
2.01k stars 181 forks source link

Pressing tab on a line containing a } causes E219 #156

Closed highlyunavailable closed 7 years ago

highlyunavailable commented 10 years ago

I'm trying to use SnipMate on Windows, and I get an E219 error, "missing {", when I press Tab on a line in one of my javascript files on a line containing } (but not {) I get an error about a missing {. For some reason the failing code doesn't trigger on Linux, but if I isolate the test, it still gives the same error. The failing function is https://github.com/garbas/vim-snipmate/blob/master/autoload/snipMate.vim#L452-L467

I isolated it down to the function globpath(a:path, a:expr). You can reproduce this in Windows or Linux on the latest version of VIM by trying the following command: :echo globpath(&rtp, "\}))*.snippet"). The })) is what is actually on the line when tab is pressed - it's the end of a hash table inside 2 functions, which is fairly common in Javascript. The full text is:

pipe(browserify({
    insertGlobals: false,
    shim: {
      bootstrap: {
        path: 'lib/bootstrap/js/bootstrap.js',
        exports: null,
        depends: {jquery: 'jQuery'}
      }
    },
    transform: ['reactify'],
    extensions: ['.jsx'],
    debug: true
  }))

It feels almost like an issue with the globpath function rather than SnipMate itself, but if SnipMate wasn't trying to check for filenames with silly characters in them, then this would not happen. In the interim, I've forked the repo and added a substitute(a:trigger, "[{}]", "", "") to strip out any curly braces during filename expansion, but this doesn't seem like a good solution that I'd like to submit a pull request for.

ajzafar commented 10 years ago

Hmm I'm unable to reproduce this. And you're right, this is/was a bug in globpath(). On certain systems, if Vim sees a curly brace in a glob() or globpath() command, it will attempt to have the shell expand the glob, and there was no way to prevent this. My patch to allow escaping of braces (and a couple other characters) was accepted as Vim 7.3.1295.

So what SnipMate does is call globpath() if on a new enough Vim, otherwise we use a wrapper around glob(). When we call globpath() we make sure to escape any problematic characters, which is in fact that line you've modified. That :echo command you offered isn't quite what SnipMate does, because of the way backslashes work in double quoted strings in VimL. The command :echo globpath(&rtp, '\}))*.snippet') is more accurate, and this doesn't give me any errors.

Two things I can see as possible causes for the problem:

highlyunavailable commented 10 years ago

The actual error when pressing Tab doesn't repro on Linux. I think you actually just told me what the real problem was - the single quote version does not reproduce on Linux. It does fail on Windows though. I'm guessing it's a resolved bug, because my Linux version is VIM 7.4.52.

vim --version on Windows, though (file version 7.4.280):

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 10 2013 14:33:40)
MS-Windows 32-bit console version

That sure looks old. However, I swapped it around to use the old s:Glob function instead and I get the exact same error, so the problem is present even if the old function is used. I guess I'll try compiling a new version of Vim for Windows and we'll see if that fixes it. I got mine from http://www.vim.org/download.php#pc but if it's out of date and is fixed in a newer version, then there's not much that can/should be done from the snipmate side to fix it I guess.

highlyunavailable commented 10 years ago

It still repros on windows with the latest VIM from the Cream project: http://sourceforge.net/projects/cream/files/Vim/7.4.256

It also repros on 7.4.52 for Windows, again from the Cream people's compilation.

:echo globpath(&rtp, '\}))*.snippet') still causes a ton of "missing {" errors on two newer versions, so I'm going to say this is still an issue.

crzidea commented 10 years ago

+1 for this. It also occurs when typing <tab> after {.

ajzafar commented 10 years ago

I forgot to link this issue in the commit message, but 9db1826 seems to work for me on Vim from vim.org and on Cream, versions 7.4 and 7.4.256 respectively. Can @highlyunavailable or @crzidea confirm? This would still indicate that there's a bug somewhere in Vim on Windows as I indicated earlier. I don't really have the Windows resources to fix it though.

highlyunavailable commented 10 years ago

This does not resolve the issue at all, unfortunately.

crzidea commented 10 years ago

@ajzafar It still hurt. The following error message may help:

function snipMate#TriggerSnippet..snipMate#GetSnippetsForWordBelowCursor..funcref#Call..snipMate#Ge
tSnippets..funcref#Call..snipMate#DefaultPool..snipMate#GetSnippetFiles..<SNR>73_Glob
ajzafar commented 10 years ago

Well, I can't reproduce unfortunately, so I guess I have to let this sit

@crzidea that's only a small fragment of the error

ajzafar commented 7 years ago

Closing due to inactivity.