mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 10:30:05 +08:00
Detech todo (#2943)
This commit is contained in:
parent
a446220add
commit
c903e32d79
@ -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 <buffer><silent> <Enter> :call <SID>open_todo()<cr>
|
|
||||||
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.
|
|
@ -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', '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', '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', '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/
|
" after run make test, the vader will be downloaded to ./build/vader/
|
||||||
|
|
||||||
|
@ -75,6 +75,27 @@ main () {
|
|||||||
rm -rf detach/$1
|
rm -rf detach/$1
|
||||||
exit 0
|
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)
|
spacevim-theme)
|
||||||
exit 0
|
exit 0
|
||||||
esac
|
esac
|
||||||
|
@ -515,7 +515,7 @@ function! SpaceVim#mapping#space#init() abort
|
|||||||
call SpaceVim#mapping#space#def('nnoremap', ['h', 'd', 'k'],
|
call SpaceVim#mapping#space#def('nnoremap', ['h', 'd', 'k'],
|
||||||
\ 'call SpaceVim#plugins#help#describe_key()',
|
\ 'call SpaceVim#plugins#help#describe_key()',
|
||||||
\ 'describe key bindings', 1)
|
\ 'describe key bindings', 1)
|
||||||
|
call SpaceVim#custom#SPC('nnoremap', ['a', 'o'], 'call SpaceVim#plugins#todo#list()', 'Open todo manager', 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort
|
function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort
|
||||||
|
109
autoload/SpaceVim/plugins/todo.vim
Normal file
109
autoload/SpaceVim/plugins/todo.vim
Normal file
@ -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 <buffer><silent> <Enter> :call <SID>open_todo()<cr>
|
||||||
|
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.
|
||||||
|
|
@ -1,20 +1,21 @@
|
|||||||
if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTodoManager'
|
if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTodoManager'
|
||||||
finish
|
finish
|
||||||
endif
|
endif
|
||||||
let b:current_syntax = 'SpaceVimTodoManager'
|
let b:current_syntax = 'SpaceVimTodoManager'
|
||||||
syntax case ignore
|
syntax case ignore
|
||||||
|
|
||||||
syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/
|
syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/
|
||||||
syn match TODOTAG /^\s*@[a-zA-Z]*/
|
syn match TODOTAG /^\s*@[a-zA-Z]*/
|
||||||
syn match TODOQUESTION /^\s*@ques[a-z]*/
|
syn match TODOQUESTION /^\s*@ques[a-z]*/
|
||||||
syn match TODOFIXME /^\s*@fixm[a-z]*/
|
syn match TODOFIXME /^\s*@fixm[a-z]*/
|
||||||
" syn match TODOCHECKBOX /[\d\+/\d\+\]/
|
" syn match TODOCHECKBOX /[\d\+/\d\+\]/
|
||||||
syn match TODOINDEX /^\s\+\d\+\.\s/
|
syn match TODOINDEX /^\s\+\d\+\.\s/
|
||||||
syn match TODOCHECKBOXPANDING /\s\+√\s\+/
|
syn match TODOCHECKBOXPANDING /\s\+√\s\+/
|
||||||
syn match TODOCHECKBOXDONE /\s\+□\s\+/
|
syn match TODOCHECKBOXDONE /\s\+□\s\+/
|
||||||
syn match TODOCHECKBOXNOTE /\s\+·\s\+/
|
syn match TODOCHECKBOXNOTE /\s\+·\s\+/
|
||||||
syn match TODODUETIME /\d\+[d]$\|\d\+[d]\s\*$/
|
syn match TODODUETIME /\d\+[d]$\|\d\+[d]\s\*$/
|
||||||
hi def link FileName Comment
|
hi def link FileName Comment
|
||||||
hi def link TODOTAG Todo
|
hi def link TODOTAG Todo
|
||||||
hi def link TODOQUESTION Question
|
hi def link TODOQUESTION Question
|
||||||
hi def link TODOFIXME ErrorMsg
|
hi def link TODOFIXME ErrorMsg
|
||||||
|
|
Loading…
Reference in New Issue
Block a user