Commits

Godefroid Chapelle  committed 9407c49

use vim.current.buffer.name instead of eval...
set colors each time

  • Participants
  • Parent commits 526e0e9

Comments (0)

Files changed (3)

 " This will add cyclomatic complexity annotations to your source code. It is
 " no longer wrong (as previous versions were!)
 
+if !has('signs')
+    finish
+endif
+if !has('python')
+    finish
+endif
 python << endpython
 import vim
 %(python_source)s
     python << END
 show_complexity()
 END
+" no idea why it is needed to update colors each time
+" to actually see the colors
+hi low_complexity guifg=#004400 guibg=#004400
+hi medium_complexity guifg=#bbbb00 guibg=#bbbb00
+hi high_complexity guifg=#ff2222 guibg=#ff2222
 endfunction
 
 hi SignColumn guifg=fg guibg=bg

File complexity.py

 
 
 def show_complexity():
-    current_file = get_current_file_name()
+    current_file = vim.current.buffer.name
     try:
         scores = compute_scores_for(current_file)
     except (IndentationError, SyntaxError):
     update_line_markers(line_changes)
 
 
-def get_current_file_name():
-    return vim.eval('expand("%:p")')
-
-
 def compute_scores_for(filename):
     code = open(filename).read()
     scores = compute_code_complexity(code).results.ordered_by_line()
 
 
 def update_line_markers(line_changes):
+    filename = vim.current.buffer.name
     for line, complexity in line_changes.iteritems():
         vim.command(':sign unplace %i' % line)
         vim.command(':sign place %i line=%i name=%s file=%s' %
-                    (line, line, complexity, vim.eval('expand("%:p")')))#}}}
+                    (line, line, complexity, filename))#}}}
 

File complexity.vim

 " This will add cyclomatic complexity annotations to your source code. It is
 " no longer wrong (as previous versions were!)
 
+if !has('signs')
+    finish
+endif
+if !has('python')
+    finish
+endif
 python << endpython
 import vim
 import compiler#{{{
 
 
 def show_complexity():
-    current_file = get_current_file_name()
+    current_file = vim.current.buffer.name
     try:
         scores = compute_scores_for(current_file)
     except (IndentationError, SyntaxError):
     update_line_markers(line_changes)
 
 
-def get_current_file_name():
-    return vim.eval('expand("%:p")')
-
-
 def compute_scores_for(filename):
     code = open(filename).read()
     scores = compute_code_complexity(code).results.ordered_by_line()
 
 
 def update_line_markers(line_changes):
+    filename = vim.current.buffer.name
     for line, complexity in line_changes.iteritems():
         vim.command(':sign unplace %i' % line)
         vim.command(':sign place %i line=%i name=%s file=%s' %
-                    (line, line, complexity, vim.eval('expand("%:p")')))#}}}
+                    (line, line, complexity, filename))#}}}
 
 
 endpython
     python << END
 show_complexity()
 END
+" no idea why it is needed to update colors each time
+" to actually see the colors
+hi low_complexity guifg=#004400 guibg=#004400
+hi medium_complexity guifg=#bbbb00 guibg=#bbbb00
+hi high_complexity guifg=#ff2222 guibg=#ff2222
 endfunction
 
 hi SignColumn guifg=fg guibg=bg