1
0
mirror of https://github.com/gryf/tagbar.git synced 2025-12-17 11:30:28 +01:00

Handle cases where 'encoding' is different from system encoding

This commit is contained in:
Jan Larres
2011-05-05 21:27:47 +12:00
parent 98fe5ec994
commit 1916c55b7c
2 changed files with 39 additions and 1 deletions

View File

@@ -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*

View File

@@ -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)