Browse Source

Added perlcritic.cim, my own clone of pep8.vim using Perl::Critic

In order to make it work, you need to:

*   install Perl::Critic

*   add bin/perl_critic to your path

    Note that `perlcritic` script name is already taken by wrapper
    script that comes with Perl::Critic itself
Alois Mahdal 11 years ago
parent
commit
7564e3b917
2 changed files with 69 additions and 0 deletions
  1. 13
    0
      bin/perlcritic_vim
  2. 56
    0
      dotfiles/vim/bundle/perlcritic/ftplugin/perl/perlcritic.vim

+ 13
- 0
bin/perlcritic_vim View File

@@ -0,0 +1,13 @@
1
+#!/usr/bin/perl
2
+
3
+use Perl::Critic;
4
+
5
+my $file = shift;
6
+my $critic = Perl::Critic->new();
7
+my @violations = $critic->critique($file);
8
+
9
+for (@violations) {
10
+    my ($l, $c) = m/.* at line (\d+), column (\d+)\./;
11
+    $_ =~ s/ at line \d+, column \d+\././;
12
+    print "$file:$l:$c:$_";
13
+}

+ 56
- 0
dotfiles/vim/bundle/perlcritic/ftplugin/perl/perlcritic.vim View File

@@ -0,0 +1,56 @@
1
+" To change mapping, just put
2
+" let g:perlcritic_map='whatever'
3
+" in your .vimrc
4
+" To change the color of
5
+function! <SID>PerlCritic()
6
+  set lazyredraw
7
+  " Close any existing cwindows.
8
+  cclose
9
+  let l:grepformat_save = &grepformat
10
+  let l:grepprogram_save = &grepprg
11
+  set grepformat&vim
12
+  set grepformat&vim
13
+  let &grepformat = '%f:%l:%m'
14
+  let &grepprg = 'perlcritic_vim'
15
+  if &readonly == 0 | update | endif
16
+  silent! grep! %
17
+  let &grepformat = l:grepformat_save
18
+  let &grepprg = l:grepprogram_save
19
+  let l:mod_total = 0
20
+  let l:win_count = 1
21
+  " Determine correct window height
22
+  windo let l:win_count = l:win_count + 1
23
+  if l:win_count <= 2 | let l:win_count = 4 | endif
24
+  windo let l:mod_total = l:mod_total + winheight(0)/l:win_count |
25
+        \ execute 'resize +'.l:mod_total
26
+  " Open cwindow
27
+  execute 'belowright copen '.l:mod_total
28
+  nnoremap <buffer> <silent> c :cclose<CR>
29
+  set nolazyredraw
30
+  redraw!
31
+  let tlist=getqflist() ", 'get(v:val, ''bufnr'')')
32
+  if empty(tlist)
33
+	  if !hlexists('GreenBar')
34
+		  hi GreenBar term=reverse ctermfg=white ctermbg=darkgreen guifg=white guibg=darkgreen
35
+	  endif
36
+	  echohl GreenBar
37
+	  echomsg "Perl::Critic correct"
38
+	  echohl None
39
+	  cclose
40
+  endif
41
+endfunction
42
+
43
+  if !exists('g:perlcritic_map')
44
+    let g:perlcritic_map='<F5>'
45
+  endif
46
+if ( !hasmapto('<SID>PerlCritic()') && (maparg(g:perlcritic_map) == '') )
47
+  exe 'nnoremap <silent> '. g:perlcritic_map .' :call <SID>PerlCritic()<CR>'
48
+"  map <F5> :call <SID>PerlCritic()<CR>
49
+"  map! <F5> :call <SID>PerlCritic()<CR>
50
+else
51
+  if ( !has("gui_running") || has("win32") )
52
+    echo "Python Perl::Critic Error: No Key mapped.\n".
53
+          \ g:perlcritic_map ." is taken and a replacement was not assigned."
54
+  endif
55
+endif
56
+