Example #1
0
def get_tab(tabpage, tabpage_is_current):
    """Returns a string for each tab page, containing one or more buffer names.
  If the current window/buffer is active, wrap it around [].
  """
    fnames = []
    for window in tabpage.windows:
        window_is_current = tabpage_is_current and (
            window.number == vim.current.window.number)
        fname = os.path.basename(window.buffer.name)
        for pattern in EXCLUDE:
            if re.match(pattern, fname):
                break
        else:
            fname_parts = []
            fname_parts.append('[' if window_is_current else ' ')

            fname_buf_type = vim.call('getbufvar', window.buffer, '&buftype')
            if fname_buf_type == 'help':
                fname_parts.append('H:%s' % fname.split('.')[0])
            elif fname_buf_type == 'quickfix':
                fname_parts.append('Q')
            else:
                fname_parts.append(fname if fname else 'new')
                if vim.call('getbufvar', window.buffer, '&modified'):
                    fname_parts.append('*')

            fname_parts.append(']' if window_is_current else ' ')
            fnames.append(''.join(fname_parts))
    tab_str = ''.join(fnames)
    padding_left, padding_right = calc_padding(len(tab_str), DEFAULT_TAB_SIZE)
    return (tab_str, tabpage_is_current, padding_left, padding_right)
Example #2
0
def get_tab(tabpage, tabpage_is_current):
  """Returns a string for each tab page, containing one or more buffer names.
  If the current window/buffer is active, wrap it around [].
  """
  fnames = []
  for window in tabpage.windows:
    window_is_current = tabpage_is_current and (window.number == vim.current.window.number)
    fname = os.path.basename(window.buffer.name)
    for pattern in EXCLUDE:
      if re.match(pattern, fname):
        break
    else:
      fname_parts = []
      fname_parts.append('[' if window_is_current else ' ')

      fname_buf_type = vim.call('getbufvar', window.buffer, '&buftype')
      if fname_buf_type == 'help':
        fname_parts.append('H:%s' % fname.split('.')[0])
      elif fname_buf_type == 'quickfix':
        fname_parts.append('Q')
      else:
        fname_parts.append(fname if fname else 'new')
        if vim.call('getbufvar', window.buffer, '&modified'):
          fname_parts.append('*')

      fname_parts.append(']' if window_is_current else ' ')
      fnames.append(''.join(fname_parts))
  tab_str = ''.join(fnames)
  padding_left, padding_right = calc_padding(len(tab_str), DEFAULT_TAB_SIZE)
  return (tab_str, tabpage_is_current, padding_left, padding_right)
Example #3
0
    def on_complete(self, ctx):

        command = vim.call('tmuxcomplete#getcommand', '', 'words')
        words = check_output(['sh', '-c', command]
                             ).decode('utf-8').splitlines()
        matches = [{'word': x} for x in words]
        self.complete(ctx, ctx['startccol'], matches)
Example #4
0
    def determine_linenumber(self, import_statement: str) -> LineNumber:
        # If there is another import statement for the same package as the
        # given one, place nearby the import statement.
        # Otherwise, find the first non-empty, non-comment line and place there.
        buf = vim.current.buffer
        ln: LineNumber
        max_lines = 1000

        tokens = import_statement.split()
        if len(tokens) > 1:
            pkg = tokens[1]  # import <pkg>, from <pkg> import ...
            _line, _col = vim.call('line', '.'), vim.call('col', '.')
            try:
                vim.call('cursor', 1, 1)
                ln = vim.call('search', r'\v^(from|import) {}'.format(pkg),
                              'n', max_lines)
                if ln:  # a line for similar module was found
                    return ln
            finally:
                vim.call('cursor', _line, _col)

        # find a non-empty line
        for ln, bline in enumerate(buf, start=LineNumber(1)):
            if ln > max_lines: break  # do not scan too many lines

            if bline == '':
                continue
            if self.get_syngroup_at_line(ln) in self.AVOID_SYNGROUPS:
                continue
            return ln

        # cannot resolve, put in the topmost line
        return 1
Example #5
0
 def __init__(self):
     self.buffer = vim.current.buffer
     self.window = vim.current.window
     self.cursor = _SnippetUtilCursor(vim.current.window.cursor)
     self.line = vim.call("line", ".") - 1
     self.column = vim.call("col", ".") - 1
     line = vim.call("getline", ".")
     self.after = line[self.column :]
     if "coc_selected_text" in vim.vars:
         self.visual_mode = vim.eval("visualmode()")
         self.visual_text = vim.vars["coc_selected_text"]
     else:
         self.visual_mode = None
         self.visual_text = ""
     if "coc_last_placeholder" in vim.vars:
         p = vim.vars["coc_last_placeholder"]
         start = _Position(p["start"]["line"], p["start"]["col"])
         end = _Position(p["end"]["line"], p["end"]["col"])
         self.last_placeholder = _Placeholder(p["current_text"], start, end)
     else:
         self.last_placeholder = None
Example #6
0
 def __init__(self):
     self.buffer = vim.current.buffer
     self.window = vim.current.window
     self.cursor = _SnippetUtilCursor(vim.current.window.cursor)
     self.line = vim.call('line', '.') - 1
     self.column = vim.call('col', '.') - 1
     line = vim.call('getline', '.')
     self.after = line[self.column :]
     if 'coc_selected_text' in vim.vars:
         self.visual_mode = vim.eval('visualmode()')
         self.visual_text = vim.vars['coc_selected_text']
     else:
         self.visual_mode = None
         self.visual_text = ''
     if 'coc_last_placeholder' in vim.vars:
         p = vim.vars['coc_last_placeholder']
         start = _Position(p['start']['line'], p['start']['col'])
         end = _Position(p['end']['line'], p['end']['col'])
         self.last_placeholder = _Placeholder(p['current_text'], start, end)
     else:
         self.last_placeholder = None
Example #7
0
 def insertline(line_nr: LineNumber, line: str):
     return vim.call('append', line_nr - 1, line)
Example #8
0
 def get_syngroup_at_line(self, line_nr: LineNumber) -> str:
     '''Get the syntax group name for the given line (0-indexed)
     in the current buffer.'''
     synid = vim.call('synID', line_nr, 1, 1)
     syntaxgroup = vim.call('synIDattr', synid, 'name')
     return syntaxgroup
Example #9
0
 def inner(*args, **kwargs):
     ret = vim.call(name, *args, **kwargs)
     return _bytes(ret)