Skip to content

Commit 7f6b029

Browse files
Help projectionist find .projections.json in new directories
I have an auto-mkdir thing for writing files in directories that don't exist, and projection templates are not applied to files in non-existent directories (and actually, vim-projectionist just fails to find .projections.json in this case). They are if I `mkdir` first though. Example: **Projection** ``` { "foo/*.js": { "template": [ "blah" ] } } ``` If I do `vim foo/bar.js` the template is used; if I do `mkdir foo/bar/ && vim foo/bar/baz.js` the template is used. But if I do `vim foo/bar/baz.js` by itself I don't get the template. Here's why it matters: angular and react and some other frameworks advocate a directory-per-component structure, so any new component is in a new directory. Your structure ends up looking like: ``` components/ foo/ foo.js foo.html foo.test.js ``` so every time you create a new component you're creating a new directory. Which means I either _never_ get the benefit of auto-mkdir (and have to type `mkdir` every time . . . I know, I know, first world problems) or I _never_ get the benefit of a projection template. This turned out to be because `expand('<afile>:p')` doesn't result in an absolute path in non-existent directories. This change fixes it by detecting non-absolute paths and prefixing them with cwd. Thoughts?
1 parent ec6ad51 commit 7f6b029

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

plugin/projectionist.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ function! s:has(root, file) abort
2525
endfunction
2626

2727
function! ProjectionistDetect(path) abort
28+
let path = a:path
29+
if path !~ '^/'
30+
let path = getcwd() . '/' . path
31+
endif
32+
2833
let b:projectionist = {}
2934
unlet! b:projectionist_file
30-
let file = simplify(fnamemodify(a:path, ':p:s?[\/]$??'))
35+
let file = simplify(fnamemodify(path, ':p:s?[\/]$??'))
3136

3237
let root = file
3338
let previous = ""

0 commit comments

Comments
 (0)