1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 10:30:05 +08:00

chore(tools): use bundle SourceCounter

This commit is contained in:
wsdjeg 2023-06-17 16:41:31 +08:00
parent 9111a210a3
commit 0b22cc3e0b
10 changed files with 256 additions and 1 deletions

View File

@ -22,7 +22,7 @@ function! SpaceVim#layers#tools#plugins() abort
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-cheat', { 'on_cmd' : 'Cheat'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-unstack', { 'merged' : 0}])
call add(plugins, ['wsdjeg/Mysql.vim', { 'on_cmd' : 'SQLGetConnection'}])
call add(plugins, ['wsdjeg/SourceCounter.vim', { 'on_cmd' : 'SourceCounter'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/SourceCounter.vim', { 'on_cmd' : 'SourceCounter'}])
call add(plugins, [g:_spacevim_root_dir . 'bundle/calendar.vim',{ 'on_cmd' : 'Calendar'}])
call add(plugins, ['junegunn/limelight.vim', { 'on_cmd' : 'Limelight'}])
call add(plugins, ['junegunn/goyo.vim', { 'on_cmd' : 'Goyo', 'loadconf' : 1}])

1
bundle/SourceCounter.vim/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
doc/tags

9
bundle/SourceCounter.vim/.vintrc.yaml vendored Normal file
View File

@ -0,0 +1,9 @@
cmdargs:
# Checking more strictly
severity: style_problem
policies:
ProhibitImplicitScopeVariable:
enabled: false
ProhibitAbbreviationOption:
enabled: false

21
bundle/SourceCounter.vim/LICENSE vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2016 Wang Shidong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

18
bundle/SourceCounter.vim/README.md vendored Normal file
View File

@ -0,0 +1,18 @@
# SourceCounter.vim
> source counter in vim
### Useage
- `:SourceCounter` : Display result in cmdline
- `:SourceCounter!` : Display result in new tab
### Options
- `g:source_counter_sort` : sort method of result, by default, it is `files`, and if you want to sort by lines, use `let g:source_counter_sort = 'lines'`
### Screenshot
![SourceCounter](pic/screen.png)

View File

@ -0,0 +1,5 @@
{
"name": "SourceCounter.vim",
"description": "Source counter in vim",
"author": "wsdjeg"
}

View File

@ -0,0 +1,138 @@
scriptencoding utf-8
let s:support_ft = ['vim', 'java', 'c', 'py', 'md', 'txt']
function! SourceCounter#View(bang, ...) abort
let result = []
if a:0
let fts = a:000
else
let fts = s:support_ft
endif
echom string(fts)
for ft in fts
let _rs = s:counter(ft)
if !empty(_rs)
call add(result, _rs)
endif
endfor
let result = sort(deepcopy(result), function('s:compare'))
let table = s:draw_table(result)
if a:bang
tabnew
for line in table
call append(line('$'), line)
endfor
else
echo join(table, "\n")
endif
endfunction
function! s:compare(a, b) abort
let m = get(g:, 'source_counter_sort', 'files')
if m ==# 'lines'
return a:a[2] == a:b[2] ? 0 : a:a[2] > a:b[2] ? -1 : 1
else
return a:a[1] == a:b[1] ? 0 : a:a[1] > a:b[1] ? -1 : 1
endif
endfunction
" https://en.wikipedia.org/wiki/Box-drawing_character
function! s:draw_table(rst) abort
if &encoding ==# 'utf-8'
let top_left_corner = '╭'
let top_right_corner = '╮'
let bottom_left_corner = '╰'
let bottom_right_corner = '╯'
let side = '│'
let top_bottom_side = '─'
let middle = '┼'
let top_middle = '┬'
let left_middle = '├'
let right_middle = '┤'
let bottom_middle = '┴'
else
let top_left_corner = '*'
let top_right_corner = '*'
let bottom_left_corner = '*'
let bottom_right_corner = '*'
let side = '|'
let top_bottom_side = '-'
let middle = '*'
let top_middle = '*'
let left_middle = '*'
let right_middle = '*'
let bottom_middle = '*'
endif
let table = []
let top_line = top_left_corner
\ . repeat(top_bottom_side, 15)
\ . top_middle
\ . repeat(top_bottom_side, 15)
\ . top_middle
\ . repeat(top_bottom_side, 15)
\ . top_right_corner
let middle_line = left_middle
\ . repeat(top_bottom_side, 15)
\ . middle
\ . repeat(top_bottom_side, 15)
\ . middle
\ . repeat(top_bottom_side, 15)
\ . right_middle
let bottom_line = bottom_left_corner
\ . repeat(top_bottom_side, 15)
\ . bottom_middle
\ . repeat(top_bottom_side, 15)
\ . bottom_middle
\ . repeat(top_bottom_side, 15)
\ . bottom_right_corner
call add(table, top_line)
let result = [['filetype', 'files', 'lines']] + a:rst
for rsl in result
let ft_line = side
\ . rsl[0] . repeat(' ', 15 - strwidth(rsl[0]))
\ . side
\ . rsl[1] . repeat(' ', 15 - strwidth(rsl[1]))
\ . side
\ . rsl[2] . repeat(' ', 15 - strwidth(rsl[2]))
\ . side
call add(table, ft_line)
call add(table, middle_line)
endfor
let table[-1] = bottom_line
return table
endfunction
function! s:counter(ft) abort
let path = getcwd()
let partten = '**/*.' . a:ft
if executable('ag')
if has('nvim')
let files = systemlist(['ag','-g', '.' . a:ft . '$'])
else
let files = split(system('ag -g .'.a:ft.'$'),nr2char(10))
endif
else
let files = globpath(l:path, l:partten, 0, 1)
endif
if len(files) == 0
return []
endif
let lines = 0
if has('nvim')
if len(files) > 380
while !empty(files)
let lines += matchstr(systemlist(['wc', '-l'] + remove(files, 0, min([380, len(files) - 1])))[-1], '\d\+')
endwhile
else
let lines = matchstr(systemlist(['wc', '-l'] + files)[-1], '\d\+')
endif
else
for fl in files
let lines += str2nr(matchstr(system('wc -l '. fl), '\d\+'))
endfor
endif
return [a:ft, len(files), lines]
endfunction

View File

@ -0,0 +1,35 @@
*SourceCounter.vim.txt* Source counter in vim
wsdjeg *SourceCounter.vim*
==============================================================================
CONTENTS *SourceCounter.vim-contents*
1. Introduction....................................|SourceCounter.vim-intro|
2. Configuration..................................|SourceCounter.vim-config|
3. Commands.....................................|SourceCounter.vim-commands|
==============================================================================
INTRODUCTION *SourceCounter.vim-intro*
Sources counter for vim and neovim.
USAGE:
>
:SourceCounter! vim md java html
<
==============================================================================
CONFIGURATION *SourceCounter.vim-config*
*g:source_counter_sort*
specific the sort type of result, 'lines' or 'files', default is 'files'.
==============================================================================
COMMANDS *SourceCounter.vim-commands*
:SourceCounter[!] [filetypes] *:SourceCounter*
List lines count for specific [filetypes], or all supported filetypes.
[!] forces desplay result in new tab.
vim:tw=78:ts=8:ft=help:norl:

BIN
bundle/SourceCounter.vim/pic/screen.png vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

View File

@ -0,0 +1,28 @@
""
" @section Introduction, intro
" Sources counter for vim and neovim.
"
" USAGE:
" >
" :SourceCounter! vim md java html
" <
let s:save_cpo = &cpoptions
set cpoptions&vim
""
" List lines count for specific [filetypes], or all supported filetypes.
"
" [!] forces desplay result in new tab.
command! -bang -nargs=* SourceCounter call SourceCounter#View('!' ==# '<bang>', <f-args>)
if !exists('g:source_counter_sort')
""
" specific the sort type of result, 'lines' or 'files', default is
" 'files'.
let g:source_counter_sort = 'files'
endif
let &cpoptions = s:save_cpo
unlet s:save_cpo