2

I'm trying to add a plugin that will provide additional tags files to look up the documentation of a language: https://github.com/DanielSiepmann/phpstorm-stubs/blob/feature/add-dynamic-tags-file/plugin/php.vim But none of my tries worked out:

let &l:tags += expand('%:p:h:h') . "/tags"
let &tags = expand('%:p:h:h') . "/tags"
set tags += expand('%:p:h:h') . "/tags"

The first solution returns the following error:

Error detected while processing /Users/siepmann/.dotfiles/.vim/bundle/phpstorm-stubs/plugin/php.vim: line 1: E734: Wrong variable type for += Press ENTER or type command to continue

The second one will prevent all other defaults that would be set in addition. So tags=./tags,tags will become tags=~/Projects/typo3/tags where ~/Projects/typo3/ is current working dir.

The thing is that the plugin should ship with the tags file and as the plugin can be installed into multiple locations the include should be dynamic.

So what will be a working solution / approach?

5
  • According to vimdoc.sourceforge.net/htmldoc/eval.html#:let the let &l: version will work like setlocal. That was a try inside ftplugin/php.vim to only adjust tags for php files. & is to handle settings as variables according to the documentation to let expand work while adjusting the setting. What's the issue with absolut path?
    – Daniel
    Sep 19, 2016 at 20:52
  • 2
    Concatenation charachter for strings in vim is ., so you should use .= to add to a string value.
    – dNitro
    Sep 19, 2016 at 21:11
  • Thanks @dNitro, that's one issue. The other is that expand works on working directory not on the file it resists. So how can I provide the path relative to plugin? And why is ._ the right way even if tags is a list of values. In my opinion vimdoc.sourceforge.net/htmldoc/options.html#:set+= should apply.
    – Daniel
    Sep 19, 2016 at 21:18
  • 2
    When using set, don't use spaces, i.e. use set tags+=<path>. Also, if you want to get a path relative to the script file it's run from, try something like let parent_dir = resolve(expand('<sfile>:p:h')) for example, and use that.
    – VanLaser
    Sep 19, 2016 at 23:36
  • Thanks @VanLaser I didn't see the <sfile> in the docs.
    – Daniel
    Sep 20, 2016 at 6:30

1 Answer 1

1

Thanks to @dNitro and @VanLaser the following is the working solution.

In ftplugin/php.vim:

if &l:tags == ""
    " Gather information
    let s:additionalFile=expand('<sfile>:p:h:h')."/tags"
    let s:existingPath=&tags
    let s:newPath=s:existingPath.",".s:additionalFile

    if s:existingPath[-1:] == ""
        let s:newPath=s:additionalFile
    endif

    " Set new path
    let &l:tags=s:newPath
endif

This will first check if tags is set for current buffer. If not it will fetch the path relative to tags file in the current plugin. Next it will concatenate the global tags setting with the new file if global tags contains something. This is due to the fact that let &l:tags+=s:newPath will not work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.