From 5f0781f6f09af63e30dcf40cbd8ea146503628f3 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 31 May 2011 13:38:17 +0900 Subject: [PATCH 01/21] - Improved caching routine. --- autoload/unite/sources/help.vim | 82 ++++++++++++++++----------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 55bc2a5..01c8d03 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,7 +1,8 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 15 Nov 2010 +" Last Change: 31 May 2011. " Author: tsukkee +" Modified: Shougo " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy " of this software and associated documentation files (the "Software"), to deal @@ -32,18 +33,44 @@ endfunction let s:cache = [] function! unite#sources#help#refresh() let s:cache = [] + + for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") + if !filereadable(tagfile) | continue | endif + + let lang = matchstr(tagfile, 'tags-\zs[a-z]\{2\}') + let place = fnamemodify(expand(tagfile), ':p:h:h:t') + + for line in readfile(tagfile) + let name = split(line, "\t")[0] + let word = name . '@' . (!empty(lang) ? lang : 'en') + let abbr = printf( + \ "%s%s (in %s)", name, !empty(lang) ? '@' . lang : '', place) + + " if not comment line + if stridx(name, "!") != 0 + call add(s:cache, { + \ 'word': word, + \ 'abbr': abbr, + \ 'kind': 'common', + \ 'source': 'help', + \ 'action__command': 'help ' . word, + \ 'source__lang' : !empty(lang) ? lang : 'en' + \}) + endif + endfor + endfor endfunction " source let s:source = { -\ 'name': 'help', -\ 'max_candidates': 50, -\ 'required_pattern_length': 1, -\ 'action_table': {}, -\ 'default_action': {'common': 'execute'} -\} + \ 'name': 'help', + \ 'max_candidates': 50, + \ 'required_pattern_length': 1, + \ 'action_table': {}, + \ 'default_action': {'common': 'execute'} + \} function! s:source.gather_candidates(args, context) - let should_refresh = a:context.is_redraw + let should_refresh = a:context.is_force || empty(s:cache) let lang_filter = [] for arg in a:args if arg == '!' @@ -59,36 +86,8 @@ function! s:source.gather_candidates(args, context) call unite#sources#help#refresh() endif - if empty(s:cache) - for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") - if !filereadable(tagfile) | continue | endif - - let lang = matchstr(tagfile, 'tags-\zs[a-z]\{2\}') - let place = fnamemodify(expand(tagfile), ':p:h:h:t') - - for line in readfile(tagfile) - let name = split(line, "\t")[0] - let word = name . '@' . (!empty(lang) ? lang : 'en') - let abbr = printf( - \ "%s%s (in %s)", name, !empty(lang) ? '@' . lang : '', place) - - " if not comment line - if stridx(name, "!") != 0 - call add(s:cache, { - \ 'word': word, - \ 'abbr': abbr, - \ 'kind': 'common', - \ 'source': 'help', - \ 'action__command': 'help ' . word, - \ 'source__lang' : !empty(lang) ? lang : 'en' - \}) - endif - endfor - endfor - endif - return filter(copy(s:cache), - \ 'empty(lang_filter) || index(lang_filter, v:val.source__lang) != -1') + \ 'empty(lang_filter) || index(lang_filter, v:val.source__lang) != -1') endfunction @@ -96,8 +95,8 @@ endfunction let s:action_table = {} let s:action_table.execute = { -\ 'description': 'lookup help' -\} + \ 'description': 'lookup help' + \} function! s:action_table.execute.func(candidate) let save_ignorecase = &ignorecase set noignorecase @@ -106,8 +105,8 @@ function! s:action_table.execute.func(candidate) endfunction let s:action_table.tabopen = { -\ 'description': 'open help in a new tab' -\} + \ 'description': 'open help in a new tab' + \} function! s:action_table.tabopen.func(candidate) let save_ignorecase = &ignorecase set noignorecase @@ -117,3 +116,4 @@ endfunction let s:source.action_table.common = s:action_table +" vim: shiftwidth=4 softtabstop=4 From a257a5ba3109c144f82eb43c99b89f44b8e5bff0 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 1 Jun 2011 15:00:06 +0900 Subject: [PATCH 02/21] - Fixed error. --- autoload/unite/sources/help.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 01c8d03..017949b 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 31 May 2011. +" Last Change: 01 Jun 2011. " Author: tsukkee " Modified: Shougo " Licence: The MIT License {{{ @@ -70,7 +70,7 @@ let s:source = { \ 'default_action': {'common': 'execute'} \} function! s:source.gather_candidates(args, context) - let should_refresh = a:context.is_force || empty(s:cache) + let should_refresh = a:context.is_redraw || empty(s:cache) let lang_filter = [] for arg in a:args if arg == '!' From 60e9d4be259ff978c90029d2bf7ae8bcdac9511c Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 25 Jun 2011 23:48:55 +0900 Subject: [PATCH 03/21] - Supported asynchronous. --- autoload/unite/sources/help.vim | 83 ++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 55bc2a5..e54c0ec 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 15 Nov 2010 +" Last Change: 25 Jun 2011. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,7 +24,7 @@ " define source function! unite#sources#help#define() - return s:source + return unite#util#has_vimproc() ? s:source : {} endfunction @@ -33,14 +33,14 @@ let s:cache = [] function! unite#sources#help#refresh() let s:cache = [] endfunction +let s:vimproc_files = {} " source let s:source = { \ 'name': 'help', \ 'max_candidates': 50, -\ 'required_pattern_length': 1, \ 'action_table': {}, -\ 'default_action': {'common': 'execute'} +\ 'default_action': { '*': 'execute' } \} function! s:source.gather_candidates(args, context) let should_refresh = a:context.is_redraw @@ -60,35 +60,65 @@ function! s:source.gather_candidates(args, context) endif if empty(s:cache) + " load files. + let s:vimproc_files = {} for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") if !filereadable(tagfile) | continue | endif - let lang = matchstr(tagfile, 'tags-\zs[a-z]\{2\}') - let place = fnamemodify(expand(tagfile), ':p:h:h:t') - - for line in readfile(tagfile) - let name = split(line, "\t")[0] - let word = name . '@' . (!empty(lang) ? lang : 'en') - let abbr = printf( - \ "%s%s (in %s)", name, !empty(lang) ? '@' . lang : '', place) - - " if not comment line - if stridx(name, "!") != 0 - call add(s:cache, { - \ 'word': word, - \ 'abbr': abbr, - \ 'kind': 'common', - \ 'source': 'help', - \ 'action__command': 'help ' . word, - \ 'source__lang' : !empty(lang) ? lang : 'en' - \}) - endif - endfor + let file = { + \ 'proc' : vimproc#fopen(tagfile, 'r'), + \ 'lang' : matchstr(tagfile, 'tags-\zs[a-z]\{2\}'), + \ 'path': fnamemodify(expand(tagfile), ':p:h:h:t'), + \ } + let s:vimproc_files[tagfile] = file endfor endif + let a:context.source__lang_filter = lang_filter return filter(copy(s:cache), - \ 'empty(lang_filter) || index(lang_filter, v:val.source__lang) != -1') + \ 'empty(a:context.source__lang_filter) || index(a:context.source__lang_filter, v:val.source__lang) != -1') +endfunction +function! s:source.async_gather_candidates(args, context) + let list = [] + let cnt = 0 + for [key, file] in items(s:vimproc_files) + while !file.proc.eof + let line = file.proc.read_line() + if line == '' || line[0] == '!' + continue + endif + + let name = split(line, "\t")[0] + let word = name . '@' . (file.lang != '' ? file.lang : 'en') + let abbr = printf("%s%s (in %s)", + \ name, ((file.lang != '') ? '@' . file.lang : ''), file.path) + + call add(list, { + \ 'word': word, + \ 'abbr': abbr, + \ 'action__command': 'help ' . word, + \ 'source__lang' : file.lang != '' ? file.lang : 'en' + \}) + + let cnt += 1 + if cnt > 400 + break + endif + endwhile + + if file.proc.eof + call remove(s:vimproc_files, key) + endif + endfor + + if empty(s:vimproc_files) + let a:context.is_async = 0 + call unite#print_message('[help] Completed.') + endif + let s:cache += list + + return filter(list, + \ 'empty(a:context.source__lang_filter) || index(a:context.source__lang_filter, v:val.source__lang) != -1') endfunction @@ -117,3 +147,4 @@ endfunction let s:source.action_table.common = s:action_table +" vim: expandtab:ts=4:sts=4:sw=4 From 9ab32d2ee59a4f492a5d96fbec53059c50f4d0a2 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 26 Jun 2011 13:43:24 +0900 Subject: [PATCH 04/21] - Optimized. --- autoload/unite/sources/help.vim | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index e54c0ec..b1c07c2 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 25 Jun 2011. +" Last Change: 26 Jun 2011. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -75,8 +75,13 @@ function! s:source.gather_candidates(args, context) endif let a:context.source__lang_filter = lang_filter - return filter(copy(s:cache), - \ 'empty(a:context.source__lang_filter) || index(a:context.source__lang_filter, v:val.source__lang) != -1') + let list = copy(s:cache) + if !empty(a:context.source__lang_filter) + call filter(list, 'empty(a:context.source__lang_filter) + \ || index(a:context.source__lang_filter, v:val.source__lang) != -1') + endif + + return list endfunction function! s:source.async_gather_candidates(args, context) let list = [] @@ -117,8 +122,13 @@ function! s:source.async_gather_candidates(args, context) endif let s:cache += list - return filter(list, - \ 'empty(a:context.source__lang_filter) || index(a:context.source__lang_filter, v:val.source__lang) != -1') + if !empty(a:context.source__lang_filter) + call filter(list, + \ 'empty(a:context.source__lang_filter) + \ || index(a:context.source__lang_filter, v:val.source__lang) != -1') + endif + + return list endfunction From 055e29c51d62ded9e18e7d38547616e56f5295c6 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 3 Jul 2011 14:18:22 +0900 Subject: [PATCH 05/21] - Fixed for vimproc#open(). --- autoload/unite/sources/help.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index b1c07c2..a6ce3e2 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 26 Jun 2011. +" Last Change: 03 Jul 2011. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -66,7 +66,7 @@ function! s:source.gather_candidates(args, context) if !filereadable(tagfile) | continue | endif let file = { - \ 'proc' : vimproc#fopen(tagfile, 'r'), + \ 'proc' : vimproc#fopen(tagfile, 'O_RDONLY'), \ 'lang' : matchstr(tagfile, 'tags-\zs[a-z]\{2\}'), \ 'path': fnamemodify(expand(tagfile), ':p:h:h:t'), \ } From 3c1f8deb720f4c5a7724d6839a052157f31454b1 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 17 Jul 2011 10:57:47 +0900 Subject: [PATCH 06/21] Use new vimproc function. --- autoload/unite/sources/help.vim | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index a6ce3e2..d817a76 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 03 Jul 2011. +" Last Change: 17 Jul 2011. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -40,6 +40,7 @@ let s:source = { \ 'name': 'help', \ 'max_candidates': 50, \ 'action_table': {}, +\ 'hooks': {}, \ 'default_action': { '*': 'execute' } \} function! s:source.gather_candidates(args, context) @@ -85,10 +86,10 @@ function! s:source.gather_candidates(args, context) endfunction function! s:source.async_gather_candidates(args, context) let list = [] - let cnt = 0 for [key, file] in items(s:vimproc_files) - while !file.proc.eof - let line = file.proc.read_line() + let lines = file.proc.read_lines(2048, 500) + " echomsg string([file.path, len(lines)]) + for line in lines if line == '' || line[0] == '!' continue endif @@ -104,14 +105,10 @@ function! s:source.async_gather_candidates(args, context) \ 'action__command': 'help ' . word, \ 'source__lang' : file.lang != '' ? file.lang : 'en' \}) - - let cnt += 1 - if cnt > 400 - break - endif - endwhile + endfor if file.proc.eof + call file.proc.close() call remove(s:vimproc_files, key) endif endfor @@ -130,7 +127,11 @@ function! s:source.async_gather_candidates(args, context) return list endfunction - +function! s:source.hooks.on_close(args, context) + for file in values(s:vimproc_files) + call file.proc.close() + endfor +endfunction " action let s:action_table = {} From 4004abd0bab40eb5f11ca4924429139c3c2944ec Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sun, 17 Jul 2011 19:14:51 +0900 Subject: [PATCH 07/21] - Fixed a bit. --- autoload/unite/sources/help.vim | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index d817a76..2268859 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -87,7 +87,7 @@ endfunction function! s:source.async_gather_candidates(args, context) let list = [] for [key, file] in items(s:vimproc_files) - let lines = file.proc.read_lines(2048, 500) + let lines = file.proc.read_lines(300, 500) " echomsg string([file.path, len(lines)]) for line in lines if line == '' || line[0] == '!' @@ -128,9 +128,6 @@ function! s:source.async_gather_candidates(args, context) return list endfunction function! s:source.hooks.on_close(args, context) - for file in values(s:vimproc_files) - call file.proc.close() - endfor endfunction " action From 350e91902ae43bab5fc4f2da91e54c72b5da4a7d Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Mon, 1 Oct 2012 22:27:11 +0900 Subject: [PATCH 08/21] - Added progress. --- autoload/unite/sources/help.vim | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 2268859..a0f950d 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 17 Jul 2011. +" Last Change: 01 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -70,16 +70,22 @@ function! s:source.gather_candidates(args, context) \ 'proc' : vimproc#fopen(tagfile, 'O_RDONLY'), \ 'lang' : matchstr(tagfile, 'tags-\zs[a-z]\{2\}'), \ 'path': fnamemodify(expand(tagfile), ':p:h:h:t'), + \ 'max' : len(readfile(tagfile)), + \ 'lnum' : 0, \ } let s:vimproc_files[tagfile] = file endfor + + let a:context.source__cont_number = 0 + let a:context.source__cont_max = len(s:vimproc_files) endif let a:context.source__lang_filter = lang_filter let list = copy(s:cache) if !empty(a:context.source__lang_filter) call filter(list, 'empty(a:context.source__lang_filter) - \ || index(a:context.source__lang_filter, v:val.source__lang) != -1') + \ || index(a:context.source__lang_filter, + \ v:val.source__lang) != -1') endif return list @@ -87,8 +93,23 @@ endfunction function! s:source.async_gather_candidates(args, context) let list = [] for [key, file] in items(s:vimproc_files) - let lines = file.proc.read_lines(300, 500) - " echomsg string([file.path, len(lines)]) + let lines = file.proc.read_lines(1000, 2000) + + " Show progress. + let file.lnum += len(lines) + let progress = (file.lnum * 100) / file.max + if progress > 100 + let progress = 100 + endif + + call unite#clear_message() + + call unite#print_message( + \ printf('[help] [%2d/%2d] Making cache of "%s"...%d%%', + \ a:context.source__cont_number, + \ a:context.source__cont_max, + \ file.path, progress)) + for line in lines if line == '' || line[0] == '!' continue @@ -110,6 +131,7 @@ function! s:source.async_gather_candidates(args, context) if file.proc.eof call file.proc.close() call remove(s:vimproc_files, key) + let a:context.source__cont_number += 1 endif endfor From e1cf48b9ab4ef293d05247c5861fc3c4bb5c106b Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 2 Oct 2012 11:13:51 +0900 Subject: [PATCH 09/21] - Improved cache behavior. --- autoload/unite/sources/help.vim | 95 +++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index a0f950d..89b27e0 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 01 Oct 2012. +" Last Change: 02 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,11 +27,18 @@ function! unite#sources#help#define() return unite#util#has_vimproc() ? s:source : {} endfunction +let s:Cache = vital#of('unite.vim').import('System.Cache') " cache let s:cache = [] function! unite#sources#help#refresh() let s:cache = [] + + let cache_dir = g:unite_data_directory . '/help' + if s:Cache.filereadable(cache_dir, 'help-cache') + " Delete cache file. + call s:Cache.delete(cache_dir, 'help-cache') + endif endfunction let s:vimproc_files = {} @@ -41,10 +48,10 @@ let s:source = { \ 'max_candidates': 50, \ 'action_table': {}, \ 'hooks': {}, -\ 'default_action': { '*': 'execute' } +\ 'default_action': 'execute', +\ 'filters' : ['matcher_default', 'sorter_word', 'converter_default'], \} -function! s:source.gather_candidates(args, context) - let should_refresh = a:context.is_redraw +function! s:source.hooks.on_init(args, context) let lang_filter = [] for arg in a:args if arg == '!' @@ -56,39 +63,55 @@ function! s:source.gather_candidates(args, context) endif endfor + let a:context.source__lang_filter = lang_filter +endfunction +function! s:source.gather_candidates(args, context) + let should_refresh = a:context.is_redraw + if should_refresh call unite#sources#help#refresh() + let a:context.is_async = 1 endif - if empty(s:cache) - " load files. - let s:vimproc_files = {} - for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") - if !filereadable(tagfile) | continue | endif - - let file = { - \ 'proc' : vimproc#fopen(tagfile, 'O_RDONLY'), - \ 'lang' : matchstr(tagfile, 'tags-\zs[a-z]\{2\}'), - \ 'path': fnamemodify(expand(tagfile), ':p:h:h:t'), - \ 'max' : len(readfile(tagfile)), - \ 'lnum' : 0, - \ } - let s:vimproc_files[tagfile] = file - endfor + let cache_dir = g:unite_data_directory . '/help' + if s:Cache.filereadable(cache_dir, 'help-cache') + " Use cache file. + let s:cache = eval(get(s:Cache.readfile( + \ cache_dir, 'help-cache'), 0, '[]')) - let a:context.source__cont_number = 0 - let a:context.source__cont_max = len(s:vimproc_files) + let a:context.is_async = 0 + call unite#print_message('[help] Completed.') endif - let a:context.source__lang_filter = lang_filter - let list = copy(s:cache) - if !empty(a:context.source__lang_filter) - call filter(list, 'empty(a:context.source__lang_filter) - \ || index(a:context.source__lang_filter, - \ v:val.source__lang) != -1') + if !empty(s:cache) + let list = copy(s:cache) + if !empty(a:context.source__lang_filter) + call filter(list, 'index(a:context.source__lang_filter, + \ v:val.source__lang) != -1') + endif + + return list endif - return list + " load files. + let s:vimproc_files = {} + for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") + if !filereadable(tagfile) | continue | endif + + let file = { + \ 'proc' : vimproc#fopen(tagfile, 'O_RDONLY'), + \ 'lang' : matchstr(tagfile, 'tags-\zs[a-z]\{2\}'), + \ 'path': fnamemodify(expand(tagfile), ':p:h:h:t'), + \ 'max' : len(readfile(tagfile)), + \ 'lnum' : 0, + \ } + let s:vimproc_files[tagfile] = file + endfor + + let a:context.source__cont_number = 1 + let a:context.source__cont_max = len(s:vimproc_files) + + return [] endfunction function! s:source.async_gather_candidates(args, context) let list = [] @@ -135,16 +158,20 @@ function! s:source.async_gather_candidates(args, context) endif endfor + if !empty(a:context.source__lang_filter) + call filter(list, 'index(a:context.source__lang_filter, + \ v:val.source__lang) != -1') + endif + + let s:cache += list if empty(s:vimproc_files) let a:context.is_async = 0 call unite#print_message('[help] Completed.') - endif - let s:cache += list - if !empty(a:context.source__lang_filter) - call filter(list, - \ 'empty(a:context.source__lang_filter) - \ || index(a:context.source__lang_filter, v:val.source__lang) != -1') + " Save cache file. + let cache_dir = g:unite_data_directory . '/help' + call s:Cache.writefile(cache_dir, 'help-cache', + \ [string(s:cache)]) endif return list From 42f4f8b4c63ffd89cedee133a36f31807fbcb433 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 2 Oct 2012 14:49:56 +0900 Subject: [PATCH 10/21] - Improved filter. --- autoload/unite/sources/help.vim | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 89b27e0..4cec602 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -64,6 +64,12 @@ function! s:source.hooks.on_init(args, context) endfor let a:context.source__lang_filter = lang_filter + + let a:context.source__input = a:context.input + if a:context.source__input == '' + let a:context.source__input = + \ input('Please input search word: ', '', 'help') + endif endfunction function! s:source.gather_candidates(args, context) let should_refresh = a:context.is_redraw @@ -85,12 +91,8 @@ function! s:source.gather_candidates(args, context) if !empty(s:cache) let list = copy(s:cache) - if !empty(a:context.source__lang_filter) - call filter(list, 'index(a:context.source__lang_filter, - \ v:val.source__lang) != -1') - endif - return list + return s:filter_list(list) endif " load files. @@ -158,10 +160,7 @@ function! s:source.async_gather_candidates(args, context) endif endfor - if !empty(a:context.source__lang_filter) - call filter(list, 'index(a:context.source__lang_filter, - \ v:val.source__lang) != -1') - endif + call s:filter_list(list) let s:cache += list if empty(s:vimproc_files) @@ -179,6 +178,16 @@ endfunction function! s:source.hooks.on_close(args, context) endfunction +function! s:filter_list(list) + call filter(a:list, 'stridx(v:val.word, a:context.source__input) >= 0') + if !empty(a:context.source__lang_filter) + call filter(a:list, 'index(a:context.source__lang_filter, + \ v:val.source__lang) != -1') + endif + + return a:list +endfunction + " action let s:action_table = {} From eb41ae187eeb2eec26627a1c3e3548ada3fd9c56 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 2 Oct 2012 18:15:39 +0900 Subject: [PATCH 11/21] - Fixed s:filter_list(). --- autoload/unite/sources/help.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 4cec602..c21f8b9 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -92,7 +92,7 @@ function! s:source.gather_candidates(args, context) if !empty(s:cache) let list = copy(s:cache) - return s:filter_list(list) + return s:filter_list(list, a:context) endif " load files. @@ -160,7 +160,7 @@ function! s:source.async_gather_candidates(args, context) endif endfor - call s:filter_list(list) + call s:filter_list(list, a:context) let s:cache += list if empty(s:vimproc_files) @@ -178,7 +178,7 @@ endfunction function! s:source.hooks.on_close(args, context) endfunction -function! s:filter_list(list) +function! s:filter_list(list, context) call filter(a:list, 'stridx(v:val.word, a:context.source__input) >= 0') if !empty(a:context.source__lang_filter) call filter(a:list, 'index(a:context.source__lang_filter, From 6558df7d4a7eba5336b767566336b20a12ab7c04 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Wed, 3 Oct 2012 18:32:06 +0900 Subject: [PATCH 12/21] - Improved messages. --- autoload/unite/sources/help.vim | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index c21f8b9..ae78f37 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 02 Oct 2012. +" Last Change: 03 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -70,6 +70,9 @@ function! s:source.hooks.on_init(args, context) let a:context.source__input = \ input('Please input search word: ', '', 'help') endif + + call unite#print_source_message('Search word: ' + \ . a:context.source__input, s:source.name) endfunction function! s:source.gather_candidates(args, context) let should_refresh = a:context.is_redraw @@ -86,7 +89,7 @@ function! s:source.gather_candidates(args, context) \ cache_dir, 'help-cache'), 0, '[]')) let a:context.is_async = 0 - call unite#print_message('[help] Completed.') + call unite#print_source_message('Completed.', s:source.name) endif if !empty(s:cache) @@ -129,11 +132,11 @@ function! s:source.async_gather_candidates(args, context) call unite#clear_message() - call unite#print_message( - \ printf('[help] [%2d/%2d] Making cache of "%s"...%d%%', + call unite#print_source_message( + \ printf('[%2d/%2d] Making cache of "%s"...%d%%', \ a:context.source__cont_number, \ a:context.source__cont_max, - \ file.path, progress)) + \ file.path, progress), s:source.name) for line in lines if line == '' || line[0] == '!' @@ -165,7 +168,7 @@ function! s:source.async_gather_candidates(args, context) let s:cache += list if empty(s:vimproc_files) let a:context.is_async = 0 - call unite#print_message('[help] Completed.') + call unite#print_source_message('Completed.', source.name) " Save cache file. let cache_dir = g:unite_data_directory . '/help' From d91c45ea627a9e59d145b49015bac18c1970b556 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 5 Oct 2012 11:15:32 +0900 Subject: [PATCH 13/21] - Fixed error. --- autoload/unite/sources/help.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index ae78f37..be91026 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 03 Oct 2012. +" Last Change: 05 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -168,7 +168,7 @@ function! s:source.async_gather_candidates(args, context) let s:cache += list if empty(s:vimproc_files) let a:context.is_async = 0 - call unite#print_source_message('Completed.', source.name) + call unite#print_source_message('Completed.', s:source.name) " Save cache file. let cache_dir = g:unite_data_directory . '/help' From 1595b38d4a5087f85cfcda6fbbfd57e751f6b297 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 6 Oct 2012 16:06:46 +0900 Subject: [PATCH 14/21] - Fixed filter(). --- autoload/unite/sources/help.vim | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index be91026..4bc4fe8 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 05 Oct 2012. +" Last Change: 06 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -163,8 +163,6 @@ function! s:source.async_gather_candidates(args, context) endif endfor - call s:filter_list(list, a:context) - let s:cache += list if empty(s:vimproc_files) let a:context.is_async = 0 @@ -176,7 +174,7 @@ function! s:source.async_gather_candidates(args, context) \ [string(s:cache)]) endif - return list + return s:filter_list(list, a:context) endfunction function! s:source.hooks.on_close(args, context) endfunction From c78c8b44b64c7ec8b89c266f26ab64d53d06f964 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 16 Oct 2012 11:07:55 +0900 Subject: [PATCH 15/21] - Use unite#util#input(). --- autoload/unite/sources/help.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 4bc4fe8..5c35d7e 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 06 Oct 2012. +" Last Change: 16 Oct 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -68,7 +68,7 @@ function! s:source.hooks.on_init(args, context) let a:context.source__input = a:context.input if a:context.source__input == '' let a:context.source__input = - \ input('Please input search word: ', '', 'help') + \ unite#util#input('Please input search word: ', '', 'help') endif call unite#print_source_message('Search word: ' From 34a36332d737b1d2d73910731ecef22a32814fb8 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Thu, 13 Dec 2012 17:26:19 +0900 Subject: [PATCH 16/21] - Fixed resume error. --- autoload/unite/sources/help.vim | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 5c35d7e..cbbdd24 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 16 Oct 2012. +" Last Change: 13 Dec 2012. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -31,6 +31,8 @@ let s:Cache = vital#of('unite.vim').import('System.Cache') " cache let s:cache = [] +let s:cont_number = 0 +let s:cont_max = 0 function! unite#sources#help#refresh() let s:cache = [] @@ -113,8 +115,8 @@ function! s:source.gather_candidates(args, context) let s:vimproc_files[tagfile] = file endfor - let a:context.source__cont_number = 1 - let a:context.source__cont_max = len(s:vimproc_files) + let s:cont_number = 1 + let s:cont_max = len(s:vimproc_files) return [] endfunction @@ -134,8 +136,7 @@ function! s:source.async_gather_candidates(args, context) call unite#print_source_message( \ printf('[%2d/%2d] Making cache of "%s"...%d%%', - \ a:context.source__cont_number, - \ a:context.source__cont_max, + \ s:cont_number, s:cont_max, \ file.path, progress), s:source.name) for line in lines @@ -159,7 +160,7 @@ function! s:source.async_gather_candidates(args, context) if file.proc.eof call file.proc.close() call remove(s:vimproc_files, key) - let a:context.source__cont_number += 1 + let s:cont_number += 1 endif endfor From 227b9706981c2184fe0aa98087625782f179bad2 Mon Sep 17 00:00:00 2001 From: "yasuda.jiro" Date: Wed, 9 Oct 2013 11:44:44 +0900 Subject: [PATCH 17/21] Replace a deprecated function 'delete' of vital --- autoload/unite/sources/help.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index cbbdd24..c779d67 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -39,7 +39,7 @@ function! unite#sources#help#refresh() let cache_dir = g:unite_data_directory . '/help' if s:Cache.filereadable(cache_dir, 'help-cache') " Delete cache file. - call s:Cache.delete(cache_dir, 'help-cache') + call s:Cache.deletefile(cache_dir, 'help-cache') endif endfunction let s:vimproc_files = {} From 7e81697f8a4d50bb3b7e379e9ad86d82b9e0e181 Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Fri, 14 Feb 2014 19:58:04 +0900 Subject: [PATCH 18/21] Fix vital#of() --- autoload/unite/sources/help.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index c779d67..4ec3bec 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -1,6 +1,6 @@ " help source for unite.vim " Version: 0.0.3 -" Last Change: 13 Dec 2012. +" Last Change: 14 Feb 2014. " Author: tsukkee " Licence: The MIT License {{{ " Permission is hereby granted, free of charge, to any person obtaining a copy @@ -27,7 +27,7 @@ function! unite#sources#help#define() return unite#util#has_vimproc() ? s:source : {} endfunction -let s:Cache = vital#of('unite.vim').import('System.Cache') +let s:Cache = vital#of('unite').import('System.Cache') " cache let s:cache = [] From f61cbf4015c143ebe6ca6cb589b088665a8325cd Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Tue, 10 Jun 2014 23:30:11 +0900 Subject: [PATCH 19/21] Fix for latest unite --- autoload/unite/sources/help.vim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 4ec3bec..13c1a1a 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -36,7 +36,7 @@ let s:cont_max = 0 function! unite#sources#help#refresh() let s:cache = [] - let cache_dir = g:unite_data_directory . '/help' + let cache_dir = unite#get_data_directory() . '/help' if s:Cache.filereadable(cache_dir, 'help-cache') " Delete cache file. call s:Cache.deletefile(cache_dir, 'help-cache') @@ -84,7 +84,7 @@ function! s:source.gather_candidates(args, context) let a:context.is_async = 1 endif - let cache_dir = g:unite_data_directory . '/help' + let cache_dir = unite#get_data_directory() . '/help' if s:Cache.filereadable(cache_dir, 'help-cache') " Use cache file. let s:cache = eval(get(s:Cache.readfile( @@ -170,7 +170,7 @@ function! s:source.async_gather_candidates(args, context) call unite#print_source_message('Completed.', s:source.name) " Save cache file. - let cache_dir = g:unite_data_directory . '/help' + let cache_dir = unite#get_data_directory() . '/help' call s:Cache.writefile(cache_dir, 'help-cache', \ [string(s:cache)]) endif From 1a0bccd022c22456f256c727f9322b8891b2d65a Mon Sep 17 00:00:00 2001 From: Shougo Matsushita Date: Sat, 9 Apr 2016 19:23:43 +0900 Subject: [PATCH 20/21] Fix s:Cache problem --- autoload/unite/sources/help.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 13c1a1a..9f0726d 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -27,7 +27,7 @@ function! unite#sources#help#define() return unite#util#has_vimproc() ? s:source : {} endfunction -let s:Cache = vital#of('unite').import('System.Cache') +let s:Cache = unite#util#get_vital_cache() " cache let s:cache = [] From fccd3773a0eea0da9a621913d3928ebf3b07db4e Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 12 Mar 2017 20:35:12 +0800 Subject: [PATCH 21/21] Improve globpath --- autoload/unite/sources/help.vim | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/autoload/unite/sources/help.vim b/autoload/unite/sources/help.vim index 9f0726d..2bed2f6 100644 --- a/autoload/unite/sources/help.vim +++ b/autoload/unite/sources/help.vim @@ -102,7 +102,7 @@ function! s:source.gather_candidates(args, context) " load files. let s:vimproc_files = {} - for tagfile in split(globpath(&runtimepath, 'doc/{tags,tags-*}'), "\n") + for tagfile in s:globpath(&runtimepath, 'doc/{tags,tags-*}', 1, 1) if !filereadable(tagfile) | continue | endif let file = { @@ -213,6 +213,19 @@ function! s:action_table.tabopen.func(candidate) let &ignorecase = save_ignorecase endfunction +function! s:globpath(path, expr, suf, list) abort + if has('patch-7.4.279') + return globpath(a:path, a:expr, a:suf, a:list) + else + let rst = globpath(a:path, a:expr, a:suf) + if a:list + return split(rst, "\n") + else + return rst + endif + endif +endfunction + let s:source.action_table.common = s:action_table " vim: expandtab:ts=4:sts=4:sw=4