garbas/vim-snipmate

Snipmate can't find the snippets directory

dgmstuart opened this issue · 12 comments

f1432b6 seems to have broken snipmate for me - possibly due to changes in how snippet_dirs is handled?

Errors (the second two show after hitting ENTER)

Error detected while processing function snipMate#TriggerSnippet[35]..snipMate#GetSnippetsForWordBelowCursor[32]..funcref#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool:
line   12:
E716: Key not present in Dictionary: snippet_dirs
Press ENTER or type command to continue
Error detected while processing function snipMate#TriggerSnippet[35]..snipMate#GetSnippetsForWordBelowCursor[32]..funcref#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..sni
pMate#DefaultPool:
line   12:
=snipMate#ShowAvailableSnips()
Error detected while processing function snipMate#ShowAvailableSnips[3]..snipMate#GetSnippetsForWordBelowCursorForComplete[1]..snipMate#GetSnippetsForWordBelowCursor[32]..funcref
#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool:
line   12:
E716: Key not present in Dictionary: snippet_dirs
Press ENTER or type command to continue
Error detected while processing function snipMate#ShowAvailableSnips[3]..snipMate#GetSnippetsForWordBelowCursorForComplete[1]..snipMate#GetSnippetsForWordBelowCursor[32]..funcref
#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool:
line   12:
E15: Invalid expression: g:snipMate.snippet_dirs

echo g:snipMate gives me this:

{'word': 'def', 'get_snippets': {'faked_function_reference': 'snipMate#GetSnippets'}, 'get_scopes': {'faked_function_reference': 'return split(&ft,"\\.")+[&syntax, "_"]'}, 'no_match_completion_feedkeys_chars': '       ', 'scope_aliases': {'xhtml': 'html', 'scss': 'css', 'ur': 'html,javascript', 'cu': 'c', 'less': 'css', 'php': 'php,html,javascript', 'html': 'javascript', 'objc': 'c', 'cpp': 'c', 'mxml': 'actionscript', 'eruby': 'eruby-rails,html'}}

@dgmstuart Are you sure you're on master? Those errors are saying that the 12th line of the snipMate#DefaultPool function is making reference to g:snipMate.snippet_dirs, which is not the case on master.

@dgmstuart In that commit as well, the only reference to snippet_dirs in the DefaultPool function is the call to the s:snippet_dirs function. That function would've been mentioned in the error message if the error occurred in it. Another thought is that Vim is having trouble finding that function because the use appears to be before the definition of it, but I think it'd give a different error message. Besides, a script-local function existence is only checked when actually being called. That is, a function definition can call functions that don't exist so long as they exist by the time the function being defined is actually called.

So I'm skeptical that that commit is the source of the problem you're experiencing. Could you share your Vim version? Maybe that could lead us somewhere.

I agree that the code doesn't seem to explain the error messages, but how else do we explain that when I check out the previous commit everything works fine and when I check out that commit I get errors?

Here's my vim version info:

:version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 26 2017 15:12:57)
MacOS X (unix) version
Included patches: 1-997
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +cmdline_hist    -ebcdic          -gettext         +listcmds        +mouse_sgr       +persistent_undo +smartindent     +termresponse    +wildignore
+arabic          +cmdline_info    +emacs_tags      -hangul_input    +localmap        -mouse_sysmouse  +postscript      +startuptime     +textobjects     +wildmenu
+autocmd         +comments        +eval            +iconv           -lua             +mouse_urxvt     +printer         +statusline      +timers          +windows
-balloon_eval    +conceal         +ex_extra        +insert_expand   +menu            +mouse_xterm     +profile         -sun_workshop    +title           +writebackup
-browse          +cryptv          +extra_search    +job             +mksession       +multi_byte      +python          +syntax          -toolbar         -X11
++builtin_terms  +cscope          +farsi           +jumplist        +modify_fname    +multi_lang      -python3         +tag_binary      +user_commands   -xfontset
+byte_offset     +cursorbind      +file_in_path    +keymap          +mouse           -mzscheme        +quickfix        +tag_old_static  +vertsplit       -xim
+channel         +cursorshape     +find_in_path    +lambda          -mouseshape      +netbeans_intg   +reltime         -tag_any_white   +virtualedit     -xpm
+cindent         +dialog_con      +float           +langmap         +mouse_dec       +num64           +rightleft       -tcl             +visual          -xsmp
-clientserver    +diff            +folding         +libcall         -mouse_gpm       +packages        +ruby            +termguicolors   +visualextra     -xterm_clipboard
+clipboard       +digraphs        -footer          +linebreak       -mouse_jsbterm   +path_extra      +scrollbind      +terminal        +viminfo         -xterm_save
+cmdline_compl   -dnd             +fork()          +lispindent      +mouse_netterm   +perl            +signs           +terminfo        +vreplace
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -l
ncurses -liconv -framework Cocoa   -mmacosx-version-min=10.11 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-thread-multi-2lev
el/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python   -lruby.2.4.1 -lobjc

