Skip to content

Commit 9080ed6

Browse files
Add ctags tool layer
1 parent 02d4c74 commit 9080ed6

File tree

5 files changed

+155
-9
lines changed

5 files changed

+155
-9
lines changed

core/autoload/spacevim/autocmd/gutentags.vim

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@ if !isdirectory(s:vim_tags)
1010
silent! call mkdir(s:vim_tags, 'p')
1111
endif
1212

13-
let g:spacevim#vim#ctags#cache_dir = s:vim_tags
14-
1513
function! spacevim#autocmd#gutentags#Init()
1614
let g:gutentags_ctags_tagfile = '.tags'
1715
" set default tags file name `tags` to `.tags`
1816
set tags=./.tags;,.tags
1917

20-
let g:gutentags_ctags_extra_args = ['--fields=+niazS', '--extra=+q']
21-
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
22-
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
23-
2418
let g:gutentags_modules = s:modules
2519

2620
" Specifies a directory in which to create all the tags files

layers/+tools/ctags/config.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,17 @@
1+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
12

3+
if spacevim#vim#plug#LocateDependency('ctags')[0] ==# 'none'
4+
call spacevim#util#warn('ctags layer failure, try ":call dein#get('.
5+
\ '"libyaml").hook_post_update()" to build ctags+libyaml as plugin,'.
6+
\ ' or set $PATH to existing build, or install system-wide with '.
7+
\ 'version >= '.join(g:spacevim#vim#plug#native_dependency[
8+
\ 'ctags'].v_req, '.').'.')
9+
endif
10+
11+
" vim-gutentags {
12+
let g:gutentags_ctags_extra_args = get(g:, 'gutentags_ctags_extra_args', [])
13+
let g:gutentags_ctags_extra_args += ['--fields=+niazS', '--extras=+q',
14+
\ '--excmd=number', '--tag-relative=yes']
15+
let g:gutentags_ctags_extra_args += ['--c++-kinds=+px']
16+
let g:gutentags_ctags_extra_args += ['--c-kinds=+px']
17+
" }
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
" Need to add libyaml/install/lib to LD_LIBRARY_PATH for ctags runtime
2+
" but dein doesn't manage plugpath once built, so look at state
3+
" For spacevim#vim#plug#LocateDependency in packages.vim and cache.vim
4+
let f = g:spacevim.state_base.'libyaml_state'
5+
if filereadable(f)
6+
let p = readfile(f)
7+
if len(p) > 0
8+
if match($LD_LIBRARY_PATH, '\V'.p[0]) == -1
9+
let $LD_LIBRARY_PATH .= (empty($LD_LIBRARY_PATH) ? '' :
10+
\ spacevim#util#PathEnvSep()).p[0]
11+
endif
12+
endif
13+
endif
14+
15+
function! BuildCtags(native) abort
16+
if executable('rst2man') != 1
17+
call spacevim#util#info('Unable to build ctags man pages unless '.
18+
\ 'rst2man in python3-docutils is installed.')
19+
endif
20+
21+
if a:native.posix_compiler
22+
execute 'tcd' a:native.plugpath
23+
let autoconf_log = a:native.temppath.'/ctags_autoconf.log'
24+
call system('./autogen.sh > '.autoconf_log)
25+
call rename(autoconf_log, a:native.plugpath.'/autoconf.log')
26+
27+
execute 'tcd build'
28+
let configure_log = a:native.temppath.'/ctags_configure.log'
29+
call system(a:native.plugpath.'/configure --enable-yaml --prefix='.
30+
\ a:native.plugpath.'/install > '.configure_log)
31+
call rename(configure_log, a:native.plugpath.'/configure.log')
32+
call execute('AsyncRun -cwd='.a:native.plugpath.'/build '.
33+
\ '-mode=term -pos=tab -program=make -post='.
34+
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''ctags'') @ '.
35+
\ 'install'.a:native.jobs_flag)
36+
endif
37+
endfunction
38+
39+
function! PostBuildCtags(native) abort
40+
call delete('autom4te.cache', 'rf')
41+
call delete('gnulib', 'rf')
42+
call delete('man', 'rf')
43+
call delete('aclocal.m4')
44+
call delete('config.guess')
45+
call delete('config.h.in')
46+
call delete('config.h.in~')
47+
call delete('config.sub')
48+
call delete('configure')
49+
call delete('depcomp')
50+
call delete('install-sh')
51+
call delete('last-aclocal.m4')
52+
call delete('Makefile.in')
53+
call delete('missing')
54+
endfunction
55+
56+
function! BuildYaml(native) abort
57+
if executable('autoconf') != 1
58+
call spacevim#util#info('Unable to build libyaml, requires'.
59+
\ ' autoconf. After rectifying try `:call '.
60+
\ 'dein#get(''libyaml'').hook_post_update()`')
61+
else
62+
if a:native.posix_compiler
63+
execute 'tcd' a:native.plugpath
64+
let autoconf_log = a:native.temppath.'/libyaml_autoconf.log'
65+
call system('./bootstrap > '.autoconf_log)
66+
call rename(autoconf_log, a:native.plugpath.'/autoconf.log')
67+
68+
execute 'tcd build'
69+
let configure_log = a:native.temppath.'/libyaml_configure.log'
70+
call system(a:native.plugpath.'/configure --prefix='.
71+
\ a:native.plugpath.'/install > '.configure_log)
72+
call rename(configure_log, a:native.plugpath.'/configure.log')
73+
call execute('AsyncRun -cwd='.a:native.plugpath.'/build '.
74+
\ '-mode=term -pos=tab -program=make -post='.
75+
\ 'call\ spacevim\#vim\#plug\#PostBuild(code,\ ''libyaml'') @ '.
76+
\ 'install'.a:native.jobs_flag)
77+
endif
78+
endif
79+
endfunction
80+
81+
function! PostBuildYaml(native) abort
82+
if a:native.posix_compiler
83+
" And PKG_CONFIG_PATH so that ctags configure can find libyaml
84+
" And LD_LIBRARY_PATH so that library can be found at runtime
85+
let ps = spacevim#util#PathSep()
86+
let eps = spacevim#util#PathEnvSep()
87+
let l = a:native.plugpath.ps.'install'.ps.'lib'
88+
let $PKG_CONFIG_PATH .= (empty($PKG_CONFIG_PATH) ? '' : eps).l.'/pkgconfig'
89+
let $LD_LIBRARY_PATH .= (empty($LD_LIBRARY_PATH) ? '' : eps).l
90+
" Put into a statefile so that it can be loaded before version check
91+
let f = g:spacevim.state_base.'libyaml_state'
92+
call writefile([l], f, 'S')
93+
endif
94+
call delete('autom4te.cache', 'rf')
95+
call delete('config', 'rf')
96+
call delete('include', 'rf')
97+
call delete('src', 'rf')
98+
call delete('tests', 'rf')
99+
call delete('aclocal.m4')
100+
call delete('configure')
101+
call delete('Makefile.in')
102+
" Can't rely on dein to wait for libyaml to build to then build ctags
103+
execute 'tcd' a:native.cwd
104+
call spacevim#vim#plug#Build('ctags')
105+
endfunction
106+
107+
let g:spacevim#vim#plug#native_dependency = get(g:,
108+
\ 'spacevim#vim#plug#native_dependency', {})
109+
" Unfortunately plugin built ctags doesn't include YYYYMMDD versioning
110+
"\ vregex: '\V\%(p\)\@<=\(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\{4}\)'.
111+
" \ '\(\[0-9]\{2}\)\(\[0-9]\{2}\)',
112+
"\ v_req: [5, 9, 2022, 8, 7],
113+
let g:spacevim#vim#plug#native_dependency['ctags'] = {
114+
\ 'bin': 'ctags',
115+
\ 'repo': 'universal-ctags/ctags',
116+
\ 'vregex': '\V\^Universal Ctags \(\[0-9]\+\).\(\[0-9]\+\).\(\[0-9]\+\)(',
117+
\ 'v_req': [5, 9, 0],
118+
\ 'feature_req': ['--list-features', '\V\nyaml'],
119+
\ 'Build': function('BuildCtags'),
120+
\ 'PostBuild': function('PostBuildCtags'),
121+
\ }
122+
let g:spacevim#vim#plug#native_dependency['libyaml'] = {
123+
\ 'repo': 'yaml/libyaml',
124+
\ 'Build': function('BuildYaml'),
125+
\ 'PostBuild': function('PostBuildYaml'),
126+
\ }

