Skip to content

Commit

Permalink
updated for version 7.3.1042
Browse files Browse the repository at this point in the history
Problem:    Python: can't assign to vim.Buffer.name.
Solution:   Python patch 3. (ZyX)
  • Loading branch information
brammool committed May 29, 2013
1 parent 7d5332d commit d6562c2
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 152 deletions.
7 changes: 6 additions & 1 deletion runtime/doc/if_pyth.txt
Expand Up @@ -250,7 +250,7 @@ vim.windows *python-windows*
object and always use windows from that tab page (or throw vim.error object and always use windows from that tab page (or throw vim.error
in case tab page was deleted). You can keep a reference to both in case tab page was deleted). You can keep a reference to both
without keeping a reference to vim module object or |python-tabpage|, without keeping a reference to vim module object or |python-tabpage|,
they will not loose their properties in this case. they will not lose their properties in this case.


vim.tabpages *python-tabpages* vim.tabpages *python-tabpages*
A sequence object providing access to the list of vim tab pages. The A sequence object providing access to the list of vim tab pages. The
Expand Down Expand Up @@ -361,6 +361,11 @@ The buffer object attributes are:
this object will raise KeyError. If option is this object will raise KeyError. If option is
|global-local| and local value is missing getting it |global-local| and local value is missing getting it
will return None. will return None.
b.name String, RW. Contains buffer name (full path).
Note: when assigning to b.name |BufFilePre| and
|BufFilePost| autocommands are launched.
b.number Buffer number. Can be used as |python-buffers| key.
Read-only.


The buffer object methods are: The buffer object methods are:
b.append(str) Append a line to the buffer b.append(str) Append a line to the buffer
Expand Down
100 changes: 55 additions & 45 deletions src/ex_cmds.c
Expand Up @@ -784,6 +784,7 @@ do_move(line1, line2, dest)
*/ */
last_line = curbuf->b_ml.ml_line_count; last_line = curbuf->b_ml.ml_line_count;
mark_adjust(line1, line2, last_line - line2, 0L); mark_adjust(line1, line2, last_line - line2, 0L);
changed_lines(last_line - num_lines + 1, 0, last_line + 1, num_lines);
if (dest >= line2) if (dest >= line2)
{ {
mark_adjust(line2 + 1, dest, -num_lines, 0L); mark_adjust(line2 + 1, dest, -num_lines, 0L);
Expand All @@ -799,6 +800,7 @@ do_move(line1, line2, dest)
curbuf->b_op_start.col = curbuf->b_op_end.col = 0; curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
mark_adjust(last_line - num_lines + 1, last_line, mark_adjust(last_line - num_lines + 1, last_line,
-(last_line - dest - extra), 0L); -(last_line - dest - extra), 0L);
changed_lines(last_line - num_lines + 1, 0, last_line + 1, -extra);


/* /*
* Now we delete the original text -- webb * Now we delete the original text -- webb
Expand Down Expand Up @@ -2414,16 +2416,65 @@ print_line(lnum, use_number, list)
info_message = FALSE; info_message = FALSE;
} }


int
rename_buffer(new_fname)
char_u *new_fname;
{
char_u *fname, *sfname, *xfname;
#ifdef FEAT_AUTOCMD
buf_T *buf = curbuf;

apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, buf);
/* buffer changed, don't change name now */
if (buf != curbuf)
return FAIL;
# ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return FAIL;
# endif
#endif
/*
* The name of the current buffer will be changed.
* A new (unlisted) buffer entry needs to be made to hold the old file
* name, which will become the alternate file name.
* But don't set the alternate file name if the buffer didn't have a
* name.
*/
fname = buf->b_ffname;
sfname = buf->b_sfname;
xfname = buf->b_fname;
buf->b_ffname = NULL;
buf->b_sfname = NULL;
if (setfname(buf, new_fname, NULL, TRUE) == FAIL)
{
buf->b_ffname = fname;
buf->b_sfname = sfname;
return FAIL;
}
buf->b_flags |= BF_NOTEDITED;
if (xfname != NULL && *xfname != NUL)
{
buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0);
if (buf != NULL && !cmdmod.keepalt)
curwin->w_alt_fnum = buf->b_fnum;
}
vim_free(fname);
vim_free(sfname);
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, buf);
#endif
/* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR
return OK;
}

/* /*
* ":file[!] [fname]". * ":file[!] [fname]".
*/ */
void void
ex_file(eap) ex_file(eap)
exarg_T *eap; exarg_T *eap;
{ {
char_u *fname, *sfname, *xfname;
buf_T *buf;

/* ":0file" removes the file name. Check for illegal uses ":3file", /* ":0file" removes the file name. Check for illegal uses ":3file",
* "0file name", etc. */ * "0file name", etc. */
if (eap->addr_count > 0 if (eap->addr_count > 0
Expand All @@ -2437,49 +2488,8 @@ ex_file(eap)


if (*eap->arg != NUL || eap->addr_count == 1) if (*eap->arg != NUL || eap->addr_count == 1)
{ {
#ifdef FEAT_AUTOCMD if (rename_buffer(eap->arg) == FAIL)
buf = curbuf;
apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf);
/* buffer changed, don't change name now */
if (buf != curbuf)
return;
# ifdef FEAT_EVAL
if (aborting()) /* autocmds may abort script processing */
return;
# endif
#endif
/*
* The name of the current buffer will be changed.
* A new (unlisted) buffer entry needs to be made to hold the old file
* name, which will become the alternate file name.
* But don't set the alternate file name if the buffer didn't have a
* name.
*/
fname = curbuf->b_ffname;
sfname = curbuf->b_sfname;
xfname = curbuf->b_fname;
curbuf->b_ffname = NULL;
curbuf->b_sfname = NULL;
if (setfname(curbuf, eap->arg, NULL, TRUE) == FAIL)
{
curbuf->b_ffname = fname;
curbuf->b_sfname = sfname;
return; return;
}
curbuf->b_flags |= BF_NOTEDITED;
if (xfname != NULL && *xfname != NUL)
{
buf = buflist_new(fname, xfname, curwin->w_cursor.lnum, 0);
if (buf != NULL && !cmdmod.keepalt)
curwin->w_alt_fnum = buf->b_fnum;
}
vim_free(fname);
vim_free(sfname);
#ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf);
#endif
/* Change directories when the 'acd' option is set. */
DO_AUTOCHDIR
} }
/* print full file name if :cd used */ /* print full file name if :cd used */
fileinfo(FALSE, FALSE, eap->forceit); fileinfo(FALSE, FALSE, eap->forceit);
Expand Down

0 comments on commit d6562c2

Please sign in to comment.