Skip to content

Commit 1bd8bda

Browse files
committed
WIP: setup patterns to use with gf command for autoloading another file
1 parent a92908e commit 1bd8bda

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

autoload/puppet/include.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function! puppet#include#IncludeExpr(fname) abort
2+
" Remove puppet 3.x style leading :: since they mean nothing for the path
3+
let l:fname = substitute(a:fname, '^::', '', '')
4+
5+
" If we can't find a second element, then we're referring to the init.pp
6+
" file
7+
if match(l:fname, '::') < 0
8+
return 'init'
9+
endif
10+
11+
" Remove first element. It'll make finding files easier since the module
12+
" name might not be in the find path.
13+
let l:fname = substitute(l:fname,'^[^:]\+::','','')
14+
15+
" Replace all subsequent :: in order to get a real file path
16+
let l:fname = substitute(l:fname,'::','/','g')
17+
18+
return l:fname
19+
endfunction

ftplugin/puppet.vim

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ setlocal commentstring=#\ %s
2121
setlocal formatoptions-=t formatoptions+=croql
2222
setlocal formatexpr=puppet#format#Format()
2323

24+
setlocal suffixesadd=.pp
25+
setlocal include=\\v^\\s*(include\|contain\|class\\s+\\\{\|Class\\s+\\\[)\\s+[\"\']?\\zs(\\f\|::)+
26+
setlocal includeexpr=puppet#include#IncludeExpr(v:fname)
27+
2428
let b:undo_ftplugin = "
2529
\ setlocal tabstop< tabstop< softtabstop< shiftwidth< expandtab<
2630
\| setlocal keywordprg< iskeyword< comments< commentstring<
2731
\| setlocal formatoptions< formatexpr<
32+
\| setlocal suffixesadd< include< includeexpr<
2833
\"

0 commit comments

Comments
 (0)