vim-rtags icon indicating copy to clipboard operation
vim-rtags copied to clipboard

automatically re-index file on save

Open theimpostor opened this issue 6 years ago • 12 comments

I find I have to re-index the file after every change, otherwise the jumps don't work. Would be great if the plugin had an option to do this for you.

Thanks for the awesome plugin.

theimpostor avatar Jun 22 '18 16:06 theimpostor

I agree. I'll work on an autocmd to do this.

mckellyln avatar Jun 25 '18 11:06 mckellyln

Does this work ?

autocmd FileWritePost,FileAppendPost * call rtags#ReindexFile()

mckellyln avatar Jun 25 '18 13:06 mckellyln

Shouldn't the code in rdm 'see' the file was changed and reindex on its own ?

mckellyln avatar Jun 25 '18 14:06 mckellyln

That command appears to work. I wonder if instead of setting it for all filetypes maybe it should be restricted to c and cpp.

Also, rtags should be watching files for changes - but there are bugs. See https://github.com/Andersbakken/rtags/issues/1172. Hence I think it'd be nice if the plugin had an option to enable the automatic re-index on save.

theimpostor avatar Jun 25 '18 15:06 theimpostor

ok, perhaps -

autocmd FileWritePost,FileAppendPost *.{c,h,cpp,hpp,ipp} call rtags#ReindexFile()

mckellyln avatar Jun 25 '18 15:06 mckellyln

That looks like it would work! Do we need BufWritePost also?

I thought there was an easy way to use the vim filetype to filter other autocommands. This is what I came up with, seems to work:

autocmd Filetype c,cpp autocmd BufWritePost,FileWritePost,FileAppendPost <buffer> call rtags#ReindexFile()

theimpostor avatar Jun 25 '18 15:06 theimpostor

I can add to the plugin to do this, and I have several other changes I've made to my clone which I find helpful. I haven't seen any updates or PRs accepted to it in a while though.

mckellyln avatar Jun 25 '18 15:06 mckellyln

Cool, if you add it I can switch to your clone locally.

theimpostor avatar Jun 25 '18 15:06 theimpostor

@theimpostor my repo has this switch now -

let g:rtagsAutoReindexOnWrite=1

To enable. My repo is at: https://github.com/mckellyln/vim-rtags but I have not yet updated the docs for my changes.

mckellyln avatar Jul 19 '18 13:07 mckellyln

AFAIK, rdm uses inotify to monitor changes to project files. That's why I'd expect it to reindex files once those are modified. @theimpostor , how big is your project? Is it bigger than the value in

cat /proc/sys/fs/inotify/max_user_watches

?

lyuts avatar Jul 23 '18 00:07 lyuts

I have mine set to 1048576 (I think I increased it manually) @lyuts thx for vim-rtags.

mckellyln avatar Jul 23 '18 12:07 mckellyln

@lyuts I am on osx high sierra, and it's not clear to me what the file watch limit is. I do have a bunch of projects indexed, I will try reducing this number and see if the autoindexing works again. Thanks for the suggestion.

theimpostor avatar Jul 24 '18 15:07 theimpostor