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 [])
评论列表
文章目录