summaryrefslogtreecommitdiffstats
path: root/powerline/segments/vim/plugin
diff options
context:
space:
mode:
Diffstat (limited to 'powerline/segments/vim/plugin')
-rw-r--r--powerline/segments/vim/plugin/__init__.py6
-rw-r--r--powerline/segments/vim/plugin/ale.py52
-rw-r--r--powerline/segments/vim/plugin/capslock.py30
-rw-r--r--powerline/segments/vim/plugin/coc.py51
-rw-r--r--powerline/segments/vim/plugin/commandt.py97
-rw-r--r--powerline/segments/vim/plugin/nerdtree.py25
-rw-r--r--powerline/segments/vim/plugin/syntastic.py43
-rw-r--r--powerline/segments/vim/plugin/tagbar.py51
8 files changed, 355 insertions, 0 deletions
diff --git a/powerline/segments/vim/plugin/__init__.py b/powerline/segments/vim/plugin/__init__.py
new file mode 100644
index 0000000..b2b9f10
--- /dev/null
+++ b/powerline/segments/vim/plugin/__init__.py
@@ -0,0 +1,6 @@
+# vim:fileencoding=utf-8:noet
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+from pkgutil import extend_path
+
+
+__path__ = extend_path(__path__, __name__)
diff --git a/powerline/segments/vim/plugin/ale.py b/powerline/segments/vim/plugin/ale.py
new file mode 100644
index 0000000..4f4bdee
--- /dev/null
+++ b/powerline/segments/vim/plugin/ale.py
@@ -0,0 +1,52 @@
+# 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_global_exists
+from powerline.theme import requires_segment_info
+
+
+@requires_segment_info
+def ale(segment_info, pl, err_format='ERR: ln {first_line} ({num}) ', warn_format='WARN: ln {first_line} ({num}) '):
+ '''Show whether ALE has found any errors or warnings
+
+ :param str err_format:
+ Format string for errors.
+
+ :param str warn_format:
+ Format string for warnings.
+
+ Highlight groups used: ``ale:warning`` or ``warning``, ``ale:error`` or ``error``.
+ '''
+ if not (vim_global_exists('ale_enabled') and int(vim.eval('g:ale_enabled'))):
+ return None
+ has_errors = int(vim.eval('ale#statusline#Count(' + str(segment_info['bufnr']) + ').total'))
+ if not has_errors:
+ return
+ error = None
+ warning = None
+ errors_count = 0
+ warnings_count = 0
+ for issue in vim.eval('ale#engine#GetLoclist(' + str(segment_info['bufnr']) + ')'):
+ if issue['type'] == 'E':
+ error = error or issue
+ errors_count += 1
+ elif issue['type'] == 'W':
+ warning = warning or issue
+ warnings_count += 1
+ segments = []
+ if error:
+ segments.append({
+ 'contents': err_format.format(first_line=error['lnum'], num=errors_count),
+ 'highlight_groups': ['ale:error', 'error'],
+ })
+ if warning:
+ segments.append({
+ 'contents': warn_format.format(first_line=warning['lnum'], num=warnings_count),
+ 'highlight_groups': ['ale:warning', 'warning'],
+ })
+ return segments
diff --git a/powerline/segments/vim/plugin/capslock.py b/powerline/segments/vim/plugin/capslock.py
new file mode 100644
index 0000000..d2c474d
--- /dev/null
+++ b/powerline/segments/vim/plugin/capslock.py
@@ -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
diff --git a/powerline/segments/vim/plugin/coc.py b/powerline/segments/vim/plugin/coc.py
new file mode 100644
index 0000000..290faec
--- /dev/null
+++ b/powerline/segments/vim/plugin/coc.py
@@ -0,0 +1,51 @@
+# 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_command_exists
+from powerline.theme import requires_segment_info
+
+# coc_status's format: E1 W2
+def parse_coc_status(coc_status):
+ # type(coc_status) is tuple
+ errors_count = 0
+ warnings_count = 0
+ if len(coc_status) <= 0:
+ return errors_count, warnings_count
+ status_str = coc_status[0]
+ if len(status_str) <= 0:
+ return errors_count, warnings_count
+ status_list = status_str.split(' ')
+ for item in status_list:
+ if len(item) > 0 and item[0] == 'E':
+ errors_count = int(item[1:])
+ if len(item) > 0 and item[0] == 'W':
+ warnings_count = int(item[1:])
+ return errors_count, warnings_count
+
+@requires_segment_info
+def coc(segment_info, pl):
+ '''Show whether coc.nvim has found any errors or warnings
+
+ Highlight groups used: ``coc:warning`` or ``warning``, ``coc:error`` or ``error``.
+ '''
+ segments = []
+ if not vim_command_exists('CocCommand'):
+ return segments
+ coc_status = vim.eval('coc#status()'),
+ errors_count, warnings_count = parse_coc_status(coc_status)
+ if errors_count > 0:
+ segments.append({
+ 'contents': 'E:' + str(errors_count),
+ 'highlight_groups': ['coc:error', 'error'],
+ })
+ if warnings_count > 0:
+ segments.append({
+ 'contents': 'W:' + str(warnings_count),
+ 'highlight_groups': ['coc:warning', 'warning'],
+ })
+ return segments
diff --git a/powerline/segments/vim/plugin/commandt.py b/powerline/segments/vim/plugin/commandt.py
new file mode 100644
index 0000000..7e5262e
--- /dev/null
+++ b/powerline/segments/vim/plugin/commandt.py
@@ -0,0 +1,97 @@
+# 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 create_ruby_dpowerline
+
+
+def initialize():
+ global initialized
+ if initialized:
+ return
+ initialized = True
+ create_ruby_dpowerline()
+ vim.command((
+ # When using :execute (vim.command uses the same code) one should not
+ # use << EOF.
+ '''
+ ruby
+ if (not ($command_t.respond_to? 'active_finder'))
+ def $command_t.active_finder
+ @active_finder and @active_finder.class.name or ''
+ end
+ end
+ if (not ($command_t.respond_to? 'path'))
+ def $command_t.path
+ @path or ''
+ end
+ end
+ def $powerline.commandt_set_active_finder
+ ::VIM::command "let g:powerline_commandt_reply = '#{$command_t.active_finder}'"
+ end
+ def $powerline.commandt_set_path
+ ::VIM::command "let g:powerline_commandt_reply = '#{($command_t.path or '').gsub(/'/, "''")}'"
+ end
+ '''
+ ))
+
+
+initialized = False
+
+
+def finder(pl):
+ '''Display Command-T finder name
+
+ Requires $command_t.active_finder and methods (code above may monkey-patch
+ $command_t to add them). All Command-T finders have ``CommandT::`` module
+ prefix, but it is stripped out (actually, any ``CommandT::`` substring will
+ be stripped out).
+
+ Highlight groups used: ``commandt:finder``.
+ '''
+ initialize()
+ vim.command('ruby $powerline.commandt_set_active_finder')
+ return [{
+ 'highlight_groups': ['commandt:finder'],
+ 'contents': vim.eval('g:powerline_commandt_reply').replace('CommandT::', '').replace('Finder::', '')
+ }]
+
+
+FINDERS_WITHOUT_PATH = set((
+ 'CommandT::MRUBufferFinder',
+ 'CommandT::BufferFinder',
+ 'CommandT::TagFinder',
+ 'CommandT::JumpFinder',
+ 'CommandT::Finder::MRUBufferFinder',
+ 'CommandT::Finder::BufferFinder',
+ 'CommandT::Finder::TagFinder',
+ 'CommandT::Finder::JumpFinder',
+))
+
+
+def path(pl):
+ '''Display path used by Command-T
+
+ Requires $command_t.active_finder and .path methods (code above may
+ monkey-patch $command_t to add them).
+
+ $command_t.active_finder is required in order to omit displaying path for
+ finders ``MRUBufferFinder``, ``BufferFinder``, ``TagFinder`` and
+ ``JumpFinder`` (pretty much any finder, except ``FileFinder``).
+
+ Highlight groups used: ``commandt:path``.
+ '''
+ initialize()
+ vim.command('ruby $powerline.commandt_set_active_finder')
+ finder = vim.eval('g:powerline_commandt_reply')
+ if finder in FINDERS_WITHOUT_PATH:
+ return None
+ vim.command('ruby $powerline.commandt_set_path')
+ return [{
+ 'highlight_groups': ['commandt:path'],
+ 'contents': vim.eval('g:powerline_commandt_reply')
+ }]
diff --git a/powerline/segments/vim/plugin/nerdtree.py b/powerline/segments/vim/plugin/nerdtree.py
new file mode 100644
index 0000000..f11be14
--- /dev/null
+++ b/powerline/segments/vim/plugin/nerdtree.py
@@ -0,0 +1,25 @@
+# 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 bufvar_exists
+from powerline.segments.vim import window_cached
+
+
+@window_cached
+def nerdtree(pl):
+ '''Return directory that is shown by the current buffer.
+
+ Highlight groups used: ``nerdtree:path`` or ``file_name``.
+ '''
+ if not bufvar_exists(None, 'NERDTreeRoot'):
+ return None
+ path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()')
+ return [{
+ 'contents': path_str,
+ 'highlight_groups': ['nerdtree:path', 'file_name'],
+ }]
diff --git a/powerline/segments/vim/plugin/syntastic.py b/powerline/segments/vim/plugin/syntastic.py
new file mode 100644
index 0000000..5bef3c7
--- /dev/null
+++ b/powerline/segments/vim/plugin/syntastic.py
@@ -0,0 +1,43 @@
+# vim:fileencoding=utf-8:noet
+from __future__ import (unicode_literals, division, absolute_import, print_function)
+
+try:
+ import vim
+except ImportError:
+ vim = object()
+
+from powerline.segments.vim import window_cached
+from powerline.bindings.vim import vim_global_exists
+
+
+@window_cached
+def syntastic(pl, err_format='ERR:  {first_line} ({num}) ', warn_format='WARN:  {first_line} ({num}) '):
+ '''Show whether syntastic has found any errors or warnings
+
+ :param str err_format:
+ Format string for errors.
+
+ :param str warn_format:
+ Format string for warnings.
+
+ Highlight groups used: ``syntastic:warning`` or ``warning``, ``syntastic:error`` or ``error``.
+ '''
+ if not vim_global_exists('SyntasticLoclist'):
+ return None
+ has_errors = int(vim.eval('g:SyntasticLoclist.current().hasErrorsOrWarningsToDisplay()'))
+ if not has_errors:
+ return
+ errors = vim.eval('g:SyntasticLoclist.current().errors()')
+ warnings = vim.eval('g:SyntasticLoclist.current().warnings()')
+ segments = []
+ if errors:
+ segments.append({
+ 'contents': err_format.format(first_line=errors[0]['lnum'], num=len(errors)),
+ 'highlight_groups': ['syntastic:error', 'error'],
+ })
+ if warnings:
+ segments.append({
+ 'contents': warn_format.format(first_line=warnings[0]['lnum'], num=len(warnings)),
+ 'highlight_groups': ['syntastic:warning', 'warning'],
+ })
+ return segments
diff --git a/powerline/segments/vim/plugin/tagbar.py b/powerline/segments/vim/plugin/tagbar.py
new file mode 100644
index 0000000..e683758
--- /dev/null
+++ b/powerline/segments/vim/plugin/tagbar.py
@@ -0,0 +1,51 @@
+# 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_command_exists, vim_get_autoload_func
+from powerline.theme import requires_segment_info
+
+
+currenttag = None
+tag_cache = {}
+
+
+@requires_segment_info
+def current_tag(segment_info, pl, flags='s'):
+ '''Return tag that is near the cursor.
+
+ :param str flags:
+ Specifies additional properties of the displayed tag. Supported values:
+
+ * s - display complete signature
+ * f - display the full hierarchy of the tag
+ * p - display the raw prototype
+
+ More info in the `official documentation`_ (search for
+ “tagbar#currenttag”).
+
+ .. _`official documentation`: https://github.com/majutsushi/tagbar/blob/master/doc/tagbar.txt
+ '''
+ 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 vim_command_exists('Tagbar'):
+ currenttag = vim_get_autoload_func('tagbar#currenttag')
+ if not currenttag:
+ return None
+ else:
+ return None
+ 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