diff --git a/doc/tagbar.txt b/doc/tagbar.txt index a80b93f..67faa06 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -417,6 +417,21 @@ Example: let g:tagbar_autoshowtag = 1 < + *g:tagbar_systemenc* +g:tagbar_systemenc~ +Default: value of 'encoding' + +This variable is for cases where the character encoding of your operating +system is different from the one set in Vim, i.e. the 'encoding' option. For +example, if you use a Simplified Chinese Windows version that has a system +encoding of "cp936", and you have set 'encoding' to "utf-8", then you would +have to set this variable to "cp936". + +Example: +> + let g:tagbar_systemenc = 'cp936' +< + ------------------------------------------------------------------------------ HIGHLIGHT COLOURS *tagbar-highlight* diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 3404eff..68bd702 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -91,6 +91,10 @@ if !exists('g:tagbar_autoshowtag') let g:tagbar_autoshowtag = 0 endif +if !exists('g:tagbar_systemenc') + let g:tagbar_systemenc = &encoding +endif + if has('multi_byte') && has('unix') && &encoding == 'utf-8' && \ (empty(&termencoding) || &termencoding == 'utf-8') let s:icon_closed = '▶' @@ -1464,15 +1468,34 @@ function! s:ProcessFile(fname, ftype) let ctags_bin = g:tagbar_ctags_bin endif + " shellescape() doesn't seem to work on windows for calling a program, so + " use the 8.3 form instead if has('win32') || has('win64') let ctags_bin = fnamemodify(ctags_bin, ':8') else let ctags_bin = shellescape(ctags_bin) endif + let ctags_cmd = ctags_bin . ctags_args . shellescape(a:fname) + + " Needed for cases where 'encoding' is different from the system's + " encoding + if g:tagbar_systemenc != &encoding + let ctags_cmd = iconv(ctags_cmd, &encoding, g:tagbar_systemenc) + elseif $LANG != '' + let ctags_cmd = iconv(ctags_cmd, &encoding, $LANG) + endif + + if ctags_cmd == '' + echoerr 'Tagbar: Encoding conversion failed!' + \ 'Please make sure your system is set up correctly' + \ 'and that Vim is compiled with the "iconv" feature.' + return + endif + let ctags_output = system(ctags_cmd) - if v:shell_error + if v:shell_error || ctags_output =~ 'Warning: cannot open source file' echoerr 'Tagbar: Could not execute ctags for ' . a:fname . '!' echomsg 'Executed command: "' . ctags_cmd . '"' if !empty(ctags_output)