mirror of
https://github.com/gryf/tagbar.git
synced 2025-12-17 19:40:27 +01:00
Make TagbarOpen command more flexible
This commit is contained in:
@@ -1377,10 +1377,21 @@ function! s:ToggleWindow()
|
||||
endfunction
|
||||
|
||||
" s:OpenWindow() {{{2
|
||||
function! s:OpenWindow(autoclose)
|
||||
" If the tagbar window is already open don't do anything
|
||||
function! s:OpenWindow(flags)
|
||||
let autofocus = a:flags =~# 'f'
|
||||
let jump = a:flags =~# 'j'
|
||||
let autoclose = a:flags =~# 'c'
|
||||
|
||||
" If the tagbar window is already open check jump flag
|
||||
" Also set the autoclose flag if requested
|
||||
let tagbarwinnr = bufwinnr('__Tagbar__')
|
||||
if tagbarwinnr != -1
|
||||
if winnr() != tagbarwinnr && jump
|
||||
execute tagbarwinnr . 'wincmd w'
|
||||
if autoclose
|
||||
let w:autoclose = autoclose
|
||||
endif
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -1408,13 +1419,13 @@ function! s:OpenWindow(autoclose)
|
||||
|
||||
let &eventignore = eventignore_save
|
||||
|
||||
call s:InitWindow(a:autoclose)
|
||||
call s:InitWindow(autoclose)
|
||||
|
||||
wincmd p
|
||||
|
||||
" Jump back to the tagbar window if autoclose or autofocus is set. Can't
|
||||
" just stay in it since it wouldn't trigger the update event
|
||||
if g:tagbar_autoclose || a:autoclose || g:tagbar_autofocus
|
||||
if g:tagbar_autoclose || autofocus || g:tagbar_autofocus
|
||||
let tagbarwinnr = bufwinnr('__Tagbar__')
|
||||
execute tagbarwinnr . 'wincmd w'
|
||||
endif
|
||||
@@ -2865,7 +2876,8 @@ function! tagbar#ToggleWindow()
|
||||
endfunction
|
||||
|
||||
function! tagbar#OpenWindow(...)
|
||||
call s:OpenWindow(a:1)
|
||||
let flags = a:0 > 0 ? a:1 : ''
|
||||
call s:OpenWindow(flags)
|
||||
endfunction
|
||||
|
||||
function! tagbar#CloseWindow()
|
||||
|
||||
@@ -225,9 +225,22 @@ displayed when the cursor stays on a tag for 'updatetime' milliseconds.
|
||||
------------------------------------------------------------------------------
|
||||
COMMANDS *tagbar-commands*
|
||||
|
||||
:TagbarOpen
|
||||
Open the Tagbar if it is closed. In case it is already open jump to it.
|
||||
:TagbarOpen [{flags}]
|
||||
Open the Tagbar window if it is closed.
|
||||
|
||||
Additional behaviour can be specified with the optional {flags} argument.
|
||||
It is a string which can contain these character flags:
|
||||
'f' Jump to Tagbar window when opening (just as if |g:tagbar_autofocus|
|
||||
were set to 1)
|
||||
'j' Jump to Tagbar window if already open
|
||||
'c' Close Tagbar on tag selection (just as if |g:tagbar_autoclose| were
|
||||
set to 1, but doesn't imply 'f')
|
||||
|
||||
For example, the following command would always jump to the Tagbar window,
|
||||
opening it first if necessary, but keep it open after selecting a tag
|
||||
(unless |g:tagbar_autoclose| is set): >
|
||||
:TagbarOpen fj
|
||||
<
|
||||
:TagbarClose
|
||||
Close the Tagbar window if it is open.
|
||||
|
||||
@@ -235,11 +248,11 @@ COMMANDS *tagbar-commands*
|
||||
Open the Tagbar window if it is closed or close it if it is open.
|
||||
|
||||
:TagbarOpenAutoClose
|
||||
Open the Tagbar window and close it on tag selection, regardless of the
|
||||
setting of |g:tagbar_autoclose|. If it was already open jump to it.
|
||||
Open the Tagbar window, jump to it and close it on tag selection. This is
|
||||
an alias for ":TagbarOpen fc".
|
||||
|
||||
:TagbarSetFoldlevel [number]
|
||||
Set the foldlevel of the tags of the current file to [number]. The
|
||||
:TagbarSetFoldlevel {number}
|
||||
Set the foldlevel of the tags of the current file to {number}. The
|
||||
foldlevel of tags in other files remains unaffected. Works in the same way
|
||||
as 'foldlevel'.
|
||||
|
||||
@@ -250,7 +263,7 @@ COMMANDS *tagbar-commands*
|
||||
------------------------------------------------------------------------------
|
||||
KEY MAPPINGS *tagbar-keys*
|
||||
|
||||
These mappings are valid in the Tagbar window:
|
||||
The following mappings are valid in the Tagbar window:
|
||||
|
||||
<F1> Display key mapping help.
|
||||
<CR>/<Enter> Jump to the tag under the cursor. Doesn't work for pseudo-tags
|
||||
@@ -318,7 +331,7 @@ g:tagbar_autoclose~
|
||||
Default: 0
|
||||
|
||||
If you set this option the Tagbar window will automatically close when you
|
||||
jump to a tag.
|
||||
jump to a tag. This implies |g:tagbar_autofocus|.
|
||||
|
||||
Example:
|
||||
>
|
||||
|
||||
@@ -85,8 +85,8 @@ augroup END
|
||||
|
||||
" Commands {{{1
|
||||
command! -nargs=0 TagbarToggle call tagbar#ToggleWindow()
|
||||
command! -nargs=0 TagbarOpen call tagbar#OpenWindow(0)
|
||||
command! -nargs=0 TagbarOpenAutoClose call tagbar#OpenWindow(1)
|
||||
command! -nargs=? TagbarOpen call tagbar#OpenWindow(<f-args>)
|
||||
command! -nargs=0 TagbarOpenAutoClose call tagbar#OpenWindow('fc')
|
||||
command! -nargs=0 TagbarClose call tagbar#CloseWindow()
|
||||
command! -nargs=1 TagbarSetFoldlevel call tagbar#SetFoldLevel(<args>)
|
||||
command! -nargs=0 TagbarShowTag call tagbar#OpenParents()
|
||||
|
||||
Reference in New Issue
Block a user