The call to s:snippet_dirs in the DefaultPool function is mentioned - it's on the first line of the error block which I posted.

When I tab to complete the snippet, that's the error that I get first, then the rest of the errors I showed above happen line by line on repeated presses of the enter key.

These error messages are quite confusing and I don't have much confidence that adjacent lines are actually related to each other.

I've edited my original issue to show the three different errors more clearly

@dgmstuart Okay so the first line of an error message like this is basically a backtrace:

Error detected while processing function snipMate#TriggerSnippet[35]..snipMate#GetSnippetsForWordBelowCursor[32]..funcref#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool:

This means the error is in the snipMate#DefaultPool function, that was called by line 61 of funcref#Call, which was called by line 4 of snipMate#GetSnippets and so on. So your Vim is finding an error on line 12 of snipMate#DefaultPool. Here is line 12 of that function from master:

for path in s:snippet_dirs()

The errors are:

E716: Key not present in Dictionary: snippet_dirs
E15: Invalid expression: g:snipMate.snippet_dirs

As you can see, line 12 of snipMate#DefaultPool has no dictionary, it has no key, and it has no expression g:snipMate.snippet_dirs. For contrast, here's what an error would look like if s:snippet_dirs didn't exist:

Error detected while processing function snipMate#TriggerSnippet[35]..snipMate#GetSnippetsForWordBelowCursor[31]..funcref#Call[61]..snipMate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool:
line   12:
E117: Unknown function: s:snippet_dirs

And here's an error that occurred in s:snippet_dirs (pay attention to the backtrace and line number):

Error detected while processing function snipMate#TriggerSnippet[35]..snipMate#GetSnippetsForWordBelowCursor[31]..funcref#Call[61]..snip Mate#GetSnippets[4]..funcref#Call[61]..snipMate#DefaultPool[12]..<SNR>108_snippet_dirs:
line    1:
E716: Key not present in Dictionary: snippet_dirs

I'm not sure why it seems to work for you with the previous commit but doesn't with that commit. As far as I can tell, your Vim isn't actually using the code from that commit. I have no idea why that would happen, though. I think our best bet is to start with a minimal vimrc and config so that I can reproduce what you're experiencing on my end and actually work with it instead of speculating.

@ajzafar So the following vimrc is about as minimal as it gets and I still get the same errors on f1432b6, and everything is fine on 2608687

" Vundle config start
set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

Plugin 'garbas/vim-snipmate'
  Plugin 'MarcWeber/vim-addon-mw-utils' " snipmate dependency
  Plugin 'tomtom/tlib_vim'              " snipmate dependency

call vundle#end()            " required
filetype plugin indent on    " required

Same situation with the (even more minimal) pathogen vimrc:

execute pathogen#infect()
syntax on
filetype plugin indent on

Is it possible that it's something to do with my snippets? I think they're pretty vanilla: https://github.com/dgmstuart/dotfiles/tree/master/.vim/snippets

OK I think I found the issue:

My .vim/autoload directory has a number of old files in it:

.vim/autoload
├── snipMate.vim
├── snipMate_python_demo.vim
├── snipmate
│   ├── jumping.vim
│   ├── legacy.vim
│   ├── parse.vim
│   └── util.vim
└── vim_snippets.vim

Files are here: https://github.com/dgmstuart/dotfiles/tree/2b992f0d0fe3f5ab4a1abf24146595749af7d6a1/.vim/autoload

I added these when I was managing plugins with Unbundle (which is very minimal), as a result of #197 (comment), and I guess I never removed them when I moved to using Vundle, which I guess is maybe a bit more clever about how it references files in the plugin's autoload directory.

Removing those files from .vim/autoload fixes the issue.

Thanks for your time @ajzafar.

Glad we could resolve this.