From c903e32d7986d455d53cff895d686f78c64d913a Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 11 Jul 2019 19:00:59 +0800 Subject: [PATCH] Detech todo (#2943) --- .SpaceVim.d/autoload/SpaceVim/dev/todo.vim | 108 ----------------- .SpaceVim.d/init.vim | 1 - .ci/detach_plugin.sh | 21 ++++ autoload/SpaceVim/mapping/space.vim | 2 +- autoload/SpaceVim/plugins/todo.vim | 109 ++++++++++++++++++ .../syntax => syntax}/SpaceVimTodoManager.vim | 41 +++---- 6 files changed, 152 insertions(+), 130 deletions(-) create mode 100644 autoload/SpaceVim/plugins/todo.vim rename {.SpaceVim.d/syntax => syntax}/SpaceVimTodoManager.vim (96%) diff --git a/.SpaceVim.d/autoload/SpaceVim/dev/todo.vim b/.SpaceVim.d/autoload/SpaceVim/dev/todo.vim index 9ff2bd592..e69de29bb 100644 --- a/.SpaceVim.d/autoload/SpaceVim/dev/todo.vim +++ b/.SpaceVim.d/autoload/SpaceVim/dev/todo.vim @@ -1,108 +0,0 @@ -"============================================================================= -" todo.vim --- todo manager for SpaceVim -" Copyright (c) 2016-2017 Wang Shidong & Contributors -" Author: Wang Shidong < wsdjeg at 163.com > -" URL: https://spacevim.org -" License: GPLv3 -"============================================================================= - -let s:JOB = SpaceVim#api#import('job') -let s:BUFFER = SpaceVim#api#import('vim#buffer') - -" @question any other recommanded tag? -let s:labels = map(['fixme', 'question', 'todo', 'idea'], '"@" . v:val') - -function! SpaceVim#dev#todo#list() abort - call s:open_win() -endfunction - -let s:bufnr = 0 - -function! s:open_win() abort - if s:bufnr != 0 && bufexists(s:bufnr) - exe 'bd ' . s:bufnr - endif - botright split __todo_manager__ - let lines = &lines * 30 / 100 - exe 'resize ' . lines - setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber winfixheight nomodifiable - set filetype=SpaceVimTodoManager - let s:bufnr = bufnr('%') - call s:update_todo_content() - nnoremap :call open_todo() -endfunction - -" @todo Improve todo manager -function! s:update_todo_content() abort - let s:todos = [] - let s:todo = {} - " @fixme fix the rg command for todo manager - let argv = ['rg','--hidden', '--no-heading', '-g', '!.git', '--color=never', '--with-filename', '--line-number', '--column', '-e', join(s:labels, '|'), '.'] - call SpaceVim#logger#info('todo cmd:' . string(argv)) - let jobid = s:JOB.start(argv, { - \ 'on_stdout' : function('s:stdout'), - \ 'on_stderr' : function('s:stderr'), - \ 'on_exit' : function('s:exit'), - \ }) - call SpaceVim#logger#info('todo jobid:' . string(jobid)) -endfunction - -function! s:stdout(id, data, event) abort - call SpaceVim#logger#info('todomanager stdout: ' . string(a:data)) - for data in a:data - if !empty(data) - let file = fnameescape(split(data, ':\d\+:')[0]) - let line = matchstr(data, ':\d\+:')[1:-2] - let column = matchstr(data, '\(:\d\+\)\@<=:\d\+:')[1:-2] - let lebal = matchstr(data, join(s:labels, '\|')) - let title = split(data, lebal)[1] - " @todo add time tag - call add(s:todos, - \ { - \ 'file' : file, - \ 'line' : line, - \ 'column' : column, - \ 'title' : title, - \ 'lebal' : lebal, - \ } - \ ) - endif - endfor -endfunction - -function! s:stderr(id, data, event) abort - call SpaceVim#logger#info('todomanager stderr: ' . string(a:data)) -endfunction - -function! s:exit(id, data, event ) abort - call SpaceVim#logger#info('todomanager exit: ' . string(a:data)) - let s:todos = sort(s:todos, function('s:compare_todo')) - let label_w = max(map(deepcopy(s:todos), 'strlen(v:val.lebal)')) - let file_w = max(map(deepcopy(s:todos), 'strlen(v:val.file)')) - let expr = "v:val.lebal . repeat(' ', label_w - strlen(v:val.lebal)) . ' ' ." - \ . "SpaceVim#api#import('file').unify_path(v:val.file, ':.') . repeat(' ', file_w - strlen(v:val.file)) . ' ' ." - \ . "v:val.title" - let lines = map(deepcopy(s:todos),expr) - call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, lines) -endfunction - -function! s:compare_todo(a, b) abort - let a = index(s:labels, a:a.lebal) - let b = index(s:labels, a:b.lebal) - return a == b ? 0 : a > b ? 1 : -1 -endfunction - -function! s:open_todo() abort - let todo = s:todos[line('.') - 1] - try - close - catch - endtry - exe 'e ' . todo.file - call cursor(todo.line, todo.column) - noautocmd normal! : -endfunction - -" @todo fuzzy find todo list -" after open todo manager buffer, we should be able to fuzzy find the item we -" need. diff --git a/.SpaceVim.d/init.vim b/.SpaceVim.d/init.vim index 093d29e5a..bf8ffb538 100644 --- a/.SpaceVim.d/init.vim +++ b/.SpaceVim.d/init.vim @@ -10,7 +10,6 @@ let g:spacevim_force_global_config = 1 call SpaceVim#custom#SPC('nnoremap', ['a', 'r'], 'call SpaceVim#dev#releases#open()', 'Release SpaceVim', 1) call SpaceVim#custom#SPC('nnoremap', ['a', 'w'], 'call SpaceVim#dev#website#open()', 'Open SpaceVim local website', 1) call SpaceVim#custom#SPC('nnoremap', ['a', 't'], 'call SpaceVim#dev#website#terminal()', 'Close SpaceVim local website', 1) -call SpaceVim#custom#SPC('nnoremap', ['a', 'o'], 'call SpaceVim#dev#todo#list()', 'Open todo manager', 1) " after run make test, the vader will be downloaded to ./build/vader/ diff --git a/.ci/detach_plugin.sh b/.ci/detach_plugin.sh index 0df628907..aae96aed5 100755 --- a/.ci/detach_plugin.sh +++ b/.ci/detach_plugin.sh @@ -75,6 +75,27 @@ main () { rm -rf detach/$1 exit 0 ;; + vim-todo) + git clone https://github.com/wsdjeg/vim-todo.vim.git detach/$1 + cd detach/$1 + _checkdir syntax/ + _detect syntax/SpaceVimTodoManager.vim + _checkdir autoload/SpaceVim/api/vim + _checkdir autoload/SpaceVim/plugins + _detect autoload/SpaceVim/plugins/todo.vim + _detect autoload/SpaceVim/api/job.vim + _detect autoload/SpaceVim/api/vim/buffer.vim + _detect LICENSE + git add . + git config user.email "wsdjeg@qq.com" + git config user.name "SpaceVimBot" + git commit -m "Auto Update" + git remote add wsdjeg_vim_todo https://SpaceVimBot:${BOTSECRET}@github.com/wsdjeg/vim-todo.vim.git + git push wsdjeg_vim_todo master + cd - + rm -rf detach/$1 + exit 0 + ;; spacevim-theme) exit 0 esac diff --git a/autoload/SpaceVim/mapping/space.vim b/autoload/SpaceVim/mapping/space.vim index 5ff5da9c7..b6e1e3ef7 100644 --- a/autoload/SpaceVim/mapping/space.vim +++ b/autoload/SpaceVim/mapping/space.vim @@ -515,7 +515,7 @@ function! SpaceVim#mapping#space#init() abort call SpaceVim#mapping#space#def('nnoremap', ['h', 'd', 'k'], \ 'call SpaceVim#plugins#help#describe_key()', \ 'describe key bindings', 1) - + call SpaceVim#custom#SPC('nnoremap', ['a', 'o'], 'call SpaceVim#plugins#todo#list()', 'Open todo manager', 1) endfunction function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort diff --git a/autoload/SpaceVim/plugins/todo.vim b/autoload/SpaceVim/plugins/todo.vim new file mode 100644 index 000000000..58bd010a5 --- /dev/null +++ b/autoload/SpaceVim/plugins/todo.vim @@ -0,0 +1,109 @@ +"============================================================================= +" todo.vim --- todo manager for SpaceVim +" Copyright (c) 2016-2017 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg at 163.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + +let s:JOB = SpaceVim#api#import('job') +let s:BUFFER = SpaceVim#api#import('vim#buffer') + +" @question any other recommanded tag? +let s:labels = map(['fixme', 'question', 'todo', 'idea'], '"@" . v:val') + +function! SpaceVim#plugins#todo#list() abort + call s:open_win() +endfunction + +let s:bufnr = 0 + +function! s:open_win() abort + if s:bufnr != 0 && bufexists(s:bufnr) + exe 'bd ' . s:bufnr + endif + botright split __todo_manager__ + let lines = &lines * 30 / 100 + exe 'resize ' . lines + setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber winfixheight nomodifiable + set filetype=SpaceVimTodoManager + let s:bufnr = bufnr('%') + call s:update_todo_content() + nnoremap :call open_todo() +endfunction + +" @todo Improve todo manager +function! s:update_todo_content() abort + let s:todos = [] + let s:todo = {} + " @fixme fix the rg command for todo manager + let argv = ['rg','--hidden', '--no-heading', '-g', '!.git', '--color=never', '--with-filename', '--line-number', '--column', '-e', join(s:labels, '|'), '.'] + call SpaceVim#logger#info('todo cmd:' . string(argv)) + let jobid = s:JOB.start(argv, { + \ 'on_stdout' : function('s:stdout'), + \ 'on_stderr' : function('s:stderr'), + \ 'on_exit' : function('s:exit'), + \ }) + call SpaceVim#logger#info('todo jobid:' . string(jobid)) +endfunction + +function! s:stdout(id, data, event) abort + call SpaceVim#logger#info('todomanager stdout: ' . string(a:data)) + for data in a:data + if !empty(data) + let file = fnameescape(split(data, ':\d\+:')[0]) + let line = matchstr(data, ':\d\+:')[1:-2] + let column = matchstr(data, '\(:\d\+\)\@<=:\d\+:')[1:-2] + let lebal = matchstr(data, join(s:labels, '\|')) + let title = split(data, lebal)[1] + " @todo add time tag + call add(s:todos, + \ { + \ 'file' : file, + \ 'line' : line, + \ 'column' : column, + \ 'title' : title, + \ 'lebal' : lebal, + \ } + \ ) + endif + endfor +endfunction + +function! s:stderr(id, data, event) abort + call SpaceVim#logger#info('todomanager stderr: ' . string(a:data)) +endfunction + +function! s:exit(id, data, event ) abort + call SpaceVim#logger#info('todomanager exit: ' . string(a:data)) + let s:todos = sort(s:todos, function('s:compare_todo')) + let label_w = max(map(deepcopy(s:todos), 'strlen(v:val.lebal)')) + let file_w = max(map(deepcopy(s:todos), 'strlen(v:val.file)')) + let expr = "v:val.lebal . repeat(' ', label_w - strlen(v:val.lebal)) . ' ' ." + \ . "SpaceVim#api#import('file').unify_path(v:val.file, ':.') . repeat(' ', file_w - strlen(v:val.file)) . ' ' ." + \ . "v:val.title" + let lines = map(deepcopy(s:todos),expr) + call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, lines) +endfunction + +function! s:compare_todo(a, b) abort + let a = index(s:labels, a:a.lebal) + let b = index(s:labels, a:b.lebal) + return a == b ? 0 : a > b ? 1 : -1 +endfunction + +function! s:open_todo() abort + let todo = s:todos[line('.') - 1] + try + close + catch + endtry + exe 'e ' . todo.file + call cursor(todo.line, todo.column) + noautocmd normal! : +endfunction + +" @todo fuzzy find todo list +" after open todo manager buffer, we should be able to fuzzy find the item we +" need. + diff --git a/.SpaceVim.d/syntax/SpaceVimTodoManager.vim b/syntax/SpaceVimTodoManager.vim similarity index 96% rename from .SpaceVim.d/syntax/SpaceVimTodoManager.vim rename to syntax/SpaceVimTodoManager.vim index 3805a608c..41c576d9a 100644 --- a/.SpaceVim.d/syntax/SpaceVimTodoManager.vim +++ b/syntax/SpaceVimTodoManager.vim @@ -1,20 +1,21 @@ -if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTodoManager' - finish -endif -let b:current_syntax = 'SpaceVimTodoManager' -syntax case ignore - -syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/ -syn match TODOTAG /^\s*@[a-zA-Z]*/ -syn match TODOQUESTION /^\s*@ques[a-z]*/ -syn match TODOFIXME /^\s*@fixm[a-z]*/ -" syn match TODOCHECKBOX /[\d\+/\d\+\]/ -syn match TODOINDEX /^\s\+\d\+\.\s/ -syn match TODOCHECKBOXPANDING /\s\+√\s\+/ -syn match TODOCHECKBOXDONE /\s\+□\s\+/ -syn match TODOCHECKBOXNOTE /\s\+·\s\+/ -syn match TODODUETIME /\d\+[d]$\|\d\+[d]\s\*$/ -hi def link FileName Comment -hi def link TODOTAG Todo -hi def link TODOQUESTION Question -hi def link TODOFIXME ErrorMsg +if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTodoManager' + finish +endif +let b:current_syntax = 'SpaceVimTodoManager' +syntax case ignore + +syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/ +syn match TODOTAG /^\s*@[a-zA-Z]*/ +syn match TODOQUESTION /^\s*@ques[a-z]*/ +syn match TODOFIXME /^\s*@fixm[a-z]*/ +" syn match TODOCHECKBOX /[\d\+/\d\+\]/ +syn match TODOINDEX /^\s\+\d\+\.\s/ +syn match TODOCHECKBOXPANDING /\s\+√\s\+/ +syn match TODOCHECKBOXDONE /\s\+□\s\+/ +syn match TODOCHECKBOXNOTE /\s\+·\s\+/ +syn match TODODUETIME /\d\+[d]$\|\d\+[d]\s\*$/ +hi def link FileName Comment +hi def link TODOTAG Todo +hi def link TODOQUESTION Question +hi def link TODOFIXME ErrorMsg +