示例#1
0
/*
 * Save a reverse delta for doing undo.
 */
void
undo_save (int type, Point pt, size_t osize, size_t size)
{
  Undo *up;

  if (get_buffer_noundo (cur_bp) || undo_nosave)
    return;

  up = (Undo *) XZALLOC (Undo);
  up->type = type;
  up->n = pt.n;
  up->o = pt.o;
  if (!get_buffer_modified (cur_bp))
    up->unchanged = true;

  if (type == UNDO_REPLACE_BLOCK)
    {
      Line * lp = get_buffer_pt (cur_bp).p;
      size_t n = get_buffer_pt (cur_bp).n;

      if (n > pt.n)
        do
          lp = get_line_prev (lp);
        while (--n > pt.n);
      else if (n < pt.n)
        do
          lp = get_line_next (lp);
        while (++n < pt.n);

      pt.p = lp;
      up->block.osize = osize;
      up->block.size = size;
      up->block.text = copy_text_block (pt, osize);
    }

  up->next = get_buffer_last_undop (cur_bp);
  set_buffer_last_undop (cur_bp, up);

  if (!doing_undo)
    set_buffer_next_undop (cur_bp, up);
}
示例#2
0
文件: file.c 项目: M1lan/zile
bool
find_file (const char *filename)
{
  Buffer bp;
  for (bp = head_bp; bp != NULL; bp = get_buffer_next (bp))
    if (get_buffer_filename (bp) != NULL &&
        STREQ (get_buffer_filename (bp), filename))
      break;

  if (bp == NULL)
    {
      if (exist_file (filename) && !is_regular_file (filename))
        {
          minibuf_error ("File exists but could not be read");
          return false;
        }
      else
        {
          bp = buffer_new ();
          set_buffer_names (bp, filename);
          set_buffer_dir (bp, astr_new_cstr (dir_name (filename)));

          estr es = estr_readf (filename);
          if (es)
            set_buffer_readonly (bp, !check_writable (filename));
          else
            es = estr_new_astr (astr_new ());
          set_buffer_text (bp, es);

          /* Reset undo history. */
          set_buffer_next_undop (bp, NULL);
          set_buffer_last_undop (bp, NULL);
          set_buffer_modified (bp, false);
        }
    }

  switch_to_buffer (bp);
  thisflag |= FLAG_NEED_RESYNC;
  return true;
}