Mercurial > vim
comparison src/fileio.c @ 1834:ccbd8177e1f4 v7.2.132
updated for version 7.2-132
author | vimboss |
---|---|
date | Thu, 05 Mar 2009 02:15:53 +0000 |
parents | 28e9eb0f2d84 |
children | 03714c67a82b |
comparison
equal
deleted
inserted
replaced
1833:fbecb12e37f5 | 1834:ccbd8177e1f4 |
---|---|
67 #ifdef FEAT_AUTOCMD | 67 #ifdef FEAT_AUTOCMD |
68 static int apply_autocmds_exarg __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap)); | 68 static int apply_autocmds_exarg __ARGS((event_T event, char_u *fname, char_u *fname_io, int force, buf_T *buf, exarg_T *eap)); |
69 static int au_find_group __ARGS((char_u *name)); | 69 static int au_find_group __ARGS((char_u *name)); |
70 | 70 |
71 # define AUGROUP_DEFAULT -1 /* default autocmd group */ | 71 # define AUGROUP_DEFAULT -1 /* default autocmd group */ |
72 # define AUGROUP_ERROR -2 /* errornouse autocmd group */ | 72 # define AUGROUP_ERROR -2 /* erroneous autocmd group */ |
73 # define AUGROUP_ALL -3 /* all autocmd groups */ | 73 # define AUGROUP_ALL -3 /* all autocmd groups */ |
74 #endif | 74 #endif |
75 | 75 |
76 #if defined(FEAT_CRYPT) || defined(FEAT_MBYTE) | 76 #if defined(FEAT_CRYPT) || defined(FEAT_MBYTE) |
77 # define HAS_BW_FLAGS | 77 # define HAS_BW_FLAGS |
142 # ifdef MACOS_X | 142 # ifdef MACOS_X |
143 static int get_mac_fio_flags __ARGS((char_u *ptr)); | 143 static int get_mac_fio_flags __ARGS((char_u *ptr)); |
144 # endif | 144 # endif |
145 #endif | 145 #endif |
146 static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf)); | 146 static int move_lines __ARGS((buf_T *frombuf, buf_T *tobuf)); |
147 | 147 #ifdef FEAT_AUTOCMD |
148 static char *e_auchangedbuf = N_("E812: Autocommands changed buffer or buffer name"); | |
149 #endif | |
148 | 150 |
149 void | 151 void |
150 filemess(buf, name, s, attr) | 152 filemess(buf, name, s, attr) |
151 buf_T *buf; | 153 buf_T *buf; |
152 char_u *name; | 154 char_u *name; |
293 wasn't possible */ | 295 wasn't possible */ |
294 char_u conv_rest[CONV_RESTLEN]; | 296 char_u conv_rest[CONV_RESTLEN]; |
295 int conv_restlen = 0; /* nr of bytes in conv_rest[] */ | 297 int conv_restlen = 0; /* nr of bytes in conv_rest[] */ |
296 #endif | 298 #endif |
297 | 299 |
300 #ifdef FEAT_AUTOCMD | |
301 /* Remember the initial values of curbuf, curbuf->b_ffname and | |
302 * curbuf->b_fname to detect whether they are altered as a result of | |
303 * executing nasty autocommands. Also check if "fname" and "sfname" | |
304 * point to one of these values. */ | |
305 buf_T *old_curbuf = curbuf; | |
306 char_u *old_b_ffname = curbuf->b_ffname; | |
307 char_u *old_b_fname = curbuf->b_fname; | |
308 int using_b_ffname = (fname == curbuf->b_ffname) | |
309 || (sfname == curbuf->b_ffname); | |
310 int using_b_fname = (fname == curbuf->b_fname) | |
311 || (sfname == curbuf->b_fname); | |
312 #endif | |
298 write_no_eol_lnum = 0; /* in case it was set by the previous read */ | 313 write_no_eol_lnum = 0; /* in case it was set by the previous read */ |
299 | 314 |
300 /* | 315 /* |
301 * If there is no file name yet, use the one for the read file. | 316 * If there is no file name yet, use the one for the read file. |
302 * BF_NOTEDITED is set to reflect this. | 317 * BF_NOTEDITED is set to reflect this. |
587 * that we are editing this file. Don't do this for a | 602 * that we are editing this file. Don't do this for a |
588 * "nofile" or "nowrite" buffer type. */ | 603 * "nofile" or "nowrite" buffer type. */ |
589 #ifdef FEAT_QUICKFIX | 604 #ifdef FEAT_QUICKFIX |
590 if (!bt_dontwrite(curbuf)) | 605 if (!bt_dontwrite(curbuf)) |
591 #endif | 606 #endif |
607 { | |
592 check_need_swap(newfile); | 608 check_need_swap(newfile); |
609 #ifdef FEAT_AUTOCMD | |
610 /* SwapExists autocommand may mess things up */ | |
611 if (curbuf != old_curbuf | |
612 || (using_b_ffname | |
613 && (old_b_ffname != curbuf->b_ffname)) | |
614 || (using_b_fname | |
615 && (old_b_fname != curbuf->b_fname))) | |
616 { | |
617 EMSG(_(e_auchangedbuf)); | |
618 return FAIL; | |
619 } | |
620 #endif | |
621 } | |
593 if (dir_of_file_exists(fname)) | 622 if (dir_of_file_exists(fname)) |
594 filemess(curbuf, sfname, (char_u *)_("[New File]"), 0); | 623 filemess(curbuf, sfname, (char_u *)_("[New File]"), 0); |
595 else | 624 else |
596 filemess(curbuf, sfname, | 625 filemess(curbuf, sfname, |
597 (char_u *)_("[New DIRECTORY]"), 0); | 626 (char_u *)_("[New DIRECTORY]"), 0); |
666 #ifdef FEAT_QUICKFIX | 695 #ifdef FEAT_QUICKFIX |
667 if (!bt_dontwrite(curbuf)) | 696 if (!bt_dontwrite(curbuf)) |
668 #endif | 697 #endif |
669 { | 698 { |
670 check_need_swap(newfile); | 699 check_need_swap(newfile); |
700 #ifdef FEAT_AUTOCMD | |
701 if (!read_stdin && (curbuf != old_curbuf | |
702 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) | |
703 || (using_b_fname && (old_b_fname != curbuf->b_fname)))) | |
704 { | |
705 EMSG(_(e_auchangedbuf)); | |
706 if (!read_buffer) | |
707 close(fd); | |
708 return FAIL; | |
709 } | |
710 #endif | |
671 #ifdef UNIX | 711 #ifdef UNIX |
672 /* Set swap file protection bits after creating it. */ | 712 /* Set swap file protection bits after creating it. */ |
673 if (swap_mode > 0 && curbuf->b_ml.ml_mfp->mf_fname != NULL) | 713 if (swap_mode > 0 && curbuf->b_ml.ml_mfp->mf_fname != NULL) |
674 (void)mch_setperm(curbuf->b_ml.ml_mfp->mf_fname, (long)swap_mode); | 714 (void)mch_setperm(curbuf->b_ml.ml_mfp->mf_fname, (long)swap_mode); |
675 #endif | 715 #endif |
696 #ifdef FEAT_AUTOCMD | 736 #ifdef FEAT_AUTOCMD |
697 if (!read_buffer) | 737 if (!read_buffer) |
698 { | 738 { |
699 int m = msg_scroll; | 739 int m = msg_scroll; |
700 int n = msg_scrolled; | 740 int n = msg_scrolled; |
701 buf_T *old_curbuf = curbuf; | |
702 | 741 |
703 /* | 742 /* |
704 * The file must be closed again, the autocommands may want to change | 743 * The file must be closed again, the autocommands may want to change |
705 * the file before reading it. | 744 * the file before reading it. |
706 */ | 745 */ |
738 } | 777 } |
739 #endif | 778 #endif |
740 /* | 779 /* |
741 * Don't allow the autocommands to change the current buffer. | 780 * Don't allow the autocommands to change the current buffer. |
742 * Try to re-open the file. | 781 * Try to re-open the file. |
782 * | |
783 * Don't allow the autocommands to change the buffer name either | |
784 * (cd for example) if it invalidates fname or sfname. | |
743 */ | 785 */ |
744 if (!read_stdin && (curbuf != old_curbuf | 786 if (!read_stdin && (curbuf != old_curbuf |
787 || (using_b_ffname && (old_b_ffname != curbuf->b_ffname)) | |
788 || (using_b_fname && (old_b_fname != curbuf->b_fname)) | |
745 || (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0)) | 789 || (fd = mch_open((char *)fname, O_RDONLY | O_EXTRA, 0)) < 0)) |
746 { | 790 { |
747 --no_wait_return; | 791 --no_wait_return; |
748 msg_scroll = msg_save; | 792 msg_scroll = msg_save; |
749 if (fd < 0) | 793 if (fd < 0) |
6318 return FALSE; | 6362 return FALSE; |
6319 } | 6363 } |
6320 | 6364 |
6321 if (!stuff_empty() || global_busy || !typebuf_typed() | 6365 if (!stuff_empty() || global_busy || !typebuf_typed() |
6322 #ifdef FEAT_AUTOCMD | 6366 #ifdef FEAT_AUTOCMD |
6323 || autocmd_busy || curbuf_lock > 0 | 6367 || autocmd_busy || curbuf_lock > 0 || allbuf_lock > 0 |
6324 #endif | 6368 #endif |
6325 ) | 6369 ) |
6326 need_check_timestamps = TRUE; /* check later */ | 6370 need_check_timestamps = TRUE; /* check later */ |
6327 else | 6371 else |
6328 { | 6372 { |
6520 busy = TRUE; | 6564 busy = TRUE; |
6521 # ifdef FEAT_EVAL | 6565 # ifdef FEAT_EVAL |
6522 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1); | 6566 set_vim_var_string(VV_FCS_REASON, (char_u *)reason, -1); |
6523 set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1); | 6567 set_vim_var_string(VV_FCS_CHOICE, (char_u *)"", -1); |
6524 # endif | 6568 # endif |
6569 ++allbuf_lock; | |
6525 n = apply_autocmds(EVENT_FILECHANGEDSHELL, | 6570 n = apply_autocmds(EVENT_FILECHANGEDSHELL, |
6526 buf->b_fname, buf->b_fname, FALSE, buf); | 6571 buf->b_fname, buf->b_fname, FALSE, buf); |
6572 --allbuf_lock; | |
6527 busy = FALSE; | 6573 busy = FALSE; |
6528 if (n) | 6574 if (n) |
6529 { | 6575 { |
6530 if (!buf_valid(buf)) | 6576 if (!buf_valid(buf)) |
6531 EMSG(_("E246: FileChangedShell autocommand deleted buffer")); | 6577 EMSG(_("E246: FileChangedShell autocommand deleted buffer")); |