Ejemplo n.º 1
0
	def render(self, window=None, window_id=None, winnr=None, is_tabline=False):
		'''Render all segments.'''
		segment_info = self.segment_info.copy()

		if window is vim.current.window:
			mode = vim_mode()
			mode = mode_translations.get(mode, mode)
		else:
			mode = 'nc'

		segment_info.update(
			window=window,
			mode=mode,
			window_id=window_id,
			winnr=winnr,
			buffer=window.buffer,
			tabpage=current_tabpage(),
			encoding=self.encoding,
		)
		segment_info['tabnr'] = segment_info['tabpage'].number
		segment_info['bufnr'] = segment_info['buffer'].number
		if is_tabline:
			winwidth = int(vim_getoption('columns'))
		else:
			winwidth = segment_info['window'].width

		statusline = super(VimRenderer, self).render(
			mode=mode,
			width=winwidth,
			segment_info=segment_info,
			matcher_info=(None if is_tabline else segment_info),
		)
		statusline = statusline.encode(self.encoding, self.strwidth_error_name)
		return statusline
Ejemplo n.º 2
0
def tablister(pl, segment_info, **kwargs):
    '''List all tab pages in segment_info format

	Specifically generates a list of segment info dictionaries with ``window``, 
	``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local 
	ones and additional ``tabpage`` and ``tabnr`` keys.

	Adds either ``tab:`` or ``tab_nc:`` prefix to all segment highlight groups.

	Works best with vim-7.4 or later: earlier versions miss tabpage object and 
	thus window objects are not available as well.
	'''
    cur_tabpage = current_tabpage()
    cur_tabnr = cur_tabpage.number

    def add_multiplier(tabpage, dct):
        dct['priority_multiplier'] = 1 + (0.001 *
                                          abs(tabpage.number - cur_tabnr))
        return dct

    return ((lambda tabpage, prefix:
             (tabpage_updated_segment_info(segment_info, tabpage),
              add_multiplier(
                  tabpage, {
                      'highlight_group_prefix': prefix,
                      'divider_highlight_group': 'tab:divider'
                  })))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
            for tabpage in list_tabpages())
Ejemplo n.º 3
0
	def render(self, window=None, window_id=None, winnr=None, is_tabline=False):
		'''Render all segments.'''
		segment_info = self.segment_info.copy()

		if window is vim.current.window:
			mode = vim_mode()
			mode = mode_translations.get(mode, mode)
		else:
			mode = 'nc'

		segment_info.update(
			window=window,
			mode=mode,
			window_id=window_id,
			winnr=winnr,
			buffer=window.buffer,
			tabpage=current_tabpage(),
			encoding=self.encoding,
		)
		segment_info['tabnr'] = segment_info['tabpage'].number
		segment_info['bufnr'] = segment_info['buffer'].number
		if is_tabline:
			winwidth = int(vim_getoption('columns'))
		else:
			winwidth = segment_info['window'].width

		statusline = super(VimRenderer, self).render(
			mode=mode,
			width=winwidth,
			segment_info=segment_info,
			matcher_info=(None if is_tabline else segment_info),
		)
		statusline = statusline.encode(self.encoding, self.strwidth_error_name)
		return statusline
Ejemplo n.º 4
0
def tablister(pl, segment_info, **kwargs):
	'''List all tab pages in segment_info format

	Specifically generates a list of segment info dictionaries with ``window``, 
	``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local 
	ones and additional ``tabpage`` and ``tabnr`` keys.

	Sets segment ``mode`` to either ``tab`` (for current tab page) or ``tab_nc`` 
	(for all other tab pages).

	Works best with vim-7.4 or later: earlier versions miss tabpage object and 
	thus window objects are not available as well.
	'''
	cur_tabpage = current_tabpage()
	cur_tabnr = cur_tabpage.number

	def add_multiplier(tabpage, dct):
		dct['priority_multiplier'] = 1 + (0.001 * abs(tabpage.number - cur_tabnr))
		return dct

	return (
		(lambda tabpage, mode: (
			tabpage_updated_segment_info(segment_info, tabpage, mode),
			add_multiplier(tabpage, {'mode': mode})
		))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
		for tabpage in list_tabpages()
	)
Ejemplo n.º 5
0
def tablister(pl, segment_info, **kwargs):
    '''List all tab pages in segment_info format

	Specifically generates a list of segment info dictionaries with ``window``, 
	``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local 
	ones and additional ``tabpage`` and ``tabnr`` keys.

	Sets segment ``mode`` to either ``tab`` (for current tab page) or ``tab_nc`` 
	(for all other tab pages).

	Works best with vim-7.4 or later: earlier versions miss tabpage object and 
	thus window objects are not available as well.
	'''
    cur_tabpage = current_tabpage()
    cur_tabnr = cur_tabpage.number

    def add_multiplier(tabpage, dct):
        dct['priority_multiplier'] = 1 + (0.001 *
                                          abs(tabpage.number - cur_tabnr))
        return dct

    return ((lambda tabpage, mode:
             (tabpage_updated_segment_info(segment_info, tabpage, mode),
              add_multiplier(tabpage, {'mode': mode})))(
                  tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
            for tabpage in list_tabpages())
Ejemplo n.º 6
0
def tablister(pl, segment_info, **kwargs):
	'''List all tab pages in segment_info format

	Specifically generates a list of segment info dictionaries with ``window``, 
	``winnr``, ``window_id``, ``buffer`` and ``bufnr`` keys set to tab-local 
	ones and additional ``tabpage`` and ``tabnr`` keys.

	Adds either ``tab:`` or ``tab_nc:`` prefix to all segment highlight groups.

	Works best with vim-7.4 or later: earlier versions miss tabpage object and 
	thus window objects are not available as well.
	'''
	cur_tabpage = current_tabpage()
	cur_tabnr = cur_tabpage.number

	def add_multiplier(tabpage, dct):
		dct['priority_multiplier'] = 1 + (0.001 * abs(tabpage.number - cur_tabnr))
		return dct

	return (
		(lambda tabpage, prefix: (
			tabpage_updated_segment_info(segment_info, tabpage),
			add_multiplier(tabpage, {'highlight_group_prefix': prefix})
		))(tabpage, 'tab' if tabpage == cur_tabpage else 'tab_nc')
		for tabpage in list_tabpages()
	)
Ejemplo n.º 7
0
def tabnr(pl, segment_info, show_current=True):
    '''Show tabpage number

	:param bool show_current:
		If False do not show current tabpage number. This is default because
		tabnr is by default only present in tabline.
	'''
    try:
        tabnr = segment_info['tabnr']
    except KeyError:
        return None
    if show_current or tabnr != current_tabpage().number:
        return str(tabnr)
Ejemplo n.º 8
0
def tabnr(pl, segment_info, show_current=True):
	'''Show tabpage number

	:param bool show_current:
		If False do not show current tabpage number. This is default because 
		tabnr is by default only present in tabline.
	'''
	try:
		tabnr = segment_info['tabnr']
	except KeyError:
		return None
	if show_current or tabnr != current_tabpage().number:
		return str(tabnr)