Esempio n. 1
0
def sync_buffer_to(to_line, to_col):
  global saved_sync
  curr_sync = vimbufsync.sync()
  cb = vim.current.buffer
  max_line = len(cb)
  end_line = min(to_line, max_line)

  if saved_sync and curr_sync.bufnr() == saved_sync.bufnr():
    line, col = saved_sync.pos()
    line, col = command_seek_before(line, 0)
    if line <= end_line:
      rest    = cb[line-1][col:]
      content = cb[line:end_line]
      content.insert(0, rest)
      saved_sync = curr_sync
    else:
      content = None
  else:
    command_reset(name=os.path.basename(cb.name))
    content = cb[:end_line]
    saved_sync = curr_sync

  # Send content
  if content:
    kind = "struct"
    while not command_tell(kind,content):
      kind = "end"
      if end_line < max_line:
        next_end = min(max_line,end_line + 20)
        content = cb[end_line:next_end]
        end_line = next_end
      else:
        content = None
  # Now we are synced, come back to environment around cursor
  command_seek_exact(to_line, to_col)
Esempio n. 2
0
def sync():
    global saved_sync
    curr_sync = vimbufsync.sync()
    if not saved_sync or curr_sync.buf() != saved_sync.buf():
        _reset()
    else:
        (line, col) = saved_sync.pos()
        rewind_to(line - 1, col) # vim indexes from lines 1, coquille from 0
    saved_sync = curr_sync
Esempio n. 3
0
def sync():
    global saved_sync
    curr_sync = vimbufsync.sync()
    if not saved_sync or curr_sync.buf() != saved_sync.buf():
        _reset()
    else:
        (line, col) = saved_sync.pos()
        rewind_to(line - 1, col)  # vim indexes from lines 1, coquille from 0
    saved_sync = curr_sync
Esempio n. 4
0
 def sync(self):
     curr_sync = vimbufsync.sync(self.source_buffer)
     if not self.saved_sync or curr_sync.buf() != self.saved_sync.buf():
         if self.coq_top.get_active_command_count() > 1:
             self._reset()
     else:
         (line, col) = self.saved_sync.pos()
         # vim indexes from lines 1, coquille from 0
         self.rewind_to(line - 1, col - 1)
     self.saved_sync = curr_sync
Esempio n. 5
0
def sync():
  global saved_sync, saved_states
  curr_sync = vimbufsync.sync()
  if not saved_sync or curr_sync.buf() != saved_sync.buf():
    saved_states = []
  else:
    line = saved_sync.line()
    i = bisect.bisect_left(saved_states, (line,""))
    if i != len(saved_states):
      saved_states = saved_states[:i]
  saved_sync = curr_sync
Esempio n. 6
0
    def sync(self):
        # type: () -> None
        """Check if the buffer has been updated and rewind Coqtop if so."""
        curr_sync = vimbufsync.sync()

        if self.saved_sync is None or curr_sync.buf() != self.saved_sync.buf():
            self._reset()
        else:
            line, col = self.saved_sync.pos()
            self.rewind_to(line - 1, col)

        self.saved_sync = curr_sync
Esempio n. 7
0
def acquire_buffer(force=False):
    if not force and vim.eval('exists("b:dotmerlin")') == "0":
        return False

    process = merlin_process()
    saved_sync = process.saved_sync
    curr_sync = vimbufsync.sync()

    if not (saved_sync and (curr_sync.bufnr() == saved_sync.bufnr())):
        process.saved_sync = None
        command_checkout(name=vim.eval("expand('%:p')"))

    return process.saved_sync
Esempio n. 8
0
def acquire_buffer(force=False):
    if not force and vim.eval('exists("b:dotmerlin")') == '0':
        return False

    process = merlin_process()
    saved_sync = process.saved_sync
    curr_sync = vimbufsync.sync()

    if not (saved_sync and (curr_sync.bufnr() == saved_sync.bufnr())):
        process.saved_sync = None
        command_reset(name=vim.eval("expand('%:p')"))

    return process.saved_sync
Esempio n. 9
0
def acquire_buffer(force=False):
  if not force and vim.eval('exists("b:dotmerlin")') == '0':
    return False

  process = merlin_process()
  saved_sync = process.saved_sync
  curr_sync = vimbufsync.sync()

  if saved_sync and curr_sync.bufnr() == saved_sync.bufnr():
    return False
  else:
    command_reset(
        kind=(vim.eval("expand('%:e')") == "mli") and "mli" or "ml",
        name=vim.eval("expand('%:p')")
        )
    process.saved_sync = curr_sync
    return True
