def ctrlp(pl, side): ''' Highlight groups used: ``ctrlp:regex`` or ``background``, ``ctrlp:prev`` or ``background``, ``ctrlp:item`` or ``file_name``, ``ctrlp:next`` or ``background``, ``ctrlp:marked`` or ``background``, ``ctrlp:focus`` or ``background``, ``ctrlp:byfname`` or ``background``, ``ctrlp:progress`` or ``file_name``, ``ctrlp:progress`` or ``file_name``. ''' ctrlp_type = getbufvar('%', 'powerline_ctrlp_type') ctrlp_args = getbufvar('%', 'powerline_ctrlp_args') return globals()['ctrlp_stl_{0}_{1}'.format(side, ctrlp_type)](pl, *ctrlp_args)
def ctrlp(pl, side): ''' Highlight groups used: ``ctrlp.regex`` or ``background``, ``ctrlp.prev`` or ``background``, ``ctrlp.item`` or ``file_name``, ``ctrlp.next`` or ``background``, ``ctrlp.marked`` or ``background``, ``ctrlp.focus`` or ``background``, ``ctrlp.byfname`` or ``background``, ``ctrlp.progress`` or ``file_name``, ``ctrlp.progress`` or ``file_name``. ''' ctrlp_type = getbufvar('%', 'powerline_ctrlp_type') ctrlp_args = getbufvar('%', 'powerline_ctrlp_args') return globals()['ctrlp_stl_{0}_{1}'.format(side, ctrlp_type)](pl, *ctrlp_args)
def modified_indicator(pl, segment_info, text="+"): """Return a file modified indicator. :param string text: text to display if the current buffer is modified """ return text if int(getbufvar(segment_info["bufnr"], "&modified")) else None
def paste_indicator(segment_info, text='PASTE'): '''Return a paste mode indicator. :param string text: text to display if paste mode is enabled ''' return text if int(getbufvar(segment_info['bufnr'], '&paste')) else None
def modified_indicator(segment_info, text='+'): '''Return a file modified indicator. :param string text: text to display if the current buffer is modified ''' return text if int(getbufvar(segment_info['bufnr'], '&modified')) else None
def modified_indicator(pl, segment_info, text='+'): '''Return a file modified indicator. :param string text: text to display if the current buffer is modified ''' return text if int(getbufvar(segment_info['bufnr'], '&modified')) else None
def branch(pl, segment_info, status_colors=True): '''Return the current working branch. :param bool status_colors: determines whether repository status will be used to determine highlighting. Default: False. Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``. Divider highlight group used: ``branch:divider``. ''' name = segment_info['buffer'].name skip = not (name and (not getbufvar(segment_info['bufnr'], '&buftype'))) if not skip: repo = guess(path=name) if repo is not None: branch = repo.branch() scol = ['branch'] if status_colors: status = tree_status(repo, pl) scol.insert(0, 'branch_dirty' if status and status.strip() else 'branch_clean') return [{ 'contents': branch, 'highlight_group': scol, 'divider_highlight_group': 'branch:divider', }]
def readonly_indicator(pl, segment_info, text=''): '''Return a read-only indicator. :param string text: text to display if the current buffer is read-only ''' return text if int(getbufvar(segment_info['bufnr'], '&readonly')) else None
def readonly_indicator(segment_info, text=''): '''Return a read-only indicator. :param string text: text to display if the current buffer is read-only ''' return text if int(getbufvar(segment_info['bufnr'], '&readonly')) else None
def branch(pl, segment_info, status_colors=False): '''Return the current working branch. :param bool status_colors: determines whether repository status will be used to determine highlighting. Default: False. Highlight groups used: ``branch_clean``, ``branch_dirty``, ``branch``. Divider highlight group used: ``branch:divider``. ''' name = segment_info['buffer'].name skip = not (name and (not getbufvar(segment_info['bufnr'], '&buftype'))) if not skip: repo = guess(path=name) if repo is not None: branch = repo.branch() scol = ['branch'] if status_colors: status = tree_status(repo, pl) scol.insert( 0, 'branch_dirty' if status and status.strip() else 'branch_clean') return [{ 'contents': branch, 'highlight_group': scol, 'divider_highlight_group': 'branch:divider', }]
def readonly_indicator(pl, segment_info, text=""): """Return a read-only indicator. :param string text: text to display if the current buffer is read-only """ return text if int(getbufvar(segment_info["bufnr"], "&readonly")) else None
def render(self, update_value, only_ruby=True, **kwargs): ret = [{'contents': update_value, 'highlight_group': ['ruby_version']}] if only_ruby: ft = getbufvar('%', '&ft') if not ft.find('ruby') >= 0: ret = None return ret
def file_type(pl, segment_info): '''Return file type. :return: file type or None if unknown file type Divider highlight group used: ``background:divider``. ''' return getbufvar(segment_info['bufnr'], '&filetype') or None
def file_encoding(pl, segment_info): '''Return file encoding/character set. :return: file encoding/character set or None if unknown or missing file encoding Divider highlight group used: ``background:divider``. ''' return getbufvar(segment_info['bufnr'], '&fileencoding') or None
def file_format(pl, segment_info): '''Return file format (i.e. line ending type). :return: file format or None if unknown or missing file format Divider highlight group used: ``background:divider``. ''' return getbufvar(segment_info['bufnr'], '&fileformat') or None
def file_encoding(pl, segment_info): """Return file encoding/character set. :return: file encoding/character set or None if unknown or missing file encoding Divider highlight group used: ``background:divider``. """ return getbufvar(segment_info["bufnr"], "&fileencoding") or None
def file_format(pl, segment_info): """Return file format (i.e. line ending type). :return: file format or None if unknown or missing file format Divider highlight group used: ``background:divider``. """ return getbufvar(segment_info["bufnr"], "&fileformat") or None
def file_type(pl, segment_info): """Return file type. :return: file type or None if unknown file type Divider highlight group used: ``background:divider``. """ return getbufvar(segment_info["bufnr"], "&filetype") or None
def nerdtree(pl): ntr = getbufvar('%', 'NERDTreeRoot') if not ntr: return path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()') return [{ 'contents': path_str, 'highlight_group': ['nerdtree.path', 'file_name'], }]
def modified_buffers(text='+ ', join_str=','): '''Return a comma-separated list of modified buffers. :param str text: text to display before the modified buffer list :param str join_str: string to use for joining the modified buffer list ''' buffer_len = vim_funcs['bufnr']('$') buffer_mod = [str(bufnr) for bufnr in range(1, buffer_len + 1) if int(getbufvar(bufnr, '&modified') or 0)] if buffer_mod: return text + join_str.join(buffer_mod) return None
def modified_buffers(pl, text="+ ", join_str=","): """Return a comma-separated list of modified buffers. :param str text: text to display before the modified buffer list :param str join_str: string to use for joining the modified buffer list """ buffer_len = vim_funcs["bufnr"]("$") buffer_mod = [str(bufnr) for bufnr in range(1, buffer_len + 1) if int(getbufvar(bufnr, "&modified") or 0)] if buffer_mod: return text + join_str.join(buffer_mod) return None
def nerdtree(pl): '''Return directory that is shown by the current buffer. Highlight groups used: ``nerdtree.path`` or ``file_name``. ''' ntr = getbufvar('%', 'NERDTreeRoot') if not ntr: return path_str = vim.eval('getbufvar("%", "NERDTreeRoot").path.str()') return [{ 'contents': path_str, 'highlight_group': ['nerdtree.path', 'file_name'], }]
def modified_buffers(pl, text='+ ', join_str=','): '''Return a comma-separated list of modified buffers. :param str text: text to display before the modified buffer list :param str join_str: string to use for joining the modified buffer list ''' buffer_len = vim_funcs['bufnr']('$') buffer_mod = [str(bufnr) for bufnr in range(1, buffer_len + 1) if int(getbufvar(bufnr, '&modified') or 0)] if buffer_mod: return text + join_str.join(buffer_mod) return None
def file_format(segment_info, expected=["unix"], unknown_text="unknown", **extra): """Return file format (i.e. line ending type). :return: file format or None if unknown or missing file format Divider highlight group used: ``background:divider``. """ fmt = getbufvar(segment_info["bufnr"], "&fileformat") if fmt in expected: return None else: return fmt or unknown_text
def virtcol_current(pl, gradient=True): '''Return current visual column with concealed characters ingored :param bool gradient: Determines whether it should show textwidth-based gradient (gradient level is ``virtcol * 100 / textwidth``). Highlight groups used: ``virtcol_current_gradient`` (gradient), ``virtcol_current`` or ``col_current``. ''' col = vim_funcs['virtcol']('.') r = [{'contents': str(col), 'highlight_group': ['virtcol_current', 'col_current']}] if gradient: textwidth = int(getbufvar('%', '&textwidth')) r[-1]['gradient_level'] = min(col * 100 / textwidth, 100) if textwidth else 0 r[-1]['highlight_group'].insert(0, 'virtcol_current_gradient') return r
def virtcol_current(pl, gradient=True): '''Return current visual column with concealed characters ingored :param bool gradient: Determines whether it should show textwidth-based gradient (gradient level is ``virtcol * 100 / textwidth``). Highlight groups used: ``virtcol_current_gradient`` (gradient), ``virtcol_current`` or ``col_current``. ''' col = vim_funcs['virtcol']('.') r = [{'contents': str(col), 'highlight_groups': ['virtcol_current', 'col_current']}] if gradient: textwidth = int(getbufvar('%', '&textwidth')) r[-1]['gradient_level'] = min(col * 100 / textwidth, 100) if textwidth else 0 r[-1]['highlight_groups'].insert(0, 'virtcol_current_gradient') return r
def virtcol_current(pl, gradient=True): """Return current visual column with concealed characters ingored :param bool gradient: Determines whether it should show textwidth-based gradient (gradient level is ``virtcol * 100 / textwidth``). Highlight groups used: ``virtcol_current_gradient`` (gradient), ``virtcol_current`` or ``col_current``. """ col = vim_funcs["virtcol"](".") r = [{"contents": str(col), "highlight_group": ["virtcol_current", "col_current"]}] if gradient: textwidth = int(getbufvar("%", "&textwidth")) r[-1]["gradient_level"] = min(col * 100 / textwidth, 100) if textwidth else 0 r[-1]["highlight_group"].insert(0, "virtcol_current_gradient") return r
def col_current_virt(pl, gradient=True): '''Return the current cursor column. Since default 'col_current()' function returns current OR virtual column only, this function returns current AND virtual columns. ''' virtcol = str(vim_funcs['virtcol']('.')) col = str(vim_funcs['col']('.')) res = [{'contents': col if virtcol == col else col + '-' + virtcol, 'highlight_group': ['virtcol_current', 'col_current']}] if gradient: textwidth = int(getbufvar('%', '&textwidth')) res[-1]['gradient_level'] = min(int(virtcol) * 100 / textwidth, 100) \ if textwidth else 0 res[-1]['highlight_group'].insert(0, 'virtcol_current_gradient') return res
def file_encoding(segment_info, expected=["utf-8"], unknown_text="unknown", **extra): """Return file encoding/character set. :return: file encoding/character set or None if unknown or missing file encoding Divider highlight group used: ``background:divider``. """ enc = getbufvar(segment_info["bufnr"], "&fileencoding") if enc in expected: return None else: if enc: return enc else: return unknown_text
def trailing_whitespace(pl, segment_info): '''Return the line number for trailing whitespaces It is advised not to use this segment in insert mode: in Insert mode it will iterate over all lines in buffer each time you happen to type a character which may cause lags. It will also show you whitespace warning each time you happen to type space. Highlight groups used: ``trailing_whitespace`` or ``warning``. ''' global trailing_whitespace_cache if trailing_whitespace_cache is None: trailing_whitespace_cache = register_buffer_cache( defaultdict(lambda: (0, None))) bufnr = segment_info['bufnr'] changedtick = getbufvar(bufnr, 'changedtick') if trailing_whitespace_cache[bufnr][0] == changedtick: return trailing_whitespace_cache[bufnr][1] else: buf = segment_info['buffer'] bws = b' \t' sws = str(' \t') # Ignore unicode_literals and use native str. for i in range(len(buf)): try: line = buf[i] except UnicodeDecodeError: # May happen in Python 3 if hasattr(vim, 'bindeval'): line = vim.bindeval('getbufline({0}, {1})'.format( bufnr, i + 1)) has_trailing_ws = (line[-1] in bws) else: line = vim.eval('strtrans(getbufline({0}, {1}))'.format( bufnr, i + 1)) has_trailing_ws = (line[-1] in bws) else: has_trailing_ws = (line and line[-1] in sws) if has_trailing_ws: break if has_trailing_ws: ret = [{ 'contents': str(i + 1), 'highlight_groups': ['trailing_whitespace', 'warning'], }] else: ret = None trailing_whitespace_cache[bufnr] = (changedtick, ret) return ret
def file_format(segment_info, expected=['unix'], unknown_text='unknown', **extra): '''Return file format (i.e. line ending type). :return: file format or None if unknown or missing file format Divider highlight group used: ``background:divider``. ''' fmt = getbufvar(segment_info['bufnr'], '&fileformat') if fmt in expected: return None else: return fmt or unknown_text
def trailing_whitespace(pl, segment_info): '''Return the line number for trailing whitespaces It is advised not to use this segment in insert mode: in Insert mode it will iterate over all lines in buffer each time you happen to type a character which may cause lags. It will also show you whitespace warning each time you happen to type space. Highlight groups used: ``trailing_whitespace`` or ``warning``. ''' global trailing_whitespace_cache if trailing_whitespace_cache is None: trailing_whitespace_cache = register_buffer_cache(defaultdict(lambda: (0, None))) bufnr = segment_info['bufnr'] changedtick = getbufvar(bufnr, 'changedtick') if trailing_whitespace_cache[bufnr][0] == changedtick: return trailing_whitespace_cache[bufnr][1] else: buf = segment_info['buffer'] bws = b' \t' sws = str(bws) for i in range(len(buf)): try: line = buf[i] except UnicodeDecodeError: # May happen in Python 3 if hasattr(vim, 'bindeval'): line = vim.bindeval('getbufline({0}, {1})'.format( bufnr, i + 1)) has_trailing_ws = (line[-1] in bws) else: line = vim.eval('strtrans(getbufline({0}, {1}))'.format( bufnr, i + 1)) has_trailing_ws = (line[-1] in bws) else: has_trailing_ws = (line and line[-1] in sws) if has_trailing_ws: break if has_trailing_ws: ret = [{ 'contents': str(i + 1), 'highlight_groups': ['trailing_whitespace', 'warning'], }] else: ret = None trailing_whitespace_cache[bufnr] = (changedtick, ret) return ret
def file_vcs_status(segment_info): '''Return the VCS status for this buffer.''' name = segment_info['buffer'].name if name and not getbufvar(segment_info['bufnr'], '&buftype'): repo = guess(path=os.path.abspath(name)) if repo: status = repo.status(os.path.relpath(name, repo.directory)) if not status: return None status = status.strip() ret = [] for status in status: ret.append({ 'contents': status, 'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'], }) return ret return None
def file_encoding(segment_info, expected=['utf-8'], unknown_text='unknown', **extra): '''Return file encoding/character set. :return: file encoding/character set or None if unknown or missing file encoding Divider highlight group used: ``background:divider``. ''' enc = getbufvar(segment_info['bufnr'], '&fileencoding') if enc in expected: return None else: if enc: return enc else: return unknown_text
def commit_status(pl, segment_info): if str(vim.eval('exists("g:BCFCommitFileName")')) == '1': bcf_filename = vim.eval('g:BCFCommitFileName') if len(bcf_filename): bcf_list_contains_this_buffer = getbufvar(segment_info['bufnr'], 'BCFListContainsThisBuffer') if bcf_list_contains_this_buffer is not None: included_in_cl = int(bcf_list_contains_this_buffer) if included_in_cl == 1: bcf_status_symbol = "✔" else: bcf_status_symbol = "✘" bcf_status_string = bcf_status_symbol + ' ' + bcf_filename if len(bcf_status_string) > 40: bcf_status_string = bcf_status_string[:19] + '→' return [{ 'contents': bcf_status_string, 'highlight_group': [ 'background' ] }] return None
def file_vcs_status(pl, segment_info): '''Return the VCS status for this buffer. Highlight groups used: ``file_vcs_status``. ''' name = segment_info['buffer'].name skip = not (name and (not getbufvar(segment_info['bufnr'], '&buftype'))) if not skip: repo = guess(path=name) if repo is not None: status = repo.status(os.path.relpath(name, repo.directory)) if not status: return None status = status.strip() ret = [] for status in status: ret.append({ 'contents': status, 'highlight_group': ['file_vcs_status_' + status, 'file_vcs_status'], }) return ret
def file_vcs_status(pl, segment_info): if not segment_info['buffer'].name or getbufvar(segment_info['bufnr'], '&buftype'): return None funcs, fname = get_rf(segment_info['bufnr']) if not fname or not funcs: return None bsetup = setup_buffer(segment_info['bufnr'], 'status', funcs, fname) if bsetup is None: return None status = rc.get(bsetup) if not status or status == 'clean': return None statchar = status[0].upper() return [{ 'contents': statchar, 'highlight': ['file_vcs_status_'+statchar, 'file_vcs_status'] }]
def unite(matcher_info): return str(getbufvar(matcher_info['bufnr'], '&filetype')) == 'unite'
def vimfiler(matcher_info): return str(getbufvar(matcher_info['bufnr'], '&filetype')) == 'vimfiler'
def help(matcher_info): return str(getbufvar(matcher_info['bufnr'], '&buftype')) == 'help'
def ctrlp(pl, side): ctrlp_type = getbufvar('%', 'powerline_ctrlp_type') ctrlp_args = getbufvar('%', 'powerline_ctrlp_args') return globals()['ctrlp_stl_{0}_{1}'.format(side, ctrlp_type)](pl, *ctrlp_args)
def vimshell(matcher_info): return re.match(r'^(vimshell|int-\w*|term-\w*)$', str(getbufvar(matcher_info['bufnr'], '&filetype')))
def is_log(matcher_info): return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumlog'
def is_status(matcher_info): return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumstatus'
def is_annotate(matcher_info): return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumannotate'
def is_commit(matcher_info): return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumcommit'
def locationlist(matcher_info): return str(getbufvar(matcher_info['bufnr'], 'errorlist_type')) == 'location'
def nerdtree(matcher_info): return str(getbufvar(matcher_info['bufnr'], '&filetype')) == 'nerdtree'
def quickfix(matcher_info): return str(getbufvar(matcher_info['bufnr'], '&buftype')) == 'quickfix'
def quickfix(matcher_info): return str(getbufvar(matcher_info['bufnr'], 'errorlist_type')) == 'quickfix'