Add support for capslock plugin
This commit is contained in:
parent
d392cf3322
commit
8cf2a86672
|
@ -32,3 +32,9 @@ NERDTree segments
|
|||
|
||||
.. automodule:: powerline.segments.vim.plugin.nerdtree
|
||||
:members:
|
||||
|
||||
Capslock segments
|
||||
-----------------
|
||||
|
||||
.. automodule:: powerline.segments.vim.plugin.capslock
|
||||
:members:
|
||||
|
|
|
@ -124,6 +124,22 @@ else:
|
|||
vim_get_func = VimFunc
|
||||
|
||||
|
||||
if hasattr(vim, 'Function'):
|
||||
def vim_func_exists(f):
|
||||
try:
|
||||
vim.Function(f)
|
||||
except ValueError:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
else:
|
||||
def vim_func_exists(f):
|
||||
try:
|
||||
return bool(int(vim.eval('type(function("{0}")) == 2'.format(f))))
|
||||
except vim.error:
|
||||
return False
|
||||
|
||||
|
||||
if type(vim) is object:
|
||||
vim_get_func = lambda *args, **kwargs: None
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
{
|
||||
"groups": {
|
||||
"branch_clean": "branch",
|
||||
"environment": "information:unimportant",
|
||||
"file_size": "information:unimportant",
|
||||
"file_format": "information:unimportant",
|
||||
"file_encoding": "file_format",
|
||||
"file_type": "file_format",
|
||||
"branch": "information:additional",
|
||||
"file_scheme": "file_name",
|
||||
"file_directory": "information:additional",
|
||||
"file_name_empty": "file_directory",
|
||||
"line_percent": "information:additional",
|
||||
"line_count": "line_current",
|
||||
"position": "information:additional",
|
||||
"single_tab": "line_current",
|
||||
"many_tabs": "line_current",
|
||||
"bufnr": "file_directory",
|
||||
"winnr": "information:unimportant",
|
||||
"tabnr": "file_directory",
|
||||
"branch_clean": "branch",
|
||||
"environment": "information:unimportant",
|
||||
"file_size": "information:unimportant",
|
||||
"file_format": "information:unimportant",
|
||||
"file_encoding": "file_format",
|
||||
"file_type": "file_format",
|
||||
"branch": "information:additional",
|
||||
"file_scheme": "file_name",
|
||||
"file_directory": "information:additional",
|
||||
"file_name_empty": "file_directory",
|
||||
"line_percent": "information:additional",
|
||||
"line_count": "line_current",
|
||||
"position": "information:additional",
|
||||
"single_tab": "line_current",
|
||||
"many_tabs": "line_current",
|
||||
"bufnr": "file_directory",
|
||||
"winnr": "information:unimportant",
|
||||
"tabnr": "file_directory",
|
||||
"capslock_indicator": "paste_indicator",
|
||||
|
||||
"csv:column_number": "line_current",
|
||||
"csv:column_name": "line_current_symbol",
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
"exclude_modes": ["nc"],
|
||||
"priority": 10
|
||||
},
|
||||
{
|
||||
"function": "powerline.segments.vim.plugin.capslock.capslock_indicator",
|
||||
"include_modes": ["i", "R", "Rv"],
|
||||
"priority": 10
|
||||
},
|
||||
{
|
||||
"function": "branch",
|
||||
"exclude_modes": ["nc"],
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
# vim:fileencoding=utf-8:noet
|
||||
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
||||
|
||||
try:
|
||||
import vim
|
||||
except ImportError:
|
||||
vim = object()
|
||||
|
||||
from powerline.bindings.vim import vim_func_exists
|
||||
from powerline.theme import requires_segment_info
|
||||
|
||||
|
||||
@requires_segment_info
|
||||
def capslock_indicator(pl, segment_info, text='CAPS'):
|
||||
'''Shows the indicator if tpope/vim-capslock plugin is enabled
|
||||
|
||||
.. _note::
|
||||
In the current state plugin automatically disables itself when leaving
|
||||
insert mode. So trying to use this segment not in insert or replace
|
||||
modes is useless.
|
||||
|
||||
:param str text:
|
||||
String to show when software capslock presented by this plugin is
|
||||
active.
|
||||
'''
|
||||
if not vim_func_exists('CapsLockStatusline'):
|
||||
return None
|
||||
# CapsLockStatusline() function returns an empty string when plugin is
|
||||
# disabled. If it is not then string is non-empty.
|
||||
return text if vim.eval('CapsLockStatusline()') else None
|
Loading…
Reference in New Issue