Esempio n. 1
0
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
Esempio n. 2
0
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 [])
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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 [])
Esempio n. 6
0
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',
            }]
Esempio n. 7
0
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'))))
Esempio n. 8
0
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
Esempio n. 9
0
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
Esempio n. 10
0
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'))))
Esempio n. 11
0
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',
			}]
Esempio n. 12
0
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
Esempio n. 13
0
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
Esempio n. 14
0
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
Esempio n. 15
0
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
Esempio n. 16
0
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
Esempio n. 17
0
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
Esempio n. 18
0
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
Esempio n. 19
0
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
Esempio n. 20
0
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
Esempio n. 21
0
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
Esempio n. 22
0
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
Esempio n. 23
0
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
Esempio n. 24
0
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
Esempio n. 25
0
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
Esempio n. 26
0
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
Esempio n. 27
0
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"}]
Esempio n. 28
0
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'))
		)
	)
Esempio n. 29
0
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'))
		)
	)
Esempio n. 30
0
def calc(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'vimcalc'
Esempio n. 31
0
def vimshell(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'vimshell'
Esempio n. 32
0
def ref_perldoc(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'ref-perldoc'
Esempio n. 33
0
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')
	)
Esempio n. 34
0
def help(matcher_info):
	return vim_getbufoption(matcher_info, 'buftype') == 'help'
Esempio n. 35
0
 def get_directory(segment_info):
     if vim_getbufoption(segment_info, 'buftype'):
         return None
     return buffer_name(segment_info)
Esempio n. 36
0
def help(matcher_info):
    return str(vim_getbufoption(matcher_info, "buftype")) == "help"
Esempio n. 37
0
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')
    )
Esempio n. 38
0
def test_help(matcher_info):
	return str(vim_getbufoption(matcher_info, 'buftype')) == 'help'
Esempio n. 39
0
def gitcommit(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'gitcommit'
Esempio n. 40
0
def calc(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'vimcalc'
Esempio n. 41
0
	def get_directory(segment_info):
		if vim_getbufoption(segment_info, 'buftype'):
			return None
		return buffer_name(segment_info)
Esempio n. 42
0
def ref_perldoc(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'ref-perldoc'
Esempio n. 43
0
def unite(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'unite'
Esempio n. 44
0
def gitcommit(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'gitcommit'
Esempio n. 45
0
def unite(matcher_info):
	return vim_getbufoption(matcher_info, 'filetype') == 'unite'
Esempio n. 46
0
def vimshell(matcher_info):
    return vim_getbufoption(matcher_info, 'filetype') == 'vimshell'
Esempio n. 47
0
def quickfix(matcher_info):
    return str(vim_getbufoption(matcher_info, "buftype")) == "quickfix"
Esempio n. 48
0
def quickfix(matcher_info):
	return str(vim_getbufoption(matcher_info, 'buftype')) == 'quickfix'
Esempio n. 49
0
def quickfix(matcher_info):
	return str(vim_getbufoption(matcher_info, 'buftype')) == 'quickfix'
Esempio n. 50
0
def help(matcher_info):
	return str(vim_getbufoption(matcher_info, 'buftype')) == 'help'