mirror of
https://github.com/powerline/powerline.git
synced 2025-07-27 07:44:36 +02:00
parent
2304242ca2
commit
f7d7e274f4
@ -1,15 +1,21 @@
|
|||||||
# vim:fileencoding=utf-8:noet
|
# vim:fileencoding=utf-8:noet
|
||||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||||
|
|
||||||
from powerline.segments.vim import window_cached
|
try:
|
||||||
|
import vim
|
||||||
|
except ImportError:
|
||||||
|
vim = object()
|
||||||
|
|
||||||
from powerline.bindings.vim import vim_command_exists, vim_get_autoload_func
|
from powerline.bindings.vim import vim_command_exists, vim_get_autoload_func
|
||||||
|
from powerline.theme import requires_segment_info
|
||||||
|
|
||||||
|
|
||||||
currenttag = None
|
currenttag = None
|
||||||
|
tag_cache = {}
|
||||||
|
|
||||||
|
|
||||||
@window_cached
|
@requires_segment_info
|
||||||
def current_tag(pl, flags='s'):
|
def current_tag(segment_info, pl, flags='s'):
|
||||||
'''Return tag that is near the cursor.
|
'''Return tag that is near the cursor.
|
||||||
|
|
||||||
:param str flags:
|
:param str flags:
|
||||||
@ -25,6 +31,10 @@ def current_tag(pl, flags='s'):
|
|||||||
.. _`official documentation`: https://github.com/majutsushi/tagbar/blob/master/doc/tagbar.txt
|
.. _`official documentation`: https://github.com/majutsushi/tagbar/blob/master/doc/tagbar.txt
|
||||||
'''
|
'''
|
||||||
global currenttag
|
global currenttag
|
||||||
|
global tag_cache
|
||||||
|
window_id = segment_info['window_id']
|
||||||
|
if segment_info['mode'] == 'nc':
|
||||||
|
return tag_cache.get(window_id, (None,))[-1]
|
||||||
if not currenttag:
|
if not currenttag:
|
||||||
if vim_command_exists('Tagbar'):
|
if vim_command_exists('Tagbar'):
|
||||||
currenttag = vim_get_autoload_func('tagbar#currenttag')
|
currenttag = vim_get_autoload_func('tagbar#currenttag')
|
||||||
@ -32,4 +42,10 @@ def current_tag(pl, flags='s'):
|
|||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
return currenttag('%s', '', flags)
|
prev_key, r = tag_cache.get(window_id, (None, None))
|
||||||
|
key = (int(vim.eval('b:changedtick')), segment_info['window'].cursor[0])
|
||||||
|
if prev_key and key == prev_key:
|
||||||
|
return r
|
||||||
|
r = currenttag('%s', '', flags)
|
||||||
|
tag_cache[window_id] = (key, r)
|
||||||
|
return r
|
||||||
|
Loading…
x
Reference in New Issue
Block a user