Skip to content

Commit f672525

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 ea1347b commit f672525

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

plugin/projectionist.vim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ function! s:has(ns, root, requirements) abort
6969
endfunction
7070

7171
function! ProjectionistDetect(path) abort
72+
let path = a:path
73+
if path !~ '^/'
74+
let path = getcwd() . '/' . path
75+
endif
76+
7277
let b:projectionist = {}
7378
unlet! b:projectionist_file
74-
if a:path =~# '^\a[[:alnum:].+-]\+:'
75-
let file = substitute(a:path, '[\/]$', '', '')
76-
else
77-
let file = simplify(fnamemodify(resolve(a:path), ':p:s?[\/]$??'))
78-
endif
79+
let file = simplify(fnamemodify(path, ':p:s?[\/]$??'))
7980

8081
let root = file
8182
let ns = matchstr(file, '^\a\a\+\ze:')

0 commit comments

Comments
 (0)