Mercurial > vim
comparison src/ex_cmds.c @ 9481:7520696c14b0 v7.4.2021
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 10 19:03:57 2016 +0200
patch 7.4.2021
Problem: Still too many buf_valid() calls.
Solution: Make au_new_curbuf a bufref. Use bufref_valid() in more places.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 10 Jul 2016 19:15:06 +0200 |
parents | 38e2fc4ee4ef |
children | 69ed2c9d34a6 |
comparison
equal
deleted
inserted
replaced
9480:8d1406fbb955 | 9481:7520696c14b0 |
---|---|
3445 { | 3445 { |
3446 ++error; | 3446 ++error; |
3447 } | 3447 } |
3448 else | 3448 else |
3449 { | 3449 { |
3450 #ifdef FEAT_AUTOCMD | |
3451 bufref_T bufref; | |
3452 | |
3453 set_bufref(&bufref, buf); | |
3454 #endif | |
3450 if (buf_write_all(buf, eap->forceit) == FAIL) | 3455 if (buf_write_all(buf, eap->forceit) == FAIL) |
3451 ++error; | 3456 ++error; |
3452 #ifdef FEAT_AUTOCMD | 3457 #ifdef FEAT_AUTOCMD |
3453 /* an autocommand may have deleted the buffer */ | 3458 /* an autocommand may have deleted the buffer */ |
3454 if (!buf_valid(buf)) | 3459 if (!bufref_valid(&bufref)) |
3455 buf = firstbuf; | 3460 buf = firstbuf; |
3456 #endif | 3461 #endif |
3457 } | 3462 } |
3458 eap->forceit = save_forceit; /* check_overwrite() may set it */ | 3463 eap->forceit = save_forceit; /* check_overwrite() may set it */ |
3459 } | 3464 } |
3657 into the buffer unexpectedly */ | 3662 into the buffer unexpectedly */ |
3658 char_u *new_name = NULL; | 3663 char_u *new_name = NULL; |
3659 int did_set_swapcommand = FALSE; | 3664 int did_set_swapcommand = FALSE; |
3660 #endif | 3665 #endif |
3661 buf_T *buf; | 3666 buf_T *buf; |
3667 bufref_T bufref; | |
3662 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 3668 #if defined(FEAT_AUTOCMD) || defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
3663 buf_T *old_curbuf = curbuf; | 3669 buf_T *old_curbuf = curbuf; |
3664 #endif | 3670 #endif |
3665 char_u *free_fname = NULL; | 3671 char_u *free_fname = NULL; |
3666 #ifdef FEAT_BROWSE | 3672 #ifdef FEAT_BROWSE |
3861 oldbuf = FALSE; | 3867 oldbuf = FALSE; |
3862 } | 3868 } |
3863 else /* existing memfile */ | 3869 else /* existing memfile */ |
3864 { | 3870 { |
3865 oldbuf = TRUE; | 3871 oldbuf = TRUE; |
3872 set_bufref(&bufref, buf); | |
3866 (void)buf_check_timestamp(buf, FALSE); | 3873 (void)buf_check_timestamp(buf, FALSE); |
3867 /* Check if autocommands made buffer invalid or changed the current | 3874 /* Check if autocommands made buffer invalid or changed the current |
3868 * buffer. */ | 3875 * buffer. */ |
3869 if (!buf_valid(buf) | 3876 if (!bufref_valid(&bufref) |
3870 #ifdef FEAT_AUTOCMD | 3877 #ifdef FEAT_AUTOCMD |
3871 || curbuf != old_curbuf | 3878 || curbuf != old_curbuf |
3872 #endif | 3879 #endif |
3873 ) | 3880 ) |
3874 goto theend; | 3881 goto theend; |
3906 * - If we ended up in the new buffer already, need to skip a few | 3913 * - If we ended up in the new buffer already, need to skip a few |
3907 * things, set auto_buf. | 3914 * things, set auto_buf. |
3908 */ | 3915 */ |
3909 if (buf->b_fname != NULL) | 3916 if (buf->b_fname != NULL) |
3910 new_name = vim_strsave(buf->b_fname); | 3917 new_name = vim_strsave(buf->b_fname); |
3911 au_new_curbuf = buf; | 3918 set_bufref(&au_new_curbuf, buf); |
3912 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); | 3919 apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf); |
3913 if (!buf_valid(buf)) /* new buffer has been deleted */ | 3920 if (!bufref_valid(&au_new_curbuf)) |
3914 { | 3921 { |
3922 /* new buffer has been deleted */ | |
3915 delbuf_msg(new_name); /* frees new_name */ | 3923 delbuf_msg(new_name); /* frees new_name */ |
3916 goto theend; | 3924 goto theend; |
3917 } | 3925 } |
3918 # ifdef FEAT_EVAL | 3926 # ifdef FEAT_EVAL |
3919 if (aborting()) /* autocmds may abort script processing */ | 3927 if (aborting()) /* autocmds may abort script processing */ |
3949 vim_free(new_name); | 3957 vim_free(new_name); |
3950 goto theend; | 3958 goto theend; |
3951 } | 3959 } |
3952 # endif | 3960 # endif |
3953 /* Be careful again, like above. */ | 3961 /* Be careful again, like above. */ |
3954 if (!buf_valid(buf)) /* new buffer has been deleted */ | 3962 if (!bufref_valid(&au_new_curbuf)) |
3955 { | 3963 { |
3964 /* new buffer has been deleted */ | |
3956 delbuf_msg(new_name); /* frees new_name */ | 3965 delbuf_msg(new_name); /* frees new_name */ |
3957 goto theend; | 3966 goto theend; |
3958 } | 3967 } |
3959 if (buf == curbuf) /* already in new buffer */ | 3968 if (buf == curbuf) /* already in new buffer */ |
3960 auto_buf = TRUE; | 3969 auto_buf = TRUE; |
3993 #endif | 4002 #endif |
3994 | 4003 |
3995 #ifdef FEAT_AUTOCMD | 4004 #ifdef FEAT_AUTOCMD |
3996 } | 4005 } |
3997 vim_free(new_name); | 4006 vim_free(new_name); |
3998 au_new_curbuf = NULL; | 4007 au_new_curbuf.br_buf = NULL; |
3999 #endif | 4008 #endif |
4000 } | 4009 } |
4001 | 4010 |
4002 curwin->w_pcmark.lnum = 1; | 4011 curwin->w_pcmark.lnum = 1; |
4003 curwin->w_pcmark.col = 0; | 4012 curwin->w_pcmark.col = 0; |
4069 buf = curbuf; | 4078 buf = curbuf; |
4070 if (buf->b_fname != NULL) | 4079 if (buf->b_fname != NULL) |
4071 new_name = vim_strsave(buf->b_fname); | 4080 new_name = vim_strsave(buf->b_fname); |
4072 else | 4081 else |
4073 new_name = NULL; | 4082 new_name = NULL; |
4083 set_bufref(&bufref, buf); | |
4074 #endif | 4084 #endif |
4075 if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) | 4085 if (p_ur < 0 || curbuf->b_ml.ml_line_count <= p_ur) |
4076 { | 4086 { |
4077 /* Save all the text, so that the reload can be undone. | 4087 /* Save all the text, so that the reload can be undone. |
4078 * Sync first so that this is a separate undo-able action. */ | 4088 * Sync first so that this is a separate undo-able action. */ |
4089 else | 4099 else |
4090 buf_freeall(curbuf, 0); /* free all things for buffer */ | 4100 buf_freeall(curbuf, 0); /* free all things for buffer */ |
4091 #ifdef FEAT_AUTOCMD | 4101 #ifdef FEAT_AUTOCMD |
4092 /* If autocommands deleted the buffer we were going to re-edit, give | 4102 /* If autocommands deleted the buffer we were going to re-edit, give |
4093 * up and jump to the end. */ | 4103 * up and jump to the end. */ |
4094 if (!buf_valid(buf)) | 4104 if (!bufref_valid(&bufref)) |
4095 { | 4105 { |
4096 delbuf_msg(new_name); /* frees new_name */ | 4106 delbuf_msg(new_name); /* frees new_name */ |
4097 goto theend; | 4107 goto theend; |
4098 } | 4108 } |
4099 vim_free(new_name); | 4109 vim_free(new_name); |
4373 delbuf_msg(char_u *name) | 4383 delbuf_msg(char_u *name) |
4374 { | 4384 { |
4375 EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), | 4385 EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), |
4376 name == NULL ? (char_u *)"" : name); | 4386 name == NULL ? (char_u *)"" : name); |
4377 vim_free(name); | 4387 vim_free(name); |
4378 au_new_curbuf = NULL; | 4388 au_new_curbuf.br_buf = NULL; |
4379 } | 4389 } |
4380 #endif | 4390 #endif |
4381 | 4391 |
4382 static int append_indent = 0; /* autoindent for first line */ | 4392 static int append_indent = 0; /* autoindent for first line */ |
4383 | 4393 |