diff options
author | Bram Moolenaar <Bram@vim.org> | 2006-01-20 23:02:51 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2006-01-20 23:02:51 +0000 |
commit | 2d3f489e09a1cc50f5b7601eff568a4eb87fbd51 (patch) | |
tree | a29e0aabb8e2ee8bba220b843d536dca3fdf2100 /src/fileio.c | |
parent | 8ada17c4d9d783b370d081c2a947ea1350cc8338 (diff) | |
download | vim-git-2d3f489e09a1cc50f5b7601eff568a4eb87fbd51.tar.gz |
updated for version 7.0183
Diffstat (limited to 'src/fileio.c')
-rw-r--r-- | src/fileio.c | 72 |
1 files changed, 51 insertions, 21 deletions
diff --git a/src/fileio.c b/src/fileio.c index 2236bbc1a..ce3e2a043 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -59,6 +59,7 @@ static char_u *check_for_cryptkey __ARGS((char_u *cryptkey, char_u *ptr, long *s #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_skip, lines_to_read, eap, flags) && 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, eap, append, forceit, * 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 |