layers/+tools/ctags/packages.vim

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
1-
MP 'ludovicchabant/vim-gutentags', { 'on_ft': ['c', 'cpp'],
1+
MP 'ludovicchabant/vim-gutentags', { 'on_ft': ['c', 'cpp', 'cs'],
22
\ 'hook_source': function('spacevim#autocmd#gutentags#Init') }
3+
4+
execute 'source '.fnamemodify(expand('<sfile>'), ':h').'/native-dependency.vim'
5+
6+
if spacevim#vim#plug#LocateDependency('ctags')[0] ==# 'none'
7+
" Note: 'depends' loading order not guaranteed for non-lazy plugins
8+
MP 'universal-ctags/ctags', { 'merged': v:false, 'rtp': '',
9+
\ 'depends': 'yaml/libyaml', 'lazy': v:true }
10+
MP 'yaml/libyaml', { 'merged': v:false, 'rtp': '',
11+
\ 'hook_post_update': function('spacevim#vim#plug#Build', ['libyaml']) }
12+
endif

layers/LAYERS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Layer Manifest
22
==============
33

4-
Last updated: 2022-09-29 12:39:45
4+
Last updated: 2022-09-29 16:50:50
55

66
Default layers: `fzf`, `better-defaults` and `which-key`.
77

@@ -47,7 +47,7 @@ Topic | Layer | Plugins
4747
+themes | [airline](https://github.com/liuchengxu/space-vim/tree/master/layers/+themes/airline) | <ul><li>[vim-airline/vim-airline](https://github.com/vim-airline/vim-airline)</li><li>[vim-airline/vim-airline-themes](https://github.com/vim-airline/vim-airline-themes)</li></ul>
4848
+themes | [lightline](https://github.com/liuchengxu/space-vim/tree/master/layers/+themes/lightline) | <ul><li>[itchyny/lightline.vim](https://github.com/itchyny/lightline.vim)</li></ul>
4949
+tools | [cscope](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/cscope) | <ul><li>[romainl/vim-qf](https://github.com/romainl/vim-qf)</li></ul>
50-
+tools | [ctags](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ctags) | <ul><li>[ludovicchabant/vim-gutentags](https://github.com/ludovicchabant/vim-gutentags)</li></ul>
50+
+tools | [ctags](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/ctags) | <ul><li>[ludovicchabant/vim-gutentags](https://github.com/ludovicchabant/vim-gutentags)</li><li>[universal-ctags/ctags](https://github.com/universal-ctags/ctags)</li><li>[yaml/libyaml](https://github.com/yaml/libyaml)</li></ul>
5151
+tools | [docker](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/docker) | <ul><li>[ekalinin/Dockerfile.vim](https://github.com/ekalinin/Dockerfile.vim)</li></ul>
5252
+tools | [file-manager](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/file-manager) | <ul><li>[Xuyuanp/nerdtree-git-plugin](https://github.com/Xuyuanp/nerdtree-git-plugin)</li><li>[danro/rename.vim](https://github.com/danro/rename.vim)</li><li>[liuchengxu/nerdtree-dash](https://github.com/liuchengxu/nerdtree-dash)</li><li>[ryanoasis/vim-devicons](https://github.com/ryanoasis/vim-devicons)</li><li>[scrooloose/nerdtree](https://github.com/scrooloose/nerdtree)</li><li>[tiagofumo/vim-nerdtree-syntax-highlight](https://github.com/tiagofumo/vim-nerdtree-syntax-highlight)</li></ul>
5353
+tools | [fzf](https://github.com/liuchengxu/space-vim/tree/master/layers/+tools/fzf) | <ul><li>[Yggdroot/LeaderF](https://github.com/Yggdroot/LeaderF)</li><li>[junegunn/fzf](https://github.com/junegunn/fzf)</li><li>[junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)</li><li>[liuchengxu/vim-clap](https://github.com/liuchengxu/vim-clap)</li><li>[vn-ki/coc-clap](https://github.com/vn-ki/coc-clap)</li></ul>

0 commit comments

Comments
 (0)