diff options
author | Bram Moolenaar <Bram@vim.org> | 2005-12-07 21:07:59 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2005-12-07 21:07:59 +0000 |
commit | d5bc83f576a26dd27fab558fdee472838b66bbb4 (patch) | |
tree | 6cb34a2983a9dc0883b2a9d6d6b3e6d13d80c207 /src | |
parent | 4e330bbf216ca93827778c2dcc8aa1a8f053c9e1 (diff) |
updated for version 7.0164v7.0164
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/ex_cmds.c | 4 | ||||
-rw-r--r-- | src/main.c | 12 | ||||
-rw-r--r-- | src/memline.c | 194 |
4 files changed, 150 insertions, 62 deletions
diff --git a/src/eval.c b/src/eval.c index d1271987e7..04772225c7 100644 --- a/src/eval.c +++ b/src/eval.c @@ -338,6 +338,8 @@ static struct vimvar {VV_NAME("beval_col", VAR_NUMBER), VV_RO}, {VV_NAME("beval_text", VAR_STRING), VV_RO}, {VV_NAME("scrollstart", VAR_STRING), 0}, + {VV_NAME("swapname", VAR_STRING), VV_RO}, + {VV_NAME("swapchoice", VAR_STRING), 0}, }; /* shorthand */ diff --git a/src/ex_cmds.c b/src/ex_cmds.c index b6fab2c14f..d1d3ae1080 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -3420,7 +3420,7 @@ do_ecmd(fnum, ffname, sfname, eap, newlnum, flags) topline = curwin->w_topline; if (!oldbuf) /* need to read the file */ { -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) swap_exists_action = SEA_DIALOG; #endif curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ @@ -3435,7 +3435,7 @@ do_ecmd(fnum, ffname, sfname, eap, newlnum, flags) (void)open_buffer(FALSE, eap); #endif -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) if (swap_exists_action == SEA_QUIT) retval = FAIL; handle_swap_exists(old_curbuf); diff --git a/src/main.c b/src/main.c index 658f4e1ea5..fd4f4e44e9 100644 --- a/src/main.c +++ b/src/main.c @@ -116,7 +116,7 @@ static void exe_pre_commands __ARGS((mparm_T *parmp)); static void exe_commands __ARGS((mparm_T *parmp)); static void source_startup_scripts __ARGS((mparm_T *parmp)); static void main_start_gui __ARGS((void)); -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) static void check_swap_exists_action __ARGS((void)); #endif #ifdef FEAT_CLIENTSERVER @@ -2150,7 +2150,7 @@ read_stdin() { int i; -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) /* When getting the ATTENTION prompt here, use a dialog */ swap_exists_action = SEA_DIALOG; #endif @@ -2161,7 +2161,7 @@ read_stdin() no_wait_return = FALSE; msg_didany = i; TIME_MSG("reading stdin"); -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) check_swap_exists_action(); #endif #if !(defined(AMIGA) || defined(MACOS)) @@ -2245,14 +2245,14 @@ create_windows(parmp) if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; #endif -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) /* When getting the ATTENTION prompt here, use a dialog */ swap_exists_action = SEA_DIALOG; #endif set_buflisted(TRUE); (void)open_buffer(FALSE, NULL); /* create memfile, read file */ -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) check_swap_exists_action(); #endif #ifdef FEAT_AUTOCMD @@ -2872,7 +2872,7 @@ usage() mch_exit(0); } -#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) +#if defined(HAS_SWAP_EXISTS_ACTION) /* * Check the result of the ATTENTION dialog: * When "Quit" selected, exit Vim. diff --git a/src/memline.c b/src/memline.c index a2ec5b224d..a6ab42c4e2 100644 --- a/src/memline.c +++ b/src/memline.c @@ -1595,7 +1595,7 @@ static int process_still_running; #endif /* - * Give information about an existing swap file + * Give information about an existing swap file. * Returns timestamp (0 when unknown). */ static time_t @@ -3494,6 +3494,93 @@ get_file_in_dir(fname, dname) return retval; } +static void attention_message __ARGS((buf_T *buf, char_u *fname)); + +/* + * Print the ATTENTION message: info about an existing swap file. + */ + static void +attention_message(buf, fname) + buf_T *buf; /* buffer being edited */ + char_u *fname; /* swap file name */ +{ + struct stat st; + time_t x, sx; + + ++no_wait_return; + (void)EMSG(_("E325: ATTENTION")); + MSG_PUTS(_("\nFound a swap file by the name \"")); + msg_home_replace(fname); + MSG_PUTS("\"\n"); + sx = swapfile_info(fname); + MSG_PUTS(_("While opening file \"")); + msg_outtrans(buf->b_fname); + MSG_PUTS("\"\n"); + if (mch_stat((char *)buf->b_fname, &st) != -1) + { + MSG_PUTS(_(" dated: ")); + x = st.st_mtime; /* Manx C can't do &st.st_mtime */ + MSG_PUTS(ctime(&x)); + if (sx != 0 && x > sx) + MSG_PUTS(_(" NEWER than swap file!\n")); + } + /* Some of these messages are long to allow translation to + * other languages. */ + MSG_PUTS(_("\n(1) Another program may be editing the same file.\n If this is the case, be careful not to end up with two\n different instances of the same file when making changes.\n")); + MSG_PUTS(_(" Quit, or continue with caution.\n")); + MSG_PUTS(_("\n(2) An edit session for this file crashed.\n")); + MSG_PUTS(_(" If this is the case, use \":recover\" or \"vim -r ")); + msg_outtrans(buf->b_fname); + MSG_PUTS(_("\"\n to recover the changes (see \":help recovery\").\n")); + MSG_PUTS(_(" If you did this already, delete the swap file \"")); + msg_outtrans(fname); + MSG_PUTS(_("\"\n to avoid this message.\n")); + cmdline_row = msg_row; + --no_wait_return; +} + +#ifdef FEAT_AUTOCMD +static int do_swapexists __ARGS((buf_T *buf, char_u *fname)); + +/* + * Trigger the SwapExists autocommands. + * Returns a value for equivalent to do_dialog() (see below): + * 0: still need to ask for a choice + * 1: open read-only + * 2: edit anyway + * 3: recover + * 4: delete it + * 5: quit + * 6: abort + */ + static int +do_swapexists(buf, fname) + buf_T *buf; + char_u *fname; +{ + set_vim_var_string(VV_SWAPNAME, fname, -1); + set_vim_var_string(VV_SWAPCHOICE, NULL, -1); + + /* Trigger SwapExists autocommands with <afile> set to the file being + * edited. */ + apply_autocmds(EVENT_SWAPEXISTS, buf->b_fname, NULL, FALSE, NULL); + + set_vim_var_string(VV_SWAPNAME, NULL, -1); + + switch (*get_vim_var_str(VV_SWAPCHOICE)) + { + case 'o': return 1; + case 'e': return 2; + case 'r': return 3; + case 'd': return 4; + case 'q': return 5; + case 'a': return 6; + } + + return 0; +} +#endif + /* * Find out what name to use for the swap file for buffer 'buf'. * @@ -3511,7 +3598,6 @@ findswapname(buf, dirp, old_fname) { char_u *fname; int n; - time_t x, sx; char_u *dir_name; #ifdef AMIGA BPTR fh; @@ -3797,7 +3883,9 @@ findswapname(buf, dirp, old_fname) if (differ == FALSE && !(curbuf->b_flags & BF_RECOVERED) && vim_strchr(p_shm, SHM_ATTENTION) == NULL) { - struct stat st; +#if defined(HAS_SWAP_EXISTS_ACTION) + int choice = 0; +#endif #ifdef CREATE_DUMMY_FILE int did_use_dummy = FALSE; @@ -3813,55 +3901,41 @@ findswapname(buf, dirp, old_fname) did_use_dummy = TRUE; } #endif -#ifdef FEAT_GUI - /* If we are supposed to start the GUI but it wasn't - * completely started yet, start it now. This makes the - * messages displayed in the Vim window when loading a - * session from the .gvimrc file. */ - if (gui.starting && !gui.in_use) - gui_start(); -#endif #if (defined(UNIX) || defined(__EMX__) || defined(VMS)) && (defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)) process_still_running = FALSE; #endif - ++no_wait_return; - (void)EMSG(_("E325: ATTENTION")); - MSG_PUTS(_("\nFound a swap file by the name \"")); - msg_home_replace(fname); - MSG_PUTS("\"\n"); - sx = swapfile_info(fname); - MSG_PUTS(_("While opening file \"")); - msg_outtrans(buf->b_fname); - MSG_PUTS("\"\n"); - if (mch_stat((char *)buf->b_fname, &st) != -1) +#ifdef FEAT_AUTOCMD + /* + * If there is an SwapExists autocommand and we can handle + * the response, trigger it. It may return 0 to ask the + * user anyway. + */ + if (swap_exists_action != SEA_NONE + && has_autocmd(EVENT_SWAPEXISTS, buf->b_fname, buf)) + choice = do_swapexists(buf, fname); + + if (choice == 0) +#endif { - MSG_PUTS(_(" dated: ")); - x = st.st_mtime; /* Manx C can't do &st.st_mtime */ - MSG_PUTS(ctime(&x)); - if (sx != 0 && x > sx) - MSG_PUTS(_(" NEWER than swap file!\n")); +#ifdef FEAT_GUI + /* If we are supposed to start the GUI but it wasn't + * completely started yet, start it now. This makes + * the messages displayed in the Vim window when + * loading a session from the .gvimrc file. */ + if (gui.starting && !gui.in_use) + gui_start(); +#endif + /* Show info about the existing swap file. */ + attention_message(buf, fname); + + /* We don't want a 'q' typed at the more-prompt + * interrupt loading a file. */ + got_int = FALSE; } - /* Some of these messages are long to allow translation to - * other languages. */ - MSG_PUTS(_("\n(1) Another program may be editing the same file.\n If this is the case, be careful not to end up with two\n different instances of the same file when making changes.\n")); - MSG_PUTS(_(" Quit, or continue with caution.\n")); - MSG_PUTS(_("\n(2) An edit session for this file crashed.\n")); - MSG_PUTS(_(" If this is the case, use \":recover\" or \"vim -r ")); - msg_outtrans(buf->b_fname); - MSG_PUTS(_("\"\n to recover the changes (see \":help recovery\").\n")); - MSG_PUTS(_(" If you did this already, delete the swap file \"")); - msg_outtrans(fname); - MSG_PUTS(_("\"\n to avoid this message.\n")); - cmdline_row = msg_row; - --no_wait_return; - - /* We don't want a 'q' typed at the more-prompt interrupt - * loading a file. */ - got_int = FALSE; #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) - if (swap_exists_action) + if (swap_exists_action != SEA_NONE && choice == 0) { char_u *name; @@ -3875,7 +3949,7 @@ findswapname(buf, dirp, old_fname) 1000, TRUE); STRCAT(name, _("\" already exists!")); } - switch (do_dialog(VIM_WARNING, + choice = do_dialog(VIM_WARNING, (char_u *)_("VIM - ATTENTION"), name == NULL ? (char_u *)_("Swap file already exists!") @@ -3884,7 +3958,24 @@ findswapname(buf, dirp, old_fname) process_still_running ? (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort") : # endif - (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Quit\n&Abort\n&Delete it"), 1, NULL)) + (char_u *)_("&Open Read-Only\n&Edit anyway\n&Recover\n&Delete it\n&Quit\n&Abort"), 1, NULL); + +# if defined(UNIX) || defined(__EMX__) || defined(VMS) + if (process_still_running && choice >= 4) + choice++; /* Skip missing "Delete it" button */ +# endif + vim_free(name); + + /* pretend screen didn't scroll, need redraw anyway */ + msg_scrolled = 0; + redraw_all_later(NOT_VALID); + } +#endif + +#if defined(HAS_SWAP_EXISTS_ACTION) + if (choice > 0) + { + switch (choice) { case 1: buf->b_p_ro = TRUE; @@ -3895,21 +3986,16 @@ findswapname(buf, dirp, old_fname) swap_exists_action = SEA_RECOVER; break; case 4: - swap_exists_action = SEA_QUIT; + mch_remove(fname); break; case 5: swap_exists_action = SEA_QUIT; - got_int = TRUE; break; case 6: - mch_remove(fname); + swap_exists_action = SEA_QUIT; + got_int = TRUE; break; } - vim_free(name); - - /* pretend screen didn't scroll, need redraw anyway */ - msg_scrolled = 0; - redraw_all_later(NOT_VALID); /* If the file was deleted this fname can be used. */ if (mch_getperm(fname) < 0) |