1
0
mirror of https://github.com/gryf/tagbar.git synced 2026-05-11 00:42:59 +02:00

17 Commits

Author SHA1 Message Date
gryf 75174f1c09 Fix has_key() parameters in currenttagtype function. 2020-08-23 17:57:46 +02:00
Danilo Luvizotto a81c01c294 Fix maximized state track on close (#642) 2020-08-17 08:33:00 +03:00
raven42 a5090717dd Add function tabgar:Update() to manually trigger AutoUpdate() (#633)
Co-authored-by: David Hegland <david.hegland@broadcom.com>
2020-08-03 15:30:13 +03:00
raven42 88bdb86325 Remove debug statement left in 4e7e199 causing screen flicker (#634) 2020-08-03 12:13:03 +03:00
embear 3fe9d8e13b Check for existence of key in dictionary before using it (#631) 2020-07-30 20:36:07 +03:00
raven42 5bb0ef3576 Add more flexible options for window positioning (#630)
New configuration option for g:tagbar_position that will supercede g:tagbar_left. This option allows for new values for 'top', 'bottom', 'left' and 'right' (default:'right') to position the Tagbar window.

New configuration option for g:tagbar_height that will supercede g:tagbar_vertical. This option is used to set the Tagbar window height when the window is split using the 'top' or 'bottom' position.

New configuration option for g:tagbar_no_status_line. This option will disable any Tagbar status line updates in the event another plugin is controlling the status line. This prevents Tagbar from changing the status line when Tagbar is not the active window.

Co-authored-by: David Hegland <david.hegland@broadcom.com>
2020-07-29 21:18:17 +03:00
tanhuacheng d7063c7484 Reset window after jump to tag if zoomed (#625) 2020-06-25 00:01:58 +03:00
Aaron Toderash 56399f446c Document extra languages supported by universal-ctags (#621)
Co-authored-by: Caleb Maclennan <caleb@alerque.com>
2020-06-12 00:04:31 +03:00
Hedy Li fcabc99ca6 Add link to docs and how to open docs in README.md (#619)
Co-authored-by: Caleb Maclennan <caleb@alerque.com>
2020-06-06 16:36:02 +03:00
Linwei a36880be22 Prevent temporary window creation on Windows (#611)
Co-authored-by: skywind3000 <skywind3000@163.com>
Co-authored-by: Caleb Maclennan <caleb@alerque.com>
2020-05-30 11:51:45 +03:00
Caleb Maclennan f1bea00e5b Merge pull request #610 from majutsushi/no-cache 2020-05-29 22:42:31 +03:00
Caleb Maclennan e8d127bf40 Catch error message from u/e ctags variants
Co-authored-by: Steven Engler <sengler@uwaterloo.ca>
2020-05-29 21:56:48 +03:00
Caleb Maclennan 92752b89ce Add option to disable use of tmp file cache 2020-05-29 21:02:31 +03:00
cridemichel 2a1486447a Play nicely with popup windows (#604) 2020-05-05 15:47:01 +03:00
Felix Strobel 1e50ea8536 Fix license link in readme file (#599) 2020-04-24 18:37:42 +03:00
cridemichel 679a9d9ac9 Block ProcessFile from processing unloaded or nonexistant buffers (#589) 2020-01-23 18:06:44 +02:00
Caleb Maclennan 6dafb3dfe8 Merge pull request #308 from gryf/show_tag_kind2
Additional function for displaying type of a current tag.
2020-01-17 13:59:59 +02:00
4 changed files with 224 additions and 42 deletions
+2 -2
View File
@@ -53,7 +53,7 @@ nmap <F8> :TagbarToggle<CR>
If you do this the F8 key will toggle the Tagbar window. You can of course use
any shortcut you want. For more flexible ways to open and close the window
(and the rest of the functionality) see the documentation.
(and the rest of the functionality) see the [documentation](https://github.com/majutsushi/tagbar/blob/master/doc/tagbar.txt) using `:help tagbar`.
## Support for additional filetypes
@@ -87,7 +87,7 @@ against Tagbar](https://github.com/majutsushi/tagbar/issues?labels=ctags-bug&pag
## License
Tagbar is distributed under the terms of the *Vim license*, see the included [LICENSE][] file.
Tagbar is distributed under the terms of the *Vim license*, see the included [LICENSE](LICENSE) file.
## Contributors
+113 -30
View File
@@ -879,14 +879,21 @@ function! s:OpenWindow(flags) abort
endif
let s:window_opening = 1
if g:tagbar_vertical == 0
if g:tagbar_position =~# '\v(bottom|right)'
let openpos = 'rightbelow '
else
let openpos = 'leftabove '
endif
if g:tagbar_position =~# '\v(left|right)'
let mode = 'vertical '
let openpos = g:tagbar_left ? 'topleft ' : 'botright '
let width = g:tagbar_width
else
let mode = ''
let openpos = g:tagbar_left ? 'leftabove ' : 'rightbelow '
let width = g:tagbar_vertical
if g:tagbar_height > 0
let width = g:tagbar_height
else
let width = g:tagbar_vertical
endif
endif
exe 'silent keepalt ' . openpos . mode . width . 'split ' . s:TagbarBufName()
exe 'silent ' . mode . 'resize ' . width
@@ -1027,6 +1034,7 @@ function! s:CloseWindow() abort
" Other windows are open, only close the tagbar one
let curfile = tagbar#state#get_current_file(0)
let s:is_maximized = 0
close
@@ -1148,6 +1156,17 @@ function! s:ProcessFile(fname, ftype) abort
return
endif
let l:bufnum = bufnr(a:fname)
if !bufloaded(l:bufnum)
call tagbar#debug#log('[ProcessFile] Buffer is not loaded exiting...')
return
endif
if !bufexists(l:bufnum)
call tagbar#debug#log('[ProcessFile] Buffer does not exist exiting...')
return
endif
let typeinfo = s:known_types[a:ftype]
" If the file has only been updated preserve the fold states, otherwise
@@ -1171,29 +1190,34 @@ function! s:ProcessFile(fname, ftype) abort
call tagbar#debug#log('typeinfo for file to process: ' . string(typeinfo))
" Use a temporary files for ctags processing instead of the original one.
" This allows using Tagbar for files accessed with netrw, and also doesn't
" slow down Tagbar for files that sit on slow network drives.
let tempfile = tempname()
let ext = fnamemodify(fileinfo.fpath, ':e')
if ext !=# ''
let tempfile .= '.' . ext
endif
if g:tagbar_use_cache
" Use a temporary files for ctags processing instead of the original one.
" This allows using Tagbar for files accessed with netrw, and also doesn't
" slow down Tagbar for files that sit on slow network drives.
let tempfile = tempname()
let ext = fnamemodify(fileinfo.fpath, ':e')
if ext !=# ''
let tempfile .= '.' . ext
endif
call tagbar#debug#log('Caching file into: ' . tempfile)
let templines = getbufline(fileinfo.bufnr, 1, '$')
let res = writefile(templines, tempfile)
call tagbar#debug#log('Caching file into: ' . tempfile)
let templines = getbufline(fileinfo.bufnr, 1, '$')
let res = writefile(templines, tempfile)
if res != 0
call tagbar#debug#log('Could not create copy '.tempfile)
return
endif
let fileinfo.mtime = getftime(tempfile)
if res != 0
call tagbar#debug#log('Could not create copy '.tempfile)
return
endif
let fileinfo.mtime = getftime(tempfile)
let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo)
let ctags_output = s:ExecuteCtagsOnFile(tempfile, a:fname, typeinfo)
if !tagbar#debug#enabled()
call delete(tempfile)
if !tagbar#debug#enabled()
call delete(tempfile)
endif
else
call tagbar#debug#log('File caching disabled')
let ctags_output = s:ExecuteCtagsOnFile(a:fname, a:fname, typeinfo)
endif
if ctags_output == -1
@@ -1351,7 +1375,7 @@ function! s:ExecuteCtagsOnFile(fname, realfname, typeinfo) abort
let ctags_output = s:ExecuteCtags(ctags_cmd)
if v:shell_error || ctags_output =~? 'Warning: cannot open source file'
if v:shell_error || ctags_output =~? 'Warning: cannot open \(source\|input\) file'
call tagbar#debug#log('Command output:')
call tagbar#debug#log(ctags_output)
call tagbar#debug#log('Exit code: ' . v:shell_error)
@@ -2244,6 +2268,9 @@ function! s:JumpToTag(stay_in_tagbar) abort
if s:pwin_by_tagbar
pclose
endif
if s:is_maximized
call s:ZoomWindow()
endif
call s:HighlightTag(0)
endif
endfunction
@@ -2268,7 +2295,7 @@ function! s:ShowInPreviewWin() abort
" We want the preview window to be relative to the file window in normal
" (horizontal) mode, and relative to the Tagbar window in vertical mode,
" to make the best use of space.
if g:tagbar_vertical == 0
if g:tagbar_position !~# '\v(top|bottom)'
call s:GotoFileWindow(taginfo.fileinfo, 1)
call s:mark_window()
endif
@@ -2279,7 +2306,7 @@ function! s:ShowInPreviewWin() abort
silent execute
\ g:tagbar_previewwin_pos . ' pedit ' .
\ fnameescape(taginfo.fileinfo.fpath)
if g:tagbar_vertical != 0
if g:tagbar_position =~# '\v(top|bottom)'
silent execute 'vertical resize ' . g:tagbar_width
endif
" Remember that the preview window was opened by Tagbar so we can
@@ -2287,7 +2314,7 @@ function! s:ShowInPreviewWin() abort
let s:pwin_by_tagbar = 1
endif
if g:tagbar_vertical != 0
if g:tagbar_position =~# '\v(top|bottom)'
call s:GotoFileWindow(taginfo.fileinfo, 1)
call s:mark_window()
endif
@@ -2855,6 +2882,39 @@ function! s:EscapeCtagsCmd(ctags_bin, args, ...) abort
return ctags_cmd
endfunction
" run shell command in a proper way: prevent temporary window creation
function! s:run_system(cmd, version) abort
if has('win32') && !has('nvim') && a:version > 0 && (has('python3') || has('python2'))
if a:version == 3 && has('python3')
let pyx = 'py3 '
let python_eval = 'py3eval'
elseif a:version == 2 && has('python2')
let pyx = 'py2 '
let python_eval = 'pyeval'
else
let pyx = 'pyx '
let python_eval = 'pyxeval'
endif
let l:pc = 0
exec pyx . 'import subprocess, vim'
exec pyx . '__argv = {"args":vim.eval("a:cmd"), "shell":True}'
exec pyx . '__argv["stdout"] = subprocess.PIPE'
exec pyx . '__argv["stderr"] = subprocess.STDOUT'
exec pyx . '__pp = subprocess.Popen(**__argv)'
exec pyx . '__return_text = __pp.stdout.read()'
exec pyx . '__pp.stdout.close()'
exec pyx . '__return_code = __pp.wait()'
exec 'let l:hr = '. python_eval .'("__return_text")'
exec 'let l:pc = '. python_eval .'("__return_code")'
let s:shell_error = l:pc
return l:hr
endif
let hr = system(a:cmd)
let s:shell_error = v:shell_error
return hr
endfunction
" s:ExecuteCtags() {{{2
" Execute ctags with necessary shell settings
" Partially based on the discussion at
@@ -2892,7 +2952,8 @@ function! s:ExecuteCtags(ctags_cmd) abort
call tagbar#debug#log('Exit code: ' . v:shell_error)
redraw!
else
silent let ctags_output = system(a:ctags_cmd)
let py_version = get(g:, 'tagbar_python', 1)
silent let ctags_output = s:run_system(a:ctags_cmd, py_version)
endif
if &shell =~? 'cmd\.exe'
@@ -3146,7 +3207,7 @@ endfunction
" s:SetStatusLine() {{{2
function! s:SetStatusLine() abort
let tagbarwinnr = bufwinnr(s:TagbarBufName())
if tagbarwinnr == -1
if tagbarwinnr == -1 || exists('g:tagbar_no_status_line')
return
endif
@@ -3360,6 +3421,18 @@ endfunction
" s:goto_win() {{{2
function! s:goto_win(winnr, ...) abort
"Do not go to a popup window to avoid errors.
"Hence, check first if a:winnr is an integer,
"if this integer is equal to 0,
"the window is a popup window
if has('popupwin')
if type(a:winnr) == type(0) && a:winnr == 0
return
endif
if a:winnr ==# 'p' && winnr('#') == 0
return
endif
endif
let cmd = type(a:winnr) == type(0) ? a:winnr . 'wincmd w'
\ : 'wincmd ' . a:winnr
let noauto = a:0 > 0 ? a:1 : 0
@@ -3483,6 +3556,12 @@ endfunction
" }}}2
" tagbar#Update() {{{2
" Trigger an AutoUpdate() of the currently opened file
function! tagbar#Update() abort
call s:AutoUpdate(fnamemodify(expand('%'), ':p'), 0)
endfunction
" tagbar#toggle_pause() {{{2
function! tagbar#toggle_pause() abort
let s:paused = !s:paused
@@ -3641,7 +3720,11 @@ function! tagbar#currenttagtype(fmt, default) abort
let typeinfo = tag.fileinfo.typeinfo
let plural = typeinfo.kinds[typeinfo.kinddict[kind]].long
let singular = s:singular_types[plural]
if has_key(s:singular_types, plural)
let singular = s:singular_types[plural]
else
let singular = plural
endif
return printf(a:fmt, singular)
endfunction
+84 -7
View File
@@ -103,6 +103,10 @@ The following features are supported by Tagbar:
Fortran, HTML, Java, JavaScript, Lisp, Lua, Make, MatLab, OCaml, Pascal,
Perl, PHP, Python, REXX, Ruby, Scheme, Shell script, SLang, SML, SQL, Tcl,
Tex, Vera, Verilog, VHDL, Vim and YACC.
- Additional languages are supported through universal-ctags, including
CUDA, R, Rust, Go, and many others. See
https://github.com/universal-ctags/ctags/blob/master/docs/news.rst#new-parsers
for the complete list.
- Can be extended to support arbitrary new types.
------------------------------------------------------------------------------
@@ -123,12 +127,13 @@ The following requirements have to be met in order to be able to use tagbar:
- Vim 7.0 or higher. Older versions will not work since Tagbar uses data
structures that were only introduced in Vim 7.
- Exuberant ctags 5.5 or higher. Ctags is the program that generates the
tag information that Tagbar uses. It is shipped with most Linux
distributions, otherwise it can be downloaded from the following
website:
- At a minimum Exuberant Ctags >= 5.5, or (highly recommended) any version
of Universal Ctags which is a currently maintained fork of Exuberant Ctags
with many bugfixes, support for many more formats, and proper Unicode
support. Some additional formats can also be handled by other providers
such as jsctags, phpctags, or others.
http://ctags.sourceforge.net/
Universal Ctags can be downloaded from https://ctags.io/
Tagbar will work on any platform that ctags runs on -- this includes
UNIX derivatives, Mac OS X and Windows. Note that other versions like
@@ -179,7 +184,7 @@ There are essentially two ways to use Tagbar:
Opening and closing the Tagbar window~
Use |:TagbarOpen| or |:TagbarToggle| to open the Tagbar window if it is
closed. By default the window is opened on the right side, set the option
|g:tagbar_left| to open it on the left instead. If the window is already open,
|g:tagbar_position| to open it elsewhere instead. If the window is already open,
|:TagbarOpen| will jump to it and |:TagbarToggle| will close it again.
|:TagbarClose| will simply close the window if it is open.
@@ -421,10 +426,34 @@ This causes ctags to use settings from ~/.vim/ctags.cnf, ignoring other
configuration files.
*g:tagbar_position*
g:tagbar_position~
Default: 'right'
By default the Tagbar window will be opened on the right-hand side of vim. Set
this option to one of 'left', 'right', 'bottom', or 'top' to open in the
corresponding position instead. This can be useful when activating Tagbar at
the same time as another plugin which creates a new window. It allows for more
granular control of the Tagbar position in relation to the current active
window.
If set to 'top' of 'bottom', |g:tagbar_height| will be used to determine the
window height for the tagbar window.
if set to 'left' or 'right', |g:tagbar_width| will be used to determine the
window width for the tagbar window.
Example:
>
let g:tagbar_position = 'left'
<
*g:tagbar_left*
g:tagbar_left~
Default: 0
This option has been superceded by |g:tagbar_position| instead. It has been left
around for backward compatibility.
By default the Tagbar window will be opened on the right-hand side of vim. Set
this option to open it on the left instead.
@@ -440,6 +469,9 @@ Example:
g:tagbar_vertical~
Default: 0
This option has been superceded by |g:tagbar_height| instead. It has been left
around for backward compatibility.
If this is set to a positive value then the Tagbar window will be opened at
the top or bottom of the Vim window instead of at the side. This can be useful
for monitors that have been rotated into a vertical position. The value of
@@ -451,11 +483,24 @@ Example:
let g:tagbar_vertical = 30
<
*g:tagbar_height*
g:tagbar_height~
Default: 0
If |g:tagbar_position| is set to 'bottom' or 'top', then this value is used to
determine the height of the Tagbar window.
See |g:tagbar_left| for configuring the position of the window.
Example:
>
let g:tagbar_height = 30
<
*g:tagbar_width*
g:tagbar_width~
Default: 40
Width of the Tagbar window in characters.
If |g:tagbar_position| is set to 'left' or 'right', then this value is used to
determine the width of the Tagbar window in characters.
Example:
>
@@ -773,6 +818,19 @@ default statusline:
endfunction
let g:tagbar_status_func = 'TagbarStatusFunc'
<
*g:tagbar_no_status_line*
g:no_status_line~
Default: undefined
This option will prevent any status line updates being done by Tagbar. Use
this in the event where another plugin is being used to update the status
line. If |g:tagbar_status_func| is set, then that function will never be
called.
Example:
>
let g:no_status_line = 1
<
*g:tagbar_silent*
g:tagbar_silent~
@@ -785,6 +843,25 @@ Example:
>
let g:tagbar_silent = 1
<
*g:tagbar_use_cache*
g:tagbar_use_cache~
Default: 1
By default the file contents are passed to ctags by writing them to
a temporary file and invoking ctags on that file. This greatly speeds up tag
generation in the event of slow file systems such as network shares and
enables tagbar to run even on netrw virtual files that ctags would otherwise
not be able to find at all. However it does incure the cost of an extra write
operation. Additionally not all sysems are able to let programs share access
to temporary file space (for example Snap packages cannot read from the host
system's temp file space). This setting can disable the cache mechanism
entriely forcing the tags to be generated from the existing copy of the file
on disk rather than the current buffer written to a temporary file.
Example:
>
let g:tagbar_use_cache = 0
<
------------------------------------------------------------------------------
HIGHLIGHT COLOURS *tagbar-highlight*
+25 -3
View File
@@ -49,10 +49,29 @@ function! s:init_var(var, value) abort
endfunction
function! s:setup_options() abort
if !exists('g:tagbar_vertical') || g:tagbar_vertical == 0
let previewwin_pos = 'topleft'
if exists('g:tagbar_position')
if g:tagbar_position !~# '\v(top|bottom)'
let previewwin_pos = 'topleft'
else
let previewwin_pos = 'rightbelow vertical'
endif
let default_pos = g:tagbar_position
else
let previewwin_pos = 'rightbelow vertical'
if exists('g:tagbar_vertical') && g:tagbar_vertical > 0
let previewwin_pos = 'rightbelow vertical'
if exists('g:tagbar_left') && g:tagbar_left
let default_pos = 'top'
else
let default_pos = 'bottom'
endif
let g:tagbar_height = g:tagbar_vertical
elseif exists('g:tagbar_left') && g:tagbar_left
let previewwin_pos = 'topleft'
let default_pos = 'left'
else
let previewwin_pos = 'topleft'
let default_pos = 'right'
endif
endif
let options = [
\ ['autoclose', 0],
@@ -64,6 +83,7 @@ function! s:setup_options() abort
\ ['expand', 0],
\ ['foldlevel', 99],
\ ['hide_nonpublic', 0],
\ ['height', 10],
\ ['indent', 2],
\ ['left', 0],
\ ['previewwin_pos', previewwin_pos],
@@ -74,9 +94,11 @@ function! s:setup_options() abort
\ ['sort', 1],
\ ['systemenc', &encoding],
\ ['vertical', 0],
\ ['position', default_pos],
\ ['width', 40],
\ ['zoomwidth', 1],
\ ['silent', 0],
\ ['use_cache', 1],
\ ]
for [opt, val] in options