From c764242b63a090ba48deda13439eac8a3bcf8840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Fri, 13 Mar 2015 10:42:15 +0100 Subject: [PATCH] Read modelines from local files Read modelines from files when there's a local configuration directory and the files are under the local configuration's root --- cfg/99-modelines.vim | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 cfg/99-modelines.vim diff --git a/cfg/99-modelines.vim b/cfg/99-modelines.vim new file mode 100644 index 0000000..6db03e4 --- /dev/null +++ b/cfg/99-modelines.vim @@ -0,0 +1,23 @@ +" When a local configuration is in use and a file is being opened under the +" local configuration's directory, enable modelines locally. Only allow a +" single modeline. + +function! CheckModelines() + if !exists( "g:vim_local_path" ) + return + endif + + let l:file_path = expand( '%:p' ) + let l:vim_local_root = fnamemodify( g:vim_local_path , ':p:h:h' ) . '/' + let l:lvlr = len( l:vim_local_root ) + + if len( l:file_path ) <= l:lvlr + \ || l:file_path[0:(l:lvlr-1)] !=# l:vim_local_root + return + endif + + setlocal modeline +endfunction + +set modelines=1 +au BufRead * call CheckModelines()