comparison src/fileio.c @ 179:7fd70926e2e1 v7.0055

updated for version 7.0055
author vimboss
date Fri, 04 Mar 2005 23:39:37 +0000
parents 84c21eb4fc40
children 041a413d626d
comparison
equal deleted inserted replaced
178:4d53c2a2af94 179:7fd70926e2e1
1329 top = (char *)ptr; 1329 top = (char *)ptr;
1330 to_size = real_size - size; 1330 to_size = real_size - size;
1331 1331
1332 /* 1332 /*
1333 * If there is conversion error or not enough room try using 1333 * If there is conversion error or not enough room try using
1334 * another conversion. 1334 * another conversion. Except for when there is no
1335 * alternative (help files).
1335 */ 1336 */
1336 while ((iconv(iconv_fd, (void *)&fromp, &from_size, 1337 while ((iconv(iconv_fd, (void *)&fromp, &from_size,
1337 &top, &to_size) 1338 &top, &to_size)
1338 == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL) 1339 == (size_t)-1 && ICONV_ERRNO != ICONV_EINVAL)
1339 || from_size > CONV_RESTLEN) 1340 || from_size > CONV_RESTLEN)
2751 else if (reset_changed && whole) 2752 else if (reset_changed && whole)
2752 { 2753 {
2753 if (!(did_cmd = apply_autocmds_exarg(EVENT_BUFWRITECMD, 2754 if (!(did_cmd = apply_autocmds_exarg(EVENT_BUFWRITECMD,
2754 sfname, sfname, FALSE, curbuf, eap))) 2755 sfname, sfname, FALSE, curbuf, eap)))
2755 { 2756 {
2756 if (bt_nofile(curbuf)) 2757 if (overwriting && bt_nofile(curbuf))
2757 nofile_err = TRUE; 2758 nofile_err = TRUE;
2758 else 2759 else
2759 apply_autocmds_exarg(EVENT_BUFWRITEPRE, 2760 apply_autocmds_exarg(EVENT_BUFWRITEPRE,
2760 sfname, sfname, FALSE, curbuf, eap); 2761 sfname, sfname, FALSE, curbuf, eap);
2761 } 2762 }
2763 else 2764 else
2764 { 2765 {
2765 if (!(did_cmd = apply_autocmds_exarg(EVENT_FILEWRITECMD, 2766 if (!(did_cmd = apply_autocmds_exarg(EVENT_FILEWRITECMD,
2766 sfname, sfname, FALSE, curbuf, eap))) 2767 sfname, sfname, FALSE, curbuf, eap)))
2767 { 2768 {
2768 if (bt_nofile(curbuf)) 2769 if (overwriting && bt_nofile(curbuf))
2769 nofile_err = TRUE; 2770 nofile_err = TRUE;
2770 else 2771 else
2771 apply_autocmds_exarg(EVENT_FILEWRITEPRE, 2772 apply_autocmds_exarg(EVENT_FILEWRITEPRE,
2772 sfname, sfname, FALSE, curbuf, eap); 2773 sfname, sfname, FALSE, curbuf, eap);
2773 } 2774 }
5915 #ifdef FEAT_GUI 5916 #ifdef FEAT_GUI
5916 int save_mouse_correct = need_mouse_correct; 5917 int save_mouse_correct = need_mouse_correct;
5917 #endif 5918 #endif
5918 #ifdef FEAT_AUTOCMD 5919 #ifdef FEAT_AUTOCMD
5919 static int busy = FALSE; 5920 static int busy = FALSE;
5920 #endif 5921 int n;
5922 char_u *s;
5923 #endif
5924 char *reason;
5921 5925
5922 /* If there is no file name, the buffer is not loaded, 'buftype' is 5926 /* If there is no file name, the buffer is not loaded, 'buftype' is
5923 * set, we are in the middle of a save or being called recursively: ignore 5927 * set, we are in the middle of a save or being called recursively: ignore
5924 * this buffer. */ 5928 * this buffer. */
5925 if (buf->b_ffname == NULL 5929 if (buf->b_ffname == NULL
5973 else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar) 5977 else if ((buf->b_p_ar >= 0 ? buf->b_p_ar : p_ar)
5974 && !bufIsChanged(buf) && stat_res >= 0) 5978 && !bufIsChanged(buf) && stat_res >= 0)
5975 reload = TRUE; 5979 reload = TRUE;
5976 else 5980 else
5977 { 5981 {
5982 if (stat_res < 0)
5983 reason = "deleted";
5984 else if (bufIsChanged(buf))
5985 reason = "conflict";
5986 else if (orig_size != buf->b_orig_size || buf_contents_changed(buf))
5987 reason = "changed";
5988 else if (orig_mode != buf->b_orig_mode)
5989 reason = "mode";
5990 else
5991 reason = "time";
5992
5978 #ifdef FEAT_AUTOCMD 5993 #ifdef FEAT_AUTOCMD
5979 int n;
5980
5981 /* 5994 /*
5982 * Only give the warning if there are no FileChangedShell 5995 * Only give the warning if there are no FileChangedShell
5983 * autocommands. 5996 * autocommands.
5984 * Avoid being called recursively by setting "busy". 5997 * Avoid being called recursively by setting "busy".
5985 */ 5998 */
5986 busy = TRUE; 5999 busy = TRUE;
6000 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1);
6001 set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1);
5987 n = apply_autocmds(EVENT_FILECHANGEDSHELL, 6002 n = apply_autocmds(EVENT_FILECHANGEDSHELL,
5988 buf->b_fname, buf->b_fname, FALSE, buf); 6003 buf->b_fname, buf->b_fname, FALSE, buf);
5989 busy = FALSE; 6004 busy = FALSE;
5990 if (n) 6005 if (n)
5991 { 6006 {
5992 if (!buf_valid(buf)) 6007 if (!buf_valid(buf))
5993 EMSG(_("E246: FileChangedShell autocommand deleted buffer")); 6008 EMSG(_("E246: FileChangedShell autocommand deleted buffer"));
5994 return 2; 6009 s = get_vim_var_str(VV_FCS_CHOICE);
5995 } 6010 if (STRCMP(s, "reload") == 0 && *reason != 'd')
5996 else 6011 reload = TRUE;
5997 #endif 6012 else if (STRCMP(s, "ask") == 0)
5998 { 6013 n = FALSE;
5999 if (stat_res < 0) 6014 else
6000 mesg = _("E211: Warning: File \"%s\" no longer available"); 6015 return 2;
6016 }
6017 if (!n)
6018 #endif
6019 {
6020 if (*reason == 'd')
6021 mesg = _("E211: File \"%s\" no longer available");
6001 else 6022 else
6002 { 6023 {
6003 helpmesg = TRUE; 6024 helpmesg = TRUE;
6004 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) 6025 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)
6005 can_reload = TRUE; 6026 can_reload = TRUE;
6008 * Check if the file contents really changed to avoid 6029 * Check if the file contents really changed to avoid
6009 * giving a warning when only the timestamp was set (e.g., 6030 * giving a warning when only the timestamp was set (e.g.,
6010 * checked out of CVS). Always warn when the buffer was 6031 * checked out of CVS). Always warn when the buffer was
6011 * changed. 6032 * changed.
6012 */ 6033 */
6013 if (bufIsChanged(buf)) 6034 if (reason[2] == 'n')
6035 {
6014 mesg = _("W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well"); 6036 mesg = _("W12: Warning: File \"%s\" has changed and the buffer was changed in Vim as well");
6015 else if (orig_size != buf->b_orig_size 6037 mesg2 = _("See \":help W12\" for more info.");
6016 || buf_contents_changed(buf)) 6038 }
6039 else if (reason[1] == 'h')
6040 {
6017 mesg = _("W11: Warning: File \"%s\" has changed since editing started"); 6041 mesg = _("W11: Warning: File \"%s\" has changed since editing started");
6018 else if (orig_mode != buf->b_orig_mode) 6042 mesg2 = _("See \":help W11\" for more info.");
6043 }
6044 else if (*reason == 'm')
6045 {
6019 mesg = _("W16: Warning: Mode of file \"%s\" has changed since editing started"); 6046 mesg = _("W16: Warning: Mode of file \"%s\" has changed since editing started");
6047 mesg2 = _("See \":help W16\" for more info.");
6048 }
6049 /* Else: only timestamp changed, ignored */
6020 } 6050 }
6021 } 6051 }
6022 } 6052 }
6023 6053
6024 } 6054 }
6036 if (mesg != NULL) 6066 if (mesg != NULL)
6037 { 6067 {
6038 path = home_replace_save(buf, buf->b_fname); 6068 path = home_replace_save(buf, buf->b_fname);
6039 if (path != NULL) 6069 if (path != NULL)
6040 { 6070 {
6041 if (helpmesg) 6071 if (!helpmesg)
6042 mesg2 = _("See \":help W11\" for more info.");
6043 else
6044 mesg2 = ""; 6072 mesg2 = "";
6045 tbuf = alloc((unsigned)(STRLEN(path) + STRLEN(mesg) 6073 tbuf = alloc((unsigned)(STRLEN(path) + STRLEN(mesg)
6046 + STRLEN(mesg2) + 2)); 6074 + STRLEN(mesg2) + 2));
6047 sprintf((char *)tbuf, mesg, path); 6075 sprintf((char *)tbuf, mesg, path);
6048 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG) 6076 #if defined(FEAT_CON_DIALOG) || defined(FEAT_GUI_DIALOG)