diff --git a/.ci/detach_plugin.sh b/.ci/detach_plugin.sh index 0b755c186..e53557a1c 100755 --- a/.ci/detach_plugin.sh +++ b/.ci/detach_plugin.sh @@ -198,6 +198,7 @@ EOT _detect autoload/SpaceVim/api/data/string.vim _detect autoload/SpaceVim/api/file.vim _detect autoload/SpaceVim/api/vim/buffer.vim + _detect autoload/SpaceVim/api/vim/regex.vim _detect autoload/SpaceVim/api/vim/compatible.vim _detect autoload/SpaceVim/logger.vim _detect autoload/SpaceVim/mapping/search.vim diff --git a/autoload/SpaceVim/api/neovim/floating.vim b/autoload/SpaceVim/api/neovim/floating.vim index fab7ee842..dee45e79b 100644 --- a/autoload/SpaceVim/api/neovim/floating.vim +++ b/autoload/SpaceVim/api/neovim/floating.vim @@ -91,7 +91,7 @@ endfunction function! s:self.win_close(id, focuce) abort return nvim_win_close(a:id, a:focuce) - " @fixme: nvim_win_close only support one argv in old version + " @fixme nvim_win_close only support one argv in old version try return nvim_win_close(a:id, a:focuce) catch /^Vim\%((\a\+)\)\=:E118/ diff --git a/autoload/SpaceVim/api/vim/regex.vim b/autoload/SpaceVim/api/vim/regex.vim index 8984b37b7..d1c09e280 100644 --- a/autoload/SpaceVim/api/vim/regex.vim +++ b/autoload/SpaceVim/api/vim/regex.vim @@ -44,7 +44,15 @@ function! s:self.parser(regex, is_perl) abort " word boundary " \bword\b => - let vim_regex = substitute(vim_regex, '\\b\(\w\+\)\\b', '\\<\1\\>', 'g') + let vim_regex = substitute(vim_regex, '\\b\(\w\+\)\\b', '<\1>', 'g') + + " right word boundary + " \bword => \ word\> + let vim_regex = substitute(vim_regex, '\(\w\+\)\\b', '\1>', 'g') " case-insensitive " (?i)abc => \cabc diff --git a/autoload/SpaceVim/plugins/flygrep.vim b/autoload/SpaceVim/plugins/flygrep.vim index ab1dba3cb..922913c0e 100644 --- a/autoload/SpaceVim/plugins/flygrep.vim +++ b/autoload/SpaceVim/plugins/flygrep.vim @@ -913,7 +913,7 @@ endfunction " }}} function! s:update_statusline() abort - if !g:FlyGrep_enable_statusline + if !get(g:, 'FlyGrep_enable_statusline', 1) return endif diff --git a/autoload/SpaceVim/plugins/todo.vim b/autoload/SpaceVim/plugins/todo.vim index 2985c6b58..aeb019968 100644 --- a/autoload/SpaceVim/plugins/todo.vim +++ b/autoload/SpaceVim/plugins/todo.vim @@ -10,6 +10,7 @@ let s:JOB = SpaceVim#api#import('job') let s:BUFFER = SpaceVim#api#import('vim#buffer') let s:SYS = SpaceVim#api#import('system') let s:LOG = SpaceVim#logger#derive('todo') +let s:REG = SpaceVim#api#import('vim#regex') let [ @@ -65,10 +66,12 @@ function! s:update_todo_content() abort let s:todos = [] let s:todo = {} + let s:labels_regex = s:get_labels_regex() + let s:labels_partten = s:get_labels_pattern() let argv = [s:grep_default_exe] + \ s:grep_default_opt + \ s:grep_default_expr_opt - let argv += [s:get_labels_regex()] + let argv += [s:labels_regex] if s:SYS.isWindows && (s:grep_default_exe ==# 'rg' || s:grep_default_exe ==# 'ag' || s:grep_default_exe ==# 'pt' ) let argv += ['.'] elseif s:SYS.isWindows && s:grep_default_exe ==# 'findstr' @@ -76,24 +79,27 @@ function! s:update_todo_content() abort endif let argv += s:grep_default_ropt call s:LOG.info('cmd: ' . string(argv)) - let jobid = s:JOB.start(argv, { + call s:LOG.info(' labels_partten: ' . s:labels_partten) + let s:todo_jobid = s:JOB.start(argv, { \ 'on_stdout' : function('s:stdout'), \ 'on_stderr' : function('s:stderr'), \ 'on_exit' : function('s:exit'), \ }) - call s:LOG.info('jobid: ' . string(jobid)) + call s:LOG.info('jobid: ' . string(s:todo_jobid)) endfunction function! s:stdout(id, data, event) abort + if a:id !=# s:todo_jobid + return + endif for data in a:data call s:LOG.info('stdout: ' . 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 full_label = matchstr(data, s:get_labels_pattern()) - let trimmed_label = substitute(full_label, '\W', '', 'g') - let title = get(split(data, full_label), 1, '') + let label = matchstr(data, s:labels_partten) + let title = get(split(data, label), 1, '') " @todo add time tag call add(s:todos, \ { @@ -101,7 +107,7 @@ function! s:stdout(id, data, event) abort \ 'line' : line, \ 'column' : column, \ 'title' : title, - \ 'label' : trimmed_label, + \ 'label' : label, \ } \ ) endif @@ -109,21 +115,28 @@ function! s:stdout(id, data, event) abort endfunction function! s:stderr(id, data, event) abort + if a:id !=# s:todo_jobid + return + endif for date in a:data call s:LOG.info('stderr: ' . string(a:data)) endfor endfunction function! s:exit(id, data, event ) abort - call s:LOG.info('exit code: ' . string(a:data)) + if a:id !=# s:todo_jobid + return + endif + call s:LOG.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.label)')) let file_w = max(map(deepcopy(s:todos), 'strlen(v:val.file)')) - let expr = "tolower(v:val.label) . repeat(' ', label_w - strlen(v:val.label)) . ' ' ." + let expr = "v:val.label . repeat(' ', label_w - strlen(v:val.label)) . ' ' ." \ . "SpaceVim#api#import('file').unify_path(v:val.file, ':.') . repeat(' ', file_w - strlen(v:val.file)) . ' ' ." - \ . 'v:val.title' + \ . "v:val.title" let lines = map(deepcopy(s:todos),expr) call s:BUFFER.buf_set_lines(s:bufnr, 0 , -1, 0, lines) + let g:wsd = s:todos endfunction function! s:compare_todo(a, b) abort @@ -159,13 +172,12 @@ function! s:get_labels_regex() let separator = '|' endif - return join(map(copy(s:labels), - \ "(v:val[0] =~ '\w' ? '\\b' : '') . v:val . '\\b:?'"), + return join(map(copy(s:labels), "v:val . '\\b'"), \ separator) endfunc -function! s:get_labels_pattern () - return '\C' . join(map(copy(s:labels), "(v:val[0] =~ '\w' ? '\\<' : '') . v:val . '\\>:\\?'"), '\|') +function! s:get_labels_pattern() + return s:REG.parser(s:get_labels_regex(), 0) endfunc diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index e31c85741..caba54413 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -1242,17 +1242,7 @@ Config the command line prompt for flygrep and denite etc. *g:spacevim_todo_labels* Option for setting todo labels in current project. -By default, it matches "@todo", "@question", "@fixme" and "@idea". -The following configuration will match todos in the form "TODO", "FIXME" and -"XXX". -> - let g:spacevim_todo_labels = [ - \ 'FIXME', - \ 'TODO', - \ 'XXX', - \ ] -< *g:spacevim_lint_on_the_fly* Enable/Disable lint on the fly feature of SpaceVim's maker. Default is 0. > diff --git a/syntax/SpaceVimTasksInfo.vim b/syntax/SpaceVimTasksInfo.vim index 3b536c692..865518ad4 100644 --- a/syntax/SpaceVimTasksInfo.vim +++ b/syntax/SpaceVimTasksInfo.vim @@ -1,25 +1,25 @@ -if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTasksInfo' - finish -endif -let b:current_syntax = 'SpaceVimTasksInfo' -syntax case ignore - -syn match TaskName /^\[.*\]/ -syn match TaskTitle /^Task\s\+Type\s\+Command/ - -" @question Why \zs does not work in syntax file? -" ref: -" https://github.com/vim/vim/issues/598 -" https://stackoverflow.com/questions/49323753/vim-syntax-file-not-matching-with-zs -" https://stackoverflow.com/questions/64153655/why-taskinfo-syntax-file-does-not-work-as-expect -" syn match TaskType /^\[.*\]\s*\zs[a-z]*/ -" syn match TaskDescription /^\[.*\]\s*[a-z]*\s\+\zs.*/ - -syn match TaskType /\(^\[.\+\]\s\+\)\@<=[a-z]*/ -syn match TaskDescription /\(^\[.*\]\s\+[a-z]\+\s\+\)\@<=.*/ -hi def link TaskTitle Title -hi def link TaskName String -hi def link TaskType Todo -hi def link TaskDescription Comment - - +if exists('b:current_syntax') && b:current_syntax ==# 'SpaceVimTasksInfo' + finish +endif +let b:current_syntax = 'SpaceVimTasksInfo' +syntax case ignore + +syn match TaskName /^\[.*\]/ +syn match TaskTitle /^Task\s\+Type\s\+Command/ + +" @question Why \zs does not work in syntax file? +" ref: +" https://github.com/vim/vim/issues/598 +" https://stackoverflow.com/questions/49323753/vim-syntax-file-not-matching-with-zs +" https://stackoverflow.com/questions/64153655/why-taskinfo-syntax-file-does-not-work-as-expect +" syn match TaskType /^\[.*\]\s*\zs[a-z]*/ +" syn match TaskDescription /^\[.*\]\s*[a-z]*\s\+\zs.*/ + +syn match TaskType /\(^\[.\+\]\s\+\)\@<=[a-z]*/ +syn match TaskDescription /\(^\[.*\]\s\+[a-z]\+\s\+\)\@<=.*/ +hi def link TaskTitle Title +hi def link TaskName String +hi def link TaskType Todo +hi def link TaskDescription Comment + + diff --git a/syntax/SpaceVimTodoManager.vim b/syntax/SpaceVimTodoManager.vim index 96d54b405..3805a608c 100644 --- a/syntax/SpaceVimTodoManager.vim +++ b/syntax/SpaceVimTodoManager.vim @@ -4,12 +4,10 @@ endif let b:current_syntax = 'SpaceVimTodoManager' syntax case ignore -syn match FileName /\(^\S\+\s\+\)\@<=[^ ]*/ +syn match FileName /\(@[a-zA-Z]*\s\+\)\@<=[^ ]*/ syn match TODOTAG /^\s*@[a-zA-Z]*/ -syn match TODOTAG /^\s*@\?todo*/ syn match TODOQUESTION /^\s*@ques[a-z]*/ -syn match TODOFIXME /^\s*@\?fixm[a-z]*/ -syn match TODOFIXME /^\s*@\?xxx*/ +syn match TODOFIXME /^\s*@fixm[a-z]*/ " syn match TODOCHECKBOX /[\d\+/\d\+\]/ syn match TODOINDEX /^\s\+\d\+\.\s/ syn match TODOCHECKBOXPANDING /\s\+√\s\+/ @@ -20,4 +18,3 @@ hi def link FileName Comment hi def link TODOTAG Todo hi def link TODOQUESTION Question hi def link TODOFIXME ErrorMsg - diff --git a/test/api/vim/regex.vader b/test/api/vim/regex.vader index 057c50651..49caba24d 100644 --- a/test/api/vim/regex.vader +++ b/test/api/vim/regex.vader @@ -5,7 +5,9 @@ Execute ( SpaceVim api: vim#key ): AssertEqual regex.parser('(?:exp)', 0), '\v%(exp)' AssertEqual regex.parser('\a\f\v', 0), '\v%x07%x0C%x0B' AssertEqual regex.parser('[:word:]', 0), '\v[0-9A-Za-z_]' - AssertEqual regex.parser('\bspace\b', 0), '\v\' + AssertEqual regex.parser('\bspace\b', 0), '\v' + AssertEqual regex.parser('\bspace', 0), '\v' AssertEqual regex.parser('if%@&ab', 0), '\vif\%\@\&ab' AssertEqual regex.parser('(?Pexp)', 0), '\v(exp)'