Esempio n. 10
0
def sync_buffer_to_(to_line, to_col, skip_marker=False):
    process = merlin_process()

    cb = vim.current.buffer
    max_line = len(cb)
    end_line = min(to_line, max_line)

    saved_sync = acquire_buffer(force=True)
    if saved_sync:
        line, col = min(saved_sync.pos(), (to_line, to_col))
    else:
        line, col = 1, 0
    col = 0
    command_seek("exact", line, col)

    line, col, _ = parse_position(command("tell", "start"))

    # Send prefix content
    if line <= end_line:
        rest = cb[line - 1][col:]
        content = cb[line:end_line]
        content.insert(0, rest)
        encoding = vim_encoding()
        content = map(lambda str: str.decode(encoding), content)
        command_tell(content)

    # put marker
    _, _, marker = parse_position(command("tell", "marker"))

    # satisfy marker
    while marker and (end_line < max_line):
        next_end = min(max_line, end_line + 50)
        _, _, marker = command_tell(cb[end_line:next_end])
        end_line = next_end

    # put eof if marker still on stack at max_line
    if marker:
        command("tell", "eof")
    if not skip_marker:
        command("seek", "marker")

    # save synchronisation point
    process.saved_sync = vimbufsync.sync()
Esempio n. 11
0
def sync_buffer_to_(to_line, to_col, skip_marker=False):
    process = merlin_process()

    cb = vim.current.buffer
    max_line = len(cb)
    end_line = min(to_line, max_line)

    saved_sync = acquire_buffer(force=True)
    if saved_sync:
        line, col = min(saved_sync.pos(), (to_line, to_col))
    else:
        line, col = 1, 0
    col = 0
    command_seek("exact", line, col)

    line, col, _ = parse_position(command("tell", "start"))

    # Send prefix content
    if line <= end_line:
        rest = cb[line - 1][col:]
        content = cb[line:end_line]
        content.insert(0, rest)
        encoding = vim_encoding()
        content = map(lambda str: str.decode(encoding), content)
        command_tell(content)

    # put marker
    _, _, marker = parse_position(command("tell", "marker"))

    # satisfy marker
    while marker and (end_line < max_line):
        next_end = min(max_line, end_line + 50)
        _, _, marker = command_tell(cb[end_line:next_end])
        end_line = next_end

    # put eof if marker still on stack at max_line
    if marker: command("tell", "eof")
    if not skip_marker: command("seek", "marker")

    # save synchronisation point
    process.saved_sync = vimbufsync.sync()
Esempio n. 12
0
def sync_buffer_to(to_line, to_col):
  global saved_sync
  curr_sync = vimbufsync.sync()
  cb = vim.current.buffer
  max_line = len(cb)
  end_line = min(to_line, max_line)

  if saved_sync and curr_sync.bufnr() == saved_sync.bufnr():
    line, col = saved_sync.pos()
    line, col = command_seek_before(line, 0)
    if line <= end_line:
      if line <= 1:
        command_reset(name=os.path.basename(cb.name))
        content = cb[:end_line]
      else:
        rest    = cb[line-1][col:]
        content = cb[line:end_line]
        content.insert(0, rest)
      saved_sync = curr_sync
    else:
      content = None
  else:
    command_reset(name=os.path.basename(cb.name))
    content = cb[:end_line]
    saved_sync = curr_sync

  # Send content
  if content:
    kind = "struct"
    while not command_tell(kind,content):
      kind = "end"
      if end_line < max_line:
        next_end = min(max_line,end_line + 20)
        content = cb[end_line:next_end]
        end_line = next_end
      else:
        content = None
  # Now we are synced, come back to environment around cursor
  command_seek_exact(to_line, to_col)
Esempio n. 13
0
def sync_buffer_to(to_line, to_col):
  process = merlin_process()
  saved_sync = process.saved_sync
  curr_sync = vimbufsync.sync()
  cb = vim.current.buffer
  max_line = len(cb)
  end_line = min(to_line, max_line)

  if saved_sync and curr_sync.bufnr() == saved_sync.bufnr():
    line, col = saved_sync.pos()
    line, col = command_seek_before(line, 0)
    if line <= end_line:
      rest    = cb[line-1][col:]
      content = cb[line:end_line]
      content.insert(0, rest)
      process.saved_sync = curr_sync
    else:
      content = None
  else:
    command_reset(name=vim.eval("expand('%:p')"))
    content = cb[:end_line]
    process.saved_sync = curr_sync

  # Send content
  if content:
    kind = "source"
    while not command_tell(kind,content):
      kind = "more"
      if end_line < max_line:
        next_end = min(max_line,end_line + 20)
        content = cb[end_line:next_end]
        end_line = next_end
      else:
        content = None
  # Now we are synced, come back to environment around cursor
  command_seek_exact(to_line, to_col)