geoffrey (owner)

Revisions

gist: 81105 Download_button fork
public
Public Clone URL: git://gist.github.com/81105.git
Embed All Files: show embed
symfony_root.vim #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"-------------------------------------------------------------------------------
" Description: Finds and cd to the symfony root of the project
" Copyright: Copyright (C) 2009 Geoffrey Bachelet
" Maintainer: Geoffrey Bachelet
" Version: 1.0
"-------------------------------------------------------------------------------
 
if exists('find_symfony_root_loaded')
  finish
endif
 
let find_symfony_root_loaded = 1
 
if ! exists('find_symfony_root_symfony_executable')
  let find_symfony_root_symfony_executable = 'symfony'
endif
 
" root detection when opening a new vim seems to work
" only if these two events are bound. not sure why.
autocmd BufWinEnter,BufRead * call FindSymfonyRoot()
 
function FindSymfonyRoot()
  let l:cwd = GetAbsoluteDirname(@%)
  let l:symfony_root = findfile(g:find_symfony_root_symfony_executable, l:cwd.';')
  let l:symfony_root = GetAbsoluteDirname(l:symfony_root)
  if strlen(l:symfony_root) != 0
    execute 'cd '.l:symfony_root
  endif
endfunction
 
function GetAbsoluteDirname(path)
  let l:path = a:path
" gets the dirname
  if !isdirectory(l:path)
    let l:path = strpart(l:path, 0, strridx(l:path, '/'))
  endif
 
" makes it absolute
  if match(l:path, '/') != 0
    let l:path = getcwd().'/'.l:path
  endif
 
  return l:path
endfunction