Mercurial > vim
diff src/fileio.c @ 633:7437be625546
updated for version 7.0183
author | vimboss |
---|---|
date | Fri, 20 Jan 2006 23:02:51 +0000 |
parents | efb7557aea10 |
children | 23a639c430c5 |
line wrap: on
line diff
--- a/src/fileio.c +++ b/src/fileio.c @@ -59,6 +59,7 @@ static char_u *check_for_cryptkey __ARGS #ifdef UNIX static void set_file_time __ARGS((char_u *fname, time_t atime, time_t mtime)); #endif +static int set_rw_fname __ARGS((char_u *fname, char_u *sfname)); static int msg_add_fileformat __ARGS((int eol_type)); static void msg_add_eol __ARGS((void)); static int check_mtime __ARGS((buf_T *buf, struct stat *s)); @@ -301,8 +302,8 @@ readfile(fname, sfname, from, lines_to_s && vim_strchr(p_cpo, CPO_FNAMER) != NULL && !(flags & READ_DUMMY)) { - if (setfname(curbuf, fname, sfname, FALSE) == OK) - curbuf->b_flags |= BF_NOTEDITED; + if (set_rw_fname(fname, sfname) == FAIL) + return FAIL; } /* After reading a file the cursor line changes but we don't want to @@ -2801,35 +2802,20 @@ buf_write(buf, fname, sfname, start, end * Don't do this when appending. * Only do this when 'cpoptions' contains the 'F' flag. */ - if (reset_changed + if (buf->b_ffname == NULL + && reset_changed && whole && buf == curbuf #ifdef FEAT_QUICKFIX && !bt_nofile(buf) #endif - && buf->b_ffname == NULL && !filtering && (!append || vim_strchr(p_cpo, CPO_FNAMEAPP) != NULL) && vim_strchr(p_cpo, CPO_FNAMEW) != NULL) { -#ifdef FEAT_AUTOCMD - /* It's like the unnamed buffer is deleted.... */ - if (curbuf->b_p_bl) - apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); - apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); -#ifdef FEAT_EVAL - if (aborting()) /* autocmds may abort script processing */ + if (set_rw_fname(fname, sfname) == FAIL) return FAIL; -#endif -#endif - if (setfname(curbuf, fname, sfname, FALSE) == OK) - curbuf->b_flags |= BF_NOTEDITED; -#ifdef FEAT_AUTOCMD - /* ....and a new named one is created */ - apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); - if (curbuf->b_p_bl) - apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); -#endif + buf = curbuf; /* just in case autocmds made "buf" invalid */ } if (sfname == NULL) @@ -4601,6 +4587,50 @@ nofail: } /* + * Set the name of the current buffer. Use when the buffer doesn't have a + * name and a ":r" or ":w" command with a file name is used. + */ + static int +set_rw_fname(fname, sfname) + char_u *fname; + char_u *sfname; +{ +#ifdef FEAT_AUTOCMD + /* It's like the unnamed buffer is deleted.... */ + if (curbuf->b_p_bl) + apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); + apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); +# ifdef FEAT_EVAL + if (aborting()) /* autocmds may abort script processing */ + return FAIL; +# endif +#endif + + if (setfname(curbuf, fname, sfname, FALSE) == OK) + curbuf->b_flags |= BF_NOTEDITED; + +#ifdef FEAT_AUTOCMD + /* ....and a new named one is created */ + apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, curbuf); + if (curbuf->b_p_bl) + apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); +# ifdef FEAT_EVAL + if (aborting()) /* autocmds may abort script processing */ + return FAIL; +# endif + + /* Do filetype detection now if 'filetype' is empty. */ + if (*curbuf->b_p_ft == NUL) + { + (void)do_doautocmd((char_u *)"filetypedetect BufRead", TRUE); + do_modelines(FALSE); + } +#endif + + return OK; +} + +/* * Put file name into IObuff with quotes. */ void