xaizek / vim-inccomplete (License: Vim) (since 2018-12-07)
Vim plugin for #include directive completion in C family of languages.
Commit 0cf941648e2c685ea10a4f7f9fed958905fb72f6

Add g:inccomplete_localsources option
Specifies what appears in "" completion.
Author: xaizek
Author date (UTC): 2018-04-03 20:31
Committer name: xaizek
Committer date (UTC): 2018-04-03 20:31
Parent(s): 81cbb214250803ee9b9995d1e8a445a2cbc3a79c
Signing key: 99DC5E4DB05F6BE2
Tree: 486c73b85d16f4693c54fd657c698175509c5e54
File Lines added Lines deleted
doc/inccomplete.txt 15 3
plugin/inccomplete.vim 39 16
File doc/inccomplete.txt changed (mode: 100644) (index 0e78f6c..db995c3)
1 *inccomplete.txt* For Vim version 7.3. Last change: 2016 Nov 10
1 *inccomplete.txt* For Vim version 7.3. Last change: 2018 Apr 3
2 2
3 3
4 4 inccomplete plugin documentation by xaizek inccomplete plugin documentation by xaizek
 
... ... It can complete both "" and <> forms of #include.
38 38
39 39 "" Completion~ "" Completion~
40 40
41 For "" it gets all header files in the current directory or any relative
42 to it directory.
41 By default gets all header files in the current directory or any directory
42 relative to it. Can be configured with |b:inccomplete_root| and
43 |g:inccomplete_localsources|.
43 44
44 45 <> Completion~ <> Completion~
45 46
 
... ... root for local includes *inccomplete-root*
135 136 When this option if set for current buffer, the plugin uses it as base When this option if set for current buffer, the plugin uses it as base
136 137 directory for local completion. directory for local completion.
137 138
139 list of sources for "" completion *inccomplete-localsources*
140 *g:inccomplete_localsources*
141 type: list
142 default: [ 'relative-paths' ]
143
144 Specifies what appears in "" completion. List can include the following
145 items:
146 - 'relative-paths' to complete paths relative to location of current buffer
147 - 'clang-buffer' to complete paths from '-I' keys in b:clang_user_options
148 - 'clang-global' to complete paths from '-I' keys in g:clang_user_options
149
138 150 ============================================================================== ==============================================================================
139 151 3. ToDo *inccomplete-todo* 3. ToDo *inccomplete-todo*
140 152
File plugin/inccomplete.vim changed (mode: 100644) (index 965d0aa..5364d32)
1 1 " Name: inccomplete " Name: inccomplete
2 2 " Author: xaizek <xaizek@posteo.net> " Author: xaizek <xaizek@posteo.net>
3 " Version: 1.7.47
3 " Version: 1.8.47
4 4 " License: Same terms as Vim itself (see :help license) " License: Same terms as Vim itself (see :help license)
5 5 " "
6 6 " See :help inccomplete for documentation. " See :help inccomplete for documentation.
 
... ... if !exists('g:inccomplete_appendslash')
36 36 let g:inccomplete_appendslash = 0 let g:inccomplete_appendslash = 0
37 37 endif endif
38 38
39 if !exists('g:inccomplete_localsources')
40 let g:inccomplete_localsources = [ 'relative-paths' ]
41 endif
42
39 43 " initialize inccomplete after all other plugins are loaded " initialize inccomplete after all other plugins are loaded
40 44 augroup inccompleteDeferredInit augroup inccompleteDeferredInit
41 45 autocmd! autocmd!
 
... ... function! s:ICFilterIncLst(user, inclst, base)
272 276
273 277 " handle multicomponent paths (e.g. "a/...", <boost/...>) " handle multicomponent paths (e.g. "a/...", <boost/...>)
274 278 if l:pos >= 0 if l:pos >= 0
275 let l:lst = s:ICFilter(a:user, l:inclst, a:base, s:ICGetDir())
276 if exists('b:inccomplete_root')
277 let l:lst += s:ICFilter(a:user, l:inclst, a:base,
278 \ b:inccomplete_root)
279 endif
279 let l:lst = []
280 for l:dir in s:ICGetUserSources()
281 let l:lst += s:ICFilter(a:user, l:inclst, a:base, l:dir)
282 endfor
280 283 let l:inclst = l:lst let l:inclst = l:lst
281 284 endif endif
282 285
 
