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(vim_getbufoption(segment_info, "modified")) else None
def csv_col_current(pl, segment_info, display_name='auto', name_format=' ({column_name:.15})'): '''Display CSV column number and column name Requires filetype to be set to ``csv``. :param bool or str name: May be ``True``, ``False`` and ``"auto"``. In the first case value from the first raw will always be displayed. In the second case it will never be displayed. In the last case ``csv.Sniffer().has_header()`` will be used to detect whether current file contains header in the first column. :param str name_format: String used to format column name (in case ``display_name`` is set to ``True`` or ``"auto"``). Accepts ``column_name`` keyword argument. Highlight groups used: ``csv:column_number`` or ``csv``, ``csv:column_name`` or ``csv``. ''' if vim_getbufoption(segment_info, 'filetype') != 'csv': return None line, col = segment_info['window'].cursor column_number, column_name = process_csv_buffer(pl, segment_info['buffer'], line, col, display_name) if not column_number: return None return [{ 'contents': column_number, 'highlight_groups': ['csv:column_number', 'csv'], }] + ([{ 'contents': name_format.format(column_name=column_name), 'highlight_groups': ['csv:column_name', 'csv'], }] if column_name else [])
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(vim_getbufoption(segment_info, 'readonly')) 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(vim_getbufoption(segment_info, 'modified')) else None
def csv_col_current(pl, segment_info, display_name='auto', name_format=' ({column_name:.15})'): '''Display CSV column number and column name Requires filetype to be set to ``csv``. :param bool or str name: May be ``True``, ``False`` and ``"auto"``. In the first case value from the first raw will always be displayed. In the second case it will never be displayed. In thi last case ``csv.Sniffer().has_header()`` will be used to detect whether current file contains header in the first column. :param str name_format: String used to format column name (in case ``display_name`` is set to ``True`` or ``"auto"``). Accepts ``column_name`` keyword argument. Highlight groups used: ``csv:column_number`` or ``csv``, ``csv:column_name`` or ``csv``. ''' if vim_getbufoption(segment_info, 'filetype') != 'csv': return None line, col = segment_info['window'].cursor column_number, column_name = process_csv_buffer(pl, segment_info['buffer'], line, col, display_name) if not column_number: return None return [{ 'contents': column_number, 'highlight_groups': ['csv:column_number', 'csv'], }] + ([{ 'contents': name_format.format(column_name=column_name), 'highlight_groups': ['csv:column_name', 'csv'], }] if column_name else [])
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 vim_getbufoption(segment_info, '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 bufferlister(pl, segment_info, show_unlisted=False, **kwargs): '''List all buffers in segment_info format Specifically generates a list of segment info dictionaries with ``buffer`` and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and ``window_id`` keys set to None. Adds either ``buf:`` or ``buf_nc:`` prefix to all segment highlight groups. :param bool show_unlisted: True if unlisted buffers should be shown as well. Current buffer is always shown. ''' cur_buffer = vim.current.buffer cur_bufnr = cur_buffer.number def add_multiplier(buffer, dct): dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr)) return dct return ((buf_segment_info, add_multiplier(buf_segment_info['buffer'], {'highlight_group_prefix': prefix})) for buf_segment_info, prefix in ( (buffer_updated_segment_info(segment_info, buffer), ('buf' if buffer is cur_buffer else 'buf_nc')) for buffer in vim.buffers) if (buf_segment_info['buffer'] is cur_buffer or show_unlisted or int(vim_getbufoption(buf_segment_info, 'buflisted'))))
def readonly_indicator(pl, segment_info, text='RO'): '''Return a read-only indicator. :param string text: text to display if the current buffer is read-only ''' return text if int(vim_getbufoption(segment_info, 'readonly')) else None
def bufferlister(pl, segment_info, show_unlisted=False, **kwargs): '''List all buffers in segment_info format Specifically generates a list of segment info dictionaries with ``buffer`` and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and ``window_id`` keys set to None. Sets segment ``mode`` to either ``buf`` (for current buffer) or ``buf_nc`` (for all other buffers). :param bool show_unlisted: True if unlisted buffers should be shown as well. Current buffer is always shown. ''' cur_buffer = vim.current.buffer cur_bufnr = cur_buffer.number def add_multiplier(buffer, dct): dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr)) return dct return ((buf_segment_info, add_multiplier(buf_segment_info['buffer'], {'mode': buf_segment_info['mode']})) for buf_segment_info in ( buffer_updated_segment_info(segment_info, buffer, ( 'buf' if buffer is cur_buffer else 'buf_nc')) for buffer in vim.buffers) if (buf_segment_info['buffer'] is cur_buffer or show_unlisted or int(vim_getbufoption(buf_segment_info, 'buflisted'))))
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 vim_getbufoption(segment_info, '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(vim_getbufoption(segment_info, "readonly")) else None
def file_bom(pl, segment_info): '''Return BOM of the current file :return: Byte order mark or None if unknown or missing BOM Divider highlight group used: ``background:divider``. ''' return 'bom' if vim_getbufoption(segment_info, 'bomb') else 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 vim_getbufoption(segment_info, '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 vim_getbufoption(segment_info, 'fileencoding') 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 vim_getbufoption(segment_info, 'filetype') or None
def tab_modified_indicator(pl, segment_info, text='+'): '''Return a file modified indicator for tabpages. :param string text: text to display if any buffer in the current tab is modified Highlight groups used: ``tab_modified_indicator`` or ``modified_indicator``. ''' for buf_segment_info in list_tabpage_buffers_segment_info(segment_info): if int(vim_getbufoption(buf_segment_info, 'modified')): return [{ 'contents': text, 'highlight_groups': ['tab_modified_indicator', 'modified_indicator'], }] 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_mod_text = join_str.join(( str(buffer.number) for buffer in vim.buffers if int(vim_getbufoption({'buffer': buffer, 'bufnr': buffer.number}, 'modified')) )) if buffer_mod_text: return text + buffer_mod_text return None
def file_vcs_status(pl, segment_info, create_watcher): """Return the VCS status for this buffer. Highlight groups used: ``file_vcs_status``. """ name = segment_info["buffer"].name skip = not (name and (not vim_getbufoption(segment_info, "buftype"))) if not skip: repo = guess(path=name, create_watcher=create_watcher) 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, create_watcher): '''Return the VCS status for this buffer. Highlight groups used: ``file_vcs_status``. ''' name = buffer_name(segment_info) skip = not (name and (not vim_getbufoption(segment_info, 'buftype'))) if not skip: repo = guess(path=name, create_watcher=create_watcher) 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_groups': ['file_vcs_status_' + status, 'file_vcs_status'], }) return ret
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 vim_getbufoption(segment_info, '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 branch(pl, segment_info, create_watcher, 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 vim_getbufoption(segment_info, "buftype"))) if not skip: repo = guess(path=name, create_watcher=create_watcher) 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 bufferlister(pl, segment_info, show_unlisted=False, **kwargs): '''List all buffers in segment_info format Specifically generates a list of segment info dictionaries with ``buffer`` and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and ``window_id`` keys set to None. Adds either ``buf:`` or ``buf_nc:`` prefix to all segment highlight groups. :param bool show_unlisted: True if unlisted buffers should be shown as well. Current buffer is always shown. ''' cur_buffer = vim.current.buffer cur_bufnr = cur_buffer.number def add_multiplier(buffer, dct): dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr)) return dct return ( ( buf_segment_info, add_multiplier(buf_segment_info['buffer'], {'highlight_group_prefix': prefix}) ) for buf_segment_info, prefix in ( ( buffer_updated_segment_info( segment_info, buffer ), ('buf' if buffer is cur_buffer else 'buf_nc') ) for buffer in vim.buffers ) if ( buf_segment_info['buffer'] is cur_buffer or show_unlisted or int(vim_getbufoption(buf_segment_info, 'buflisted')) ) )
def bufferlister(pl, segment_info, show_unlisted=False, **kwargs): '''List all buffers in segment_info format Specifically generates a list of segment info dictionaries with ``buffer`` and ``bufnr`` keys set to buffer-specific ones, ``window``, ``winnr`` and ``window_id`` keys set to None. Sets segment ``mode`` to either ``buf`` (for current buffer) or ``buf_nc`` (for all other buffers). :param bool show_unlisted: True if unlisted buffers should be shown as well. Current buffer is always shown. ''' cur_buffer = vim.current.buffer cur_bufnr = cur_buffer.number def add_multiplier(buffer, dct): dct['priority_multiplier'] = 1 + (0.001 * abs(buffer.number - cur_bufnr)) return dct return ( ( buf_segment_info, add_multiplier(buf_segment_info['buffer'], {'mode': buf_segment_info['mode']}) ) for buf_segment_info in ( buffer_updated_segment_info( segment_info, buffer, ('buf' if buffer is cur_buffer else 'buf_nc') ) for buffer in vim.buffers ) if ( buf_segment_info['buffer'] is cur_buffer or show_unlisted or int(vim_getbufoption(buf_segment_info, 'buflisted')) ) )
def calc(matcher_info): return vim_getbufoption(matcher_info, 'filetype') == 'vimcalc'
def vimshell(matcher_info): return vim_getbufoption(matcher_info, 'filetype') == 'vimshell'
def ref_perldoc(matcher_info): return vim_getbufoption(matcher_info, 'filetype') == 'ref-perldoc'
def commandt(matcher_info): name = buffer_name(matcher_info) return ( vim_getbufoption(matcher_info, 'filetype') == 'command-t' or (name and os.path.basename(name) == b'GoToFile') )
def help(matcher_info): return vim_getbufoption(matcher_info, 'buftype') == 'help'
def get_directory(segment_info): if vim_getbufoption(segment_info, 'buftype'): return None return buffer_name(segment_info)
def help(matcher_info): return str(vim_getbufoption(matcher_info, "buftype")) == "help"
def test_help(matcher_info): return str(vim_getbufoption(matcher_info, 'buftype')) == 'help'
def gitcommit(matcher_info): return vim_getbufoption(matcher_info, 'filetype') == 'gitcommit'
def unite(matcher_info): return vim_getbufoption(matcher_info, 'filetype') == 'unite'
def quickfix(matcher_info): return str(vim_getbufoption(matcher_info, "buftype")) == "quickfix"
def quickfix(matcher_info): return str(vim_getbufoption(matcher_info, 'buftype')) == 'quickfix'
def help(matcher_info): return str(vim_getbufoption(matcher_info, 'buftype')) == 'help'