Closed hanxi closed 6 years ago
Maybe we can backup the register and restore it after the execution of global command?
I view this plugin use cmd out of vim.
https://github.com/ludovicchabant/vim-gutentags/blob/master/plat/unix/update_tags.sh#L98-L107
if [ -f "$TAGS_FILE" ]; then
if [ "$UPDATED_SOURCE" != "" ]; then
echo "Removing references to: $UPDATED_SOURCE"
tab=" "
cmd="grep --text -Ev '^[^$tab]+$tab$UPDATED_SOURCE$tab' '$TAGS_FILE' > '$TAGS_FILE.temp'"
echo "$cmd"
eval "$cmd" || true
INDEX_WHOLE_PROJECT=0
fi
fi
If we backup the register, maybe need backup all register.
Yeah, I known that vim-gutentags do this job with external command. But sorry, I'm not familiar with bat..
Maybe one day I'll try to rewrite this plugin with python or other language. But not today..
I try backup and restore all register. Buy it's look like slowly.
diff --git a/autoload/gen_tags/ctags.vim b/autoload/gen_tags/ctags.vim
index 33486a0..93fc983 100644
--- a/autoload/gen_tags/ctags.vim
+++ b/autoload/gen_tags/ctags.vim
@@ -240,6 +240,17 @@ function! s:ctags_prune(tagfile, file) abort
"Save current tab page
let l:pretabpage = tabpagenr('$') - tabpagenr()
+ "Save registers
+ let l:regs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-'
+ let l:i = 0
+ while (l:i<strlen(l:regs))
+ exec 'let l:oldreg'.l:i.' = getreg("'.l:regs[l:i].'")'
+ exec 'let l:oldregtype'.l:i.' = getregtype("'.l:regs[l:i].'")'
+ let l:i = l:i + 1
+ endwhile
+ let l:oldregx = getreg('"')
+ let l:oldregtypex = getregtype('"')
+
set eventignore=FileType
set nofoldenable
set noswapfile
@@ -268,6 +279,14 @@ function! s:ctags_prune(tagfile, file) abort
exec 'silent tabp1'
endif
+ "Restore registers
+ let l:i = 0
+ while (l:i<strlen(l:regs))
+ exec 'call setreg("'.l:regs[l:i].'", l:oldreg'.l:i.', l:oldregtype'.l:i.')'
+ let l:i = l:i + 1
+ endwhile
+ call setreg('"', l:oldregx, l:oldregtypex)
+
"Restore undofile setting
if has('persistent-undo')
let &undofile = l:undostatus
I write the profile, the most time is in
exec 'silent tabedit ' . a:tagfile
exec 'silent %g/' . escape(a:file, ' /') . '/d'
"Save registers
1 0.000004 let l:regs = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-'
1 0.000003 let l:i = 0
65 0.000255 while (l:i<strlen(l:regs))
64 0.000766 exec 'let l:oldreg'.l:i.' = getreg("'.l:regs[l:i].'")'
64 0.000814 exec 'let l:oldregtype'.l:i.' = getregtype("'.l:regs[l:i].'")'
64 0.000190 let l:i = l:i + 1
64 0.000093 endwhile
1 0.000005 let l:oldregx = getreg('"')
1 0.000005 let l:oldregtypex = getregtype('"')
1 0.000013 set eventignore=FileType
1 0.000007 set nofoldenable
1 0.000077 set noswapfile
"Open tagfile
1 0.112995 exec 'silent tabedit ' . a:tagfile
"Delete specified lines
1 0.000019 if has('win32')
let l:file = escape(a:file, ' \')
exec 'silent %g/' . escape(l:file, ' \/') . '/d'
else
1 0.815465 exec 'silent %g/' . escape(a:file, ' /') . '/d'
1 0.000010 endif
1 0.064653 exec 'silent write'
1 0.002476 exec 'silent bd!'
yes, it's very slow.
I rewrite ctags_prune()
function with python, it will fix this issue.
But I need more testing and profiling on it.
I try to profile it
The old implement
FUNCTION <SNR>40_ctags_prune()
Called 50 times
Total time: 0.405388
Self time: 0.405388
The python implement
FUNCTION <SNR>40_ctags_prune()
Called 50 times
Total time: 0.002066
Self time: 0.002066
The python version is almost 200 times faster than the old version. 😄
Good job. :+1:
Thanks, I'll merge it after some tests
https://github.com/jsfaint/gen_tags.vim/blob/master/autoload/gen_tags/ctags.vim#L255
I have no idea to fix it.