... ... endfunction
338 341 " everywhere in path except '.' " everywhere in path except '.'
339 342 function! s:ICGetList(user, base) function! s:ICGetList(user, base)
340 343 if a:user if a:user
341 let l:dir = s:ICGetDir()
342 let l:dirs = [l:dir]
343 if exists('b:inccomplete_root')
344 let l:dirs = [b:inccomplete_root] + l:dirs
345 endif
346 let l:dirs += s:ICGetSubDirs(l:dirs, a:base)
344 let l:dirs = s:ICGetUserSources()
345 let l:dirs = s:ICAddNoDupPaths(l:dirs, s:ICGetSubDirs(l:dirs, a:base))
347 346 return s:ICFindIncludes(1, l:dirs) return s:ICFindIncludes(1, l:dirs)
348 347 endif endif
349 348
350 349 " prepare list of directories " prepare list of directories
351 let l:pathlst = s:ICAddNoDupPaths(split(&path, ','), s:ICGetClangIncludes())
350 let l:pathlst = s:ICAddNoDupPaths(split(&path, ','),
351 \ s:ICGetClangIncludes(2))
352 352 let l:pathlst = s:ICAddNoDupPaths(l:pathlst, let l:pathlst = s:ICAddNoDupPaths(l:pathlst,
353 353 \ s:ICGetSubDirs(l:pathlst, a:base)) \ s:ICGetSubDirs(l:pathlst, a:base))
354 354 call reverse(sort(l:pathlst)) call reverse(sort(l:pathlst))
 
... ... function! s:ICGetList(user, base)
370 370 return l:result return l:result
371 371 endfunction endfunction
372 372
373 " returns list of paths to directories which should be searched for
374 " ""-completion
375 function! s:ICGetUserSources()
376 let l:dirs = []
377 if index(g:inccomplete_localsources, 'relative-paths') >= 0
378 let l:dirs += [s:ICGetDir()]
379 endif
380 if index(g:inccomplete_localsources, 'clang-buffer') >= 0
381 let l:dirs = s:ICAddNoDupPaths(l:dirs, s:ICGetClangIncludes(1))
382 endif
383 if index(g:inccomplete_localsources, 'clang-global') >= 0
384 let l:dirs = s:ICAddNoDupPaths(l:dirs, s:ICGetClangIncludes(0))
385 endif
386 if exists('b:inccomplete_root')
387 let l:dirs = s:ICAddNoDupPaths(l:dirs, [b:inccomplete_root])
388 endif
389 return l:dirs
390 endfunction
391
373 392 " gets directory of the current buffer " gets directory of the current buffer
374 393 function! s:ICGetDir() function! s:ICGetDir()
375 394 let l:curbuf = s:ICGetBufferName() let l:curbuf = s:ICGetBufferName()
 
... ... endfunction
468 487
469 488 " retrieves include directories from b:clang_user_options and " retrieves include directories from b:clang_user_options and
470 489 " g:clang_user_options " g:clang_user_options
471 function! s:ICGetClangIncludes()
490 " possible values of which:
491 " - 0 -- only g:clang_user_options
492 " - 1 -- only b:clang_user_options
493 " - 2 -- both options
494 function! s:ICGetClangIncludes(which)
472 495 let l:opts = '' let l:opts = ''
473 if exists('b:clang_user_options')
496 if a:which != 0 && exists('b:clang_user_options')
474 497 let l:opts .= b:clang_user_options.' ' let l:opts .= b:clang_user_options.' '
475 498 endif endif
476 if exists('g:clang_user_options')
499 if a:which != 1 && exists('g:clang_user_options')
477 500 let l:opts .= g:clang_user_options.' ' let l:opts .= g:clang_user_options.' '
478 501 endif endif
479 502 if empty(l:opts) if empty(l:opts)
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/vim-inccomplete

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/vim-inccomplete

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master