Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

pvim fine-tuned

  • Loading branch information...
commit 4718d7806b48f60b8976d4d76e84de7443b0d873 1 parent e7465b5
Yanick Champoux authored October 14, 2012
103  bin/gen_pvim 100644 → 100755
... ...
@@ -1,4 +1,4 @@
1  
-#!/usr/bin/env perl 
  1
+#!/usr/bin/env perl
2 2
 
3 3
 # :map ,r <ESC>:!perl parse_project.pl %:h<CR>
4 4
 
@@ -28,6 +28,10 @@ has project_filename => (
28 28
     coerce => sub { file(shift) },
29 29
 );
30 30
 
  31
+method has_project_file {
  32
+    return -f $self->project_filename;
  33
+}
  34
+
31 35
 has project_file => (
32 36
     is => 'ro',
33 37
     lazy => 1,
@@ -57,6 +61,7 @@ has absolute_path => (
57 61
         $self->root ||
58 62
         $self->parent->absolute_path->subdir($self->location)->cleanup;
59 63
     },
  64
+    handles => [ 'subsumes' ],
60 65
 );
61 66
 
62 67
 has project => (
@@ -112,8 +117,6 @@ method read_dir {
112 117
             $self->add_subdir(
113 118
                 name     => $1, 
114 119
                 location =>  $2,
115  
-                project  => $self->project,
116  
-                parent   => $self,
117 120
             );
118 121
             next;
119 122
         }
@@ -131,9 +134,9 @@ method read_dir {
131 134
     }
132 135
 }
133 136
 
134  
-method add_subdir(:$name, :$location, :$project, :$parent){
135  
-    my $d = Node->new( name => $name, location => $location, project =>
136  
-        $project, parent => $parent );
  137
+method add_subdir(:$name, :$location){
  138
+    my $d = Node->new( name => $name, location => $location, parent => $self,
  139
+    project => $self->project );
137 140
     push $self->subdirs, $d;
138 141
     $d->read_dir;
139 142
 }
@@ -190,9 +193,6 @@ has indent => (
190 193
 method print_children {
191 194
 
192 195
     for my $file ( $self->all_files ) {
193  
-        #my $fp = $path->file($file) =~ s#^/##r;
194  
-        #next unless -f $fp;
195  
-        #next if any { $path->file($file)->cleanup->stringify =~ $_ } @ignores;
196 196
         next if $self->project->should_ignore($file);
197 197
         say '  ' x $self->indent, $file->relative($self->absolute_path);
198 198
     }
@@ -207,7 +207,7 @@ method print_dir {
207 207
     return if $self->parent and
208 208
         $self->project->should_ignore($self->absolute_path);
209 209
 
210  
-    printf "%s%s Files=%s {\n",
  210
+    printf "%s%-20s Files=%s {\n",
211 211
         '  ' x ($self->indent-1),
212 212
         $self->name, $self->location;
213 213
 
@@ -231,7 +231,6 @@ method should_ignore($file){
231 231
         push @dirs, $d->all_subdirs;
232 232
 
233 233
         my $rel = $file->relative($d->absolute_path);
234  
-        $rel .= '/' if ref $file eq 'Path::Class::Dir';
235 234
         return 1 if any { $rel =~ /^$_$/ } $d->all_ignores;
236 235
 
237 236
     }
@@ -239,10 +238,6 @@ method should_ignore($file){
239 238
     return 0;
240 239
 }
241 240
 
242  
-method subsumes($path) {
243  
-    return $self->absolute_path->subsumes($path);
244  
-}
245  
-
246 241
 method add_file($file) {
247 242
     my ($sub) = sort { length($a) <=> length($b) } grep { $_->subsumes($file) } $self->all_subdirs;
248 243
 
@@ -276,67 +271,25 @@ package main;
276 271
 chdir shift if @ARGV;
277 272
 
278 273
 my $p = Node->new;
279  
-$p->read_project;
280  
-$p->add_new_files;
281  
-$p->save_project;
282  
-
283  
-
284  
-__END__
285  
-
286  
-
287  
-my $project_dir = shift || '.';
288  
-chdir $project_dir;
289  
-
290  
-my $project_file = file( 'project.vim' );
291  
-
292  
-my $p = read_project( $project_file );
293  
-
294  
-add_new_files($p);
295  
-
296  
-# create ignore regexes
297  
-my @ignores = generate_ignores($p);
298  
-
299  
-save_project($p);
300  
-
301  
-#####
302  
-
303  
-
304  
-
305  
-sub generate_ignores {
306  
-    my $dir = shift;
307  
-    my $path = shift || dir('/');
308  
-
309  
-    $path = $path->subdir($dir->{dir})->cleanup;
310  
-
311  
-    my $re_path = quotemeta $path;
312  
-    $re_path .= '\/' unless $re_path =~ m#\\/$#;
313  
-
314  
-    return map( { join '', '^', 
315  
-        "$re_path$_" ,
316  
-            , '$' }
317  
-        @{ $dir->{ignores} } ),
318  
-        map { __SUB__->($_,$path) } @{ $dir->{dirs} };
  274
+if ( $p->has_project_file ) {
  275
+    $p->read_project;
319 276
 }
320  
-
321  
-
322  
-
323  
-
324  
-sub read_project {
325  
-    open my $fh, '<', shift;
326  
-
327  
-    my $p;
328  
-
329  
-    while(<$fh>) {
330  
-        next until /^(\S+)=(\S+).*?\{/;
331  
-        $p->{name} = $1;
332  
-        $p->{root}  = dir($2);
333  
-        last;
334  
-    }
335  
-
336  
-    $p = { %$p, read_dir($fh, $p) };
337  
-
338  
-    return $p;
  277
+else {
  278
+    # build default skeleton
  279
+    use Cwd;
  280
+    my $path = getcwd();
  281
+    $p->root($path);
  282
+    $path =~ s#.*/##;
  283
+    $p->name($path);
  284
+
  285
+    push $p->subdirs,
  286
+        Node->new( name => 'lib/', location => 'lib', parent => $p, project => $p ),
  287
+        Node->new( name => 't/', location => 't' , parent => $p, project => $p ),
  288
+        Node->new( name => 'distro', location => '.' , parent => $p, project => $p );
  289
+    push $p->ignores, qw/ \.git /;
339 290
 }
  291
+$p->add_new_files;
  292
+$p->print_project;
340 293
 
341 294
 
342  
-
  295
+__END__
2  vim-plugins/project/plugin/project.vim
@@ -1221,7 +1221,7 @@ function! s:Project(filename) " <<<
1221 1221
         nnoremap <buffer> <silent> <LocalLeader>r :call <SID>RefreshEntriesFromDir(0)<CR>
1222 1222
         nnoremap <buffer> <silent> <LocalLeader>R :call <SID>RefreshEntriesFromDir(1)<CR>
1223 1223
         " For Windows users: same as \R
1224  
-        nnoremap <buffer> <silent>           <F5> :call <SID>RefreshEntriesFromDir(1)<CR>
  1224
+        nnoremap <buffer> <silent>           <F5> 1GdG:r !gen_pvim %:h<CR>1Gdd
1225 1225
         nnoremap <buffer> <silent> <LocalLeader>e :call <SID>OpenEntry(line('.'), '', '', 0)<CR>
1226 1226
         nnoremap <buffer> <silent> <LocalLeader>E :call <SID>OpenEntry(line('.'), '', 'e', 1)<CR>
1227 1227
         " The :help command stomps on the Project Window.  Try to avoid that.

0 notes on commit 4718d78

Please sign in to comment.
Something went wrong with that request. Please try again.