Skip to content

Enhancements for vim-flog #3

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Install the Flog gem like this: `gem install flog`.

To install the plugin just run this command in your Terminal:

`curl https://github.com/fousa/vim-flog/raw/master/plugin/flog.vim -o ~/.vim/plugin/flog.vim`
`curl https://raw.github.com/fousa/vim-flog/master/plugin/flog.vim -o ~/.vim/plugin/flog.vim`

When this is done add `:silent exe "g:flog_enable"` to your .vimrc file.

Expand All @@ -39,16 +39,16 @@ Configuration
You can set the colors for the complexity indication with the following commands in your .vimrc:

* Set the color of for low complexity: <br/>
`:silent exe "let g:flog_low_color=#a5c261"`
`:let g:flog_low_color_hl = "term=standout ctermfg=118 ctermbg=235 guifg=#999999 guibg=#323232"`

* Set the color of for medium complexity: <br/>
`:silent exe "let g:flog_medium_color=#ffc66d"`
`:let g:flog_medium_color_hl = "term=standout ctermfg=81 ctermbg=235 guifg=#66D9EF guibg=#323232"`

* Set the color of for high complexity: <br/>
`:silent exe "let g:flog_high_color=#cc7833"`
`:let g:flog_high_color_hl = "term=standout cterm=bold ctermfg=199 ctermbg=16 gui=bold guifg=#F92672 guibg=#232526"`

* Set the background color: <br/>
`:silent exe "let g:flog_background_color=#323232"`
`:let s:background_hl = "guifg=#999999 guibg=#323232 gui=NONE"`

You can set the limits for the complexity indication with the following commands in your .vimrc:

Expand All @@ -58,6 +58,28 @@ You can set the limits for the complexity indication with the following commands
* Set the limit to switch to a high complexity: <br/>
:silent exe "`let g:flog_high_limit=20"`

You can hide some levels of complexity:

* Hide low complexity: <br/>
`:silent exe "let g:flog_hide_low=1"`

* Hide medium complexity: <br/>
`:silent exe "let g:flog_hide_medium=1"`

You can also turn flog off and on:

* Turn on flog
`:call EnableFlog()`

* Turn off flog
`:call DisableFlog()`

* Toggle flog
`:call ToggleFlog()`

Additionally, you can map this in your .vimrc:
`:map ,f :call ToggleFlog()<cr>`

Credits
-------

Expand Down
91 changes: 69 additions & 22 deletions plugin/flog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,37 @@ if !has('signs') || !has('ruby')
finish
endif

let s:low_color = "#a5c261"
let s:medium_color = "#ffc66d"
let s:high_color = "#cc7833"
let s:background_color = "#323232"
let s:low_color_hl = "term=standout ctermfg=118 ctermbg=235 guifg=#a5c261 guibg=#323232"
let s:medium_color_hl = "term=standout ctermfg=81 ctermbg=235 guifg=#ffc66d guibg=#323232"
let s:high_color_hl = "term=standout cterm=bold ctermfg=199 ctermbg=16 gui=bold guifg=#cc7833 guibg=#232526"
let s:background_hl = "guifg=#999999 guibg=#323232 gui=NONE"
let s:medium_limit = 10
let s:high_limit = 20
let s:hide_low = 0
let s:hide_medium = 0

if exists("g:flog_low_color")
let s:low_color = g:flog_low_color
if exists("g:flog_hide_low")
let s:hide_low = g:flog_hide_low
endif

if exists("g:flog_medium_color")
let s:medium_color = g:flog_medium_color
if exists("g:flog_hide_medium")
let s:hide_medium = g:flog_hide_medium
endif

if exists("g:flog_high_color")
let s:high_color = g:flog_high_color
if exists("g:flog_low_color_hl")
let s:low_color_hl = g:flog_low_color_hl
endif

if exists("g:flog_background_color")
let s:background_color = g:flog_background_color
if exists("g:flog_medium_color_hl")
let s:medium_color_hl = g:flog_medium_color_hl
endif

if exists("g:flog_high_color_hl")
let s:high_color_hl = g:flog_high_color_hl
endif

if exists("g:flog_background_hl")
let s:high_background_hl = g:flog_high_background_hl
endif

if exists("g:flog_medium_limit")
Expand Down Expand Up @@ -132,20 +142,30 @@ def show_complexity(results = {})
when medium_limit..high_limit then "medium_complexity"
else "high_complexity"
end
value = rest[0].to_i
value = "9+" if value >= 100
VIM.command ":sign define #{value.to_s} text=#{value.to_s} texthl=#{complexity}"
value = rest[0].to_i
value = "9+" if value >= 100
VIM.command ":sign define #{value.to_s} text=#{value.to_s} texthl=#{complexity}"
render_score line_number, value, medium_limit, high_limit
end
end

def render_score(line_number, value, medium_limit, high_limit)
hide_medium = VIM::evaluate 's:hide_medium'
hide_low = VIM::evaluate 's:hide_low'
if (hide_low == 1 && value < medium_limit) || (hide_medium == 1 && value < high_limit)
VIM.command ":sign unplace #{line_number}"
else
VIM.command ":sign place #{line_number} line=#{line_number} name=#{value.to_s} file=#{VIM::Buffer.current.name}"
end
end

EOF

function! s:UpdateHighlighting()
exe 'hi low_complexity guifg='.s:low_color
exe 'hi medium_complexity guifg='.s:medium_color
exe 'hi high_complexity guifg='.s:high_color
exe 'hi SignColumn guifg=#999999 guibg='.s:background_color.' gui=NONE'
exe 'hi low_complexity '.s:low_color_hl
exe 'hi medium_complexity '.s:medium_color_hl
exe 'hi high_complexity '.s:high_color_hl
exe 'hi SignColumn '.s:background_hl
endfunction

function! ShowComplexity()
Expand All @@ -168,13 +188,40 @@ call s:UpdateHighlighting()

endfunction

function! HideComplexity()
sign unplace *
call s:UpdateHighlighting()

endfunction

function! EnableFlog()
let g:flog_enable=1
if &filetype == 'ruby'
call ShowComplexity()
endif
autocmd! BufReadPost,BufWritePost,FileReadPost,FileWritePost *.rb call ShowComplexity()
endfunction

function! DisableFlog()
let g:flog_enable=0
call HideComplexity()
autocmd! BufReadPost,BufWritePost,FileReadPost,FileWritePost *.rb
endfunction

function! ToggleFlog()
if !exists("g:flog_enable") || g:flog_enable
call DisableFlog()
else
call EnableFlog()
end
endfunction

call s:UpdateHighlighting()

sign define low_color text=XX texthl=low_complexity
sign define medium_color text=XX texthl=medium_complexity
sign define high_color text=XX texthl=high_complexity


if !exists("g:flow_enable") || g:flog_enable
autocmd! BufReadPost,BufWritePost,FileReadPost,FileWritePost *.rb call ShowComplexity()
if !exists("g:flog_enable") || g:flog_enable
call EnableFlog()
endif