comparison src/buffer.c @ 16453:4e9bea9b8025 v8.1.1231

patch 8.1.1231: asking about existing swap file unnecessarily commit https://github.com/vim/vim/commit/67cf86bfff5fd5224d557d81cb146f46e33b831c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Apr 28 22:25:38 2019 +0200 patch 8.1.1231: asking about existing swap file unnecessarily Problem: Asking about existing swap file unnecessarily. Solution: When it is safe, delete the swap file. Remove HAS_SWAP_EXISTS_ACTION, it is always defined. (closes #1237)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Apr 2019 22:30:06 +0200
parents 54ffc82f38a8
children ca1814eeecf5
comparison
equal deleted inserted replaced
16452:a311ea84a94c 16453:4e9bea9b8025
970 exarg_T *eap, 970 exarg_T *eap,
971 int start, 971 int start,
972 int dir, 972 int dir,
973 int count) 973 int count)
974 { 974 {
975 #if defined(HAS_SWAP_EXISTS_ACTION)
976 bufref_T old_curbuf; 975 bufref_T old_curbuf;
977 976
978 set_bufref(&old_curbuf, curbuf); 977 set_bufref(&old_curbuf, curbuf);
979 978
980 swap_exists_action = SEA_DIALOG; 979 swap_exists_action = SEA_DIALOG;
981 #endif
982 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, 980 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO,
983 start, dir, count, eap->forceit); 981 start, dir, count, eap->forceit);
984 #if defined(HAS_SWAP_EXISTS_ACTION)
985 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') 982 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's')
986 { 983 {
987 # if defined(FEAT_EVAL) 984 #if defined(FEAT_EVAL)
988 cleanup_T cs; 985 cleanup_T cs;
989 986
990 /* Reset the error/interrupt/exception state here so that 987 /* Reset the error/interrupt/exception state here so that
991 * aborting() returns FALSE when closing a window. */ 988 * aborting() returns FALSE when closing a window. */
992 enter_cleanup(&cs); 989 enter_cleanup(&cs);
993 # endif 990 #endif
994 991
995 /* Quitting means closing the split window, nothing else. */ 992 /* Quitting means closing the split window, nothing else. */
996 win_close(curwin, TRUE); 993 win_close(curwin, TRUE);
997 swap_exists_action = SEA_NONE; 994 swap_exists_action = SEA_NONE;
998 swap_exists_did_quit = TRUE; 995 swap_exists_did_quit = TRUE;
999 996
1000 # if defined(FEAT_EVAL) 997 #if defined(FEAT_EVAL)
1001 /* Restore the error/interrupt/exception state if not discarded by a 998 /* Restore the error/interrupt/exception state if not discarded by a
1002 * new aborting error, interrupt, or uncaught exception. */ 999 * new aborting error, interrupt, or uncaught exception. */
1003 leave_cleanup(&cs); 1000 leave_cleanup(&cs);
1004 # endif 1001 #endif
1005 } 1002 }
1006 else 1003 else
1007 handle_swap_exists(&old_curbuf); 1004 handle_swap_exists(&old_curbuf);
1008 #endif 1005 }
1009 } 1006
1010
1011 #if defined(HAS_SWAP_EXISTS_ACTION) || defined(PROTO)
1012 /* 1007 /*
1013 * Handle the situation of swap_exists_action being set. 1008 * Handle the situation of swap_exists_action being set.
1014 * It is allowed for "old_curbuf" to be NULL or invalid. 1009 * It is allowed for "old_curbuf" to be NULL or invalid.
1015 */ 1010 */
1016 void 1011 void
1017 handle_swap_exists(bufref_T *old_curbuf) 1012 handle_swap_exists(bufref_T *old_curbuf)
1018 { 1013 {
1019 # if defined(FEAT_EVAL) 1014 #if defined(FEAT_EVAL)
1020 cleanup_T cs; 1015 cleanup_T cs;
1021 # endif 1016 #endif
1022 # ifdef FEAT_SYN_HL 1017 #ifdef FEAT_SYN_HL
1023 long old_tw = curbuf->b_p_tw; 1018 long old_tw = curbuf->b_p_tw;
1024 # endif 1019 #endif
1025 buf_T *buf; 1020 buf_T *buf;
1026 1021
1027 if (swap_exists_action == SEA_QUIT) 1022 if (swap_exists_action == SEA_QUIT)
1028 { 1023 {
1029 # if defined(FEAT_EVAL) 1024 #if defined(FEAT_EVAL)
1030 /* Reset the error/interrupt/exception state here so that 1025 /* Reset the error/interrupt/exception state here so that
1031 * aborting() returns FALSE when closing a buffer. */ 1026 * aborting() returns FALSE when closing a buffer. */
1032 enter_cleanup(&cs); 1027 enter_cleanup(&cs);
1033 # endif 1028 #endif
1034 1029
1035 /* User selected Quit at ATTENTION prompt. Go back to previous 1030 /* User selected Quit at ATTENTION prompt. Go back to previous
1036 * buffer. If that buffer is gone or the same as the current one, 1031 * buffer. If that buffer is gone or the same as the current one,
1037 * open a new, empty buffer. */ 1032 * open a new, empty buffer. */
1038 swap_exists_action = SEA_NONE; /* don't want it again */ 1033 swap_exists_action = SEA_NONE; /* don't want it again */
1051 msg_silent = 1; // prevent fileinfo message 1046 msg_silent = 1; // prevent fileinfo message
1052 enter_buffer(buf); 1047 enter_buffer(buf);
1053 // restore msg_silent, so that the command line will be shown 1048 // restore msg_silent, so that the command line will be shown
1054 msg_silent = old_msg_silent; 1049 msg_silent = old_msg_silent;
1055 1050
1056 # ifdef FEAT_SYN_HL 1051 #ifdef FEAT_SYN_HL
1057 if (old_tw != curbuf->b_p_tw) 1052 if (old_tw != curbuf->b_p_tw)
1058 check_colorcolumn(curwin); 1053 check_colorcolumn(curwin);
1059 # endif 1054 #endif
1060 } 1055 }
1061 /* If "old_curbuf" is NULL we are in big trouble here... */ 1056 /* If "old_curbuf" is NULL we are in big trouble here... */
1062 1057
1063 # if defined(FEAT_EVAL) 1058 #if defined(FEAT_EVAL)
1064 /* Restore the error/interrupt/exception state if not discarded by a 1059 /* Restore the error/interrupt/exception state if not discarded by a
1065 * new aborting error, interrupt, or uncaught exception. */ 1060 * new aborting error, interrupt, or uncaught exception. */
1066 leave_cleanup(&cs); 1061 leave_cleanup(&cs);
1067 # endif 1062 #endif
1068 } 1063 }
1069 else if (swap_exists_action == SEA_RECOVER) 1064 else if (swap_exists_action == SEA_RECOVER)
1070 { 1065 {
1071 # if defined(FEAT_EVAL) 1066 #if defined(FEAT_EVAL)
1072 /* Reset the error/interrupt/exception state here so that 1067 /* Reset the error/interrupt/exception state here so that
1073 * aborting() returns FALSE when closing a buffer. */ 1068 * aborting() returns FALSE when closing a buffer. */
1074 enter_cleanup(&cs); 1069 enter_cleanup(&cs);
1075 # endif 1070 #endif
1076 1071
1077 /* User selected Recover at ATTENTION prompt. */ 1072 /* User selected Recover at ATTENTION prompt. */
1078 msg_scroll = TRUE; 1073 msg_scroll = TRUE;
1079 ml_recover(); 1074 ml_recover();
1080 msg_puts("\n"); /* don't overwrite the last message */ 1075 msg_puts("\n"); /* don't overwrite the last message */
1081 cmdline_row = msg_row; 1076 cmdline_row = msg_row;
1082 do_modelines(0); 1077 do_modelines(0);
1083 1078
1084 # if defined(FEAT_EVAL) 1079 #if defined(FEAT_EVAL)
1085 /* Restore the error/interrupt/exception state if not discarded by a 1080 /* Restore the error/interrupt/exception state if not discarded by a
1086 * new aborting error, interrupt, or uncaught exception. */ 1081 * new aborting error, interrupt, or uncaught exception. */
1087 leave_cleanup(&cs); 1082 leave_cleanup(&cs);
1088 # endif 1083 #endif
1089 } 1084 }
1090 swap_exists_action = SEA_NONE; 1085 swap_exists_action = SEA_NONE;
1091 } 1086 }
1092 #endif
1093 1087
1094 /* 1088 /*
1095 * do_bufdel() - delete or unload buffer(s) 1089 * do_bufdel() - delete or unload buffer(s)
1096 * 1090 *
1097 * addr_count == 0: ":bdel" - delete current buffer 1091 * addr_count == 0: ":bdel" - delete current buffer
5257 p_ea = p_ea_save; 5251 p_ea = p_ea_save;
5258 if (split_ret == FAIL) 5252 if (split_ret == FAIL)
5259 continue; 5253 continue;
5260 5254
5261 /* Open the buffer in this window. */ 5255 /* Open the buffer in this window. */
5262 #if defined(HAS_SWAP_EXISTS_ACTION)
5263 swap_exists_action = SEA_DIALOG; 5256 swap_exists_action = SEA_DIALOG;
5264 #endif
5265 set_curbuf(buf, DOBUF_GOTO); 5257 set_curbuf(buf, DOBUF_GOTO);
5266 if (!bufref_valid(&bufref)) 5258 if (!bufref_valid(&bufref))
5267 { 5259 {
5268 /* autocommands deleted the buffer!!! */ 5260 /* autocommands deleted the buffer!!! */
5269 #if defined(HAS_SWAP_EXISTS_ACTION)
5270 swap_exists_action = SEA_NONE; 5261 swap_exists_action = SEA_NONE;
5271 #endif
5272 break; 5262 break;
5273 } 5263 }
5274 #if defined(HAS_SWAP_EXISTS_ACTION)
5275 if (swap_exists_action == SEA_QUIT) 5264 if (swap_exists_action == SEA_QUIT)
5276 { 5265 {
5277 # if defined(FEAT_EVAL) 5266 #if defined(FEAT_EVAL)
5278 cleanup_T cs; 5267 cleanup_T cs;
5279 5268
5280 /* Reset the error/interrupt/exception state here so that 5269 /* Reset the error/interrupt/exception state here so that
5281 * aborting() returns FALSE when closing a window. */ 5270 * aborting() returns FALSE when closing a window. */
5282 enter_cleanup(&cs); 5271 enter_cleanup(&cs);
5283 # endif 5272 #endif
5284 5273
5285 /* User selected Quit at ATTENTION prompt; close this window. */ 5274 /* User selected Quit at ATTENTION prompt; close this window. */
5286 win_close(curwin, TRUE); 5275 win_close(curwin, TRUE);
5287 --open_wins; 5276 --open_wins;
5288 swap_exists_action = SEA_NONE; 5277 swap_exists_action = SEA_NONE;
5289 swap_exists_did_quit = TRUE; 5278 swap_exists_did_quit = TRUE;
5290 5279
5291 # if defined(FEAT_EVAL) 5280 #if defined(FEAT_EVAL)
5292 /* Restore the error/interrupt/exception state if not 5281 /* Restore the error/interrupt/exception state if not
5293 * discarded by a new aborting error, interrupt, or uncaught 5282 * discarded by a new aborting error, interrupt, or uncaught
5294 * exception. */ 5283 * exception. */
5295 leave_cleanup(&cs); 5284 leave_cleanup(&cs);
5296 # endif 5285 #endif
5297 } 5286 }
5298 else 5287 else
5299 handle_swap_exists(NULL); 5288 handle_swap_exists(NULL);
5300 #endif
5301 } 5289 }
5302 5290
5303 ui_breakcheck(); 5291 ui_breakcheck();
5304 if (got_int) 5292 if (got_int)
5305 { 5293 {