xolox / vim-easytags

Automated tag file generation and syntax highlighting of tags in Vim
http://peterodding.com/code/vim/easytags/
1.01k stars 109 forks source link

index out of range, 142_save_by_filetype, line 5, proposed fix #98

Closed stepds closed 9 years ago

stepds commented 9 years ago

I think you could change something in file easytags.txt to avoid a run-time error. File easytags.txt says about _g:easytagslanguages option [...]

  let g:easytags_languages = {
  \   'language': {
  \     'cmd': g:easytags_cmd,
  \       'args': [],
  \       'fileoutput_opt': '-f',
  \       'stdout_opt': '-f-',
  \       'recurse_flag': '-R'
  \   }
  \}

Each key is a special language definition. The key is a Vim file type in lowercase. The above snippet shows the defaults; you only need to specify options that differ.

And so I did, I only specified options that differ, like so (Windows _vimrc):

  let g:easytags_languages = {
  \   'r': {
  \     'cmd': g:easytags_cmd,
  \       'args': [ '"--options='.$VIM.'\ctags\ctags.cnf" ],
  \       'fileoutput_opt': '-f',
  \       'stdout_opt': '-f-',
  \       'recurse_flag': '-R'
  \   }
  \}

But something was missing because when I ran :UpdateTags easytags output an error message

easytags.vim 3.7: Vim(let):E684: list index out of range: 4 (at function xolox#easytags#update..xolox#easytags#update#with_vim..<SNR>142_save_by_filetype, line 5)

I worked around this error by specifying more options for my custom command. I copied some options from the default call to ctags in function s:prep_cmdfile. So now easytags tags .r files just fine with the changed line in _vimrc:

  \       'args': [ '"--options='.$VIM.'\ctags\ctags.cnf" --fields=+l --sort=no' ],
xolox commented 9 years ago

Hi @stepds and thanks for the feedback.

First I'll try to reply to your original point:

The idea behind the g:easytags_languages option is to add support for languages that are not supported by Exuberant Ctags, so using a custom tag extraction program that will probably have a completely different command line interface but with compatible output. In such cases the vim-easytags plug-in can't tell whether that program would support the required --fields=+l option (probably not though) so it can't add it automatically.

Side bar: This discussion does highlight a weak point (bug?) of vim-easytags: I don't use custom language definitions myself so never noticed, but I guess this feature does not go well together with vim-easytags' dependence on the language: field added by Exuberant Ctags but probably not by other tools.

Second I can't resist a more general reply:

I don't really get your example, because you're creating a definition for a custom tag generation command, but it's just using g:easytags_cmd, and I don't see any non-default options added except for the ctags.cnf file. If all you want to do is make sure your ctags.cnf file is loaded, why not put it somewhere where Exuberant Ctags finds it automatically? And why do that only for R, using a custom language definition?

stepds commented 9 years ago

Hi xolox,

why not put it somewhere where Exuberant Ctags finds it automatically? Because I use vim in a self-contained, portable folder configuration on Windows. That includes an exuberant ctags folder. Exub. ctags can't automatically find its configuration file unless the file is in some fixed location - think of /etc/ctags.cnf in linux, but it's actually Windows. I can't put the configuration file in a fixed location, because it would be outside the self-contained, portable vim folder. So I need to resort to command-line switches to tell ctags where to find its cnf file.

And why do that only for R, using a custom language definition? I do that for three more languages I use, the configuration I sent was a paired down example. I only do it for three languages because those are the only ones I need that ctags can't automaticaly parse. For the ones it knows I don't need to pass a command-line option.

I don't see any non-default options added except for the ctags.cnf file. That's the one I need to make it work, and it's a non-default option.

The idea behind the g:easytags_languages option is to add support for languages that are not supported by Exuberant Ctags... ...or that Exub ctags can support only through command-line options - you may consider. Admittedly, my portable vim on Windows requirement is outside the scope of your design, ATM - but you see that I can make it work regardless by working around the error message I reported. Thanks xolox!

xolox commented 9 years ago

Hi @stepds and thanks for the reply, I now have a better understanding of the reasoning that led to the issue you reported. I think I can help out fairly easily, I'll be back in a moment :-)

xolox commented 9 years ago

I believe the new g:easytags_opts option can resolve your issue and simplify your Vim configuration significantly. Can you try it out?

stepds commented 9 years ago

Some issue, see if this tells you anything _vimrc

let g:easytags_cmd = $VIM.'\ctags\ctags.exe'
let g:easytags_opts = '"--options='.$VIM.'\ctags\ctags.cnf"'

first and second runs (didn't try more)

:messages
Error detected while processing function xolox#easytags#register..xolox#easytags#get_tagsfile..xolox#easytags#filetypes#canonicalize..<SNR>151_discover_supported_filetypes..xolox#easytags#ctags_command:
line 6:
E712: Argument of map() must be a List or Dictionary
E712: Argument of extend() must be a List or Dictionary
kopischke commented 9 years ago

@xolox Just happened on this while browsing my issues stream. I'm currently deep in Vim script quirks and oddities terrirtory in a project of mine, and I had a kind of déjà-vu reading the error reports, so I thought I'd share my observations. Feel free to shoot me down if I'm off base, but here goes:

xolox commented 9 years ago

@stepds: As the documentation says the option expects a list of strings, just like the args entry for languages defined via g:easytags_languages while the example you quoted defines a string:

let g:easytags_opts = '"--options='.$VIM.'\ctags\ctags.cnf"'

If you change the above to this it should work:

let g:easytags_opts = ['--options=$VIM\ctags\ctags.cnf']

As you may have noticed I just published vim-easytags 3.9.1, this new version contains two changes:

  1. Environment variables in the strings contained in g:easytags_opts are now expanded (so you don't have to do that manually anymore, you can see this in my example)
  2. I've tried to clarify the documentation with an example based on this issue.
xolox commented 9 years ago

@kopischke wrote:

OP’s original 'args' value was missing a closing single quote; this kind of things makes Vim barf “out of index” errors when it happens in nested collections. The revised example with extra options closes its quotes correctly, which would explain why it worked.

The error in the example may well be caused by a copy/paste error, reformatting or typing out an example. If that error was in the OPs vimrc it would have caused an error at the definition site, not the error the OP quoted:

easytags.vim 3.7: Vim(let):E684: list index out of range: 4 (at function xolox#easytags#update..xolox#easytags#update#with_vim..<SNR>142_save_by_filetype, line 5)

Given the above, in my opinion this has nothing to do with Vim script quirks and oddities (although I do admit there are _a lot_ of those :-).

stepds commented 9 years ago

Brilliant, with the revised vimrc easytags works smoothly, thanks! The updated example text is much improved, now it speaks to me, and hopefully to others, as to the benefit. OT what's the markdown to quote someone's text, like in your reply above?

xolox commented 9 years ago

@stepds: I'm glad to hear that the revised documentation helps and that you can now easily tell vim-easytags what to do without needing any creative hacks :-). About the Markdown quoting, you do that by starting a paragraph with a > symbol. I'm closing this issue now because your problem seems to be resolved :-). Happy Vimming!