=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/vim/Attic/cmdline.c,v retrieving revision 1.1 retrieving revision 1.2 diff -c -r1.1 -r1.2 *** src/usr.bin/vim/Attic/cmdline.c 1996/09/07 21:40:26 1.1 --- src/usr.bin/vim/Attic/cmdline.c 1996/09/21 06:22:54 1.2 *************** *** 1,4 **** ! /* $OpenBSD: cmdline.c,v 1.1 1996/09/07 21:40:26 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar --- 1,4 ---- ! /* $OpenBSD: cmdline.c,v 1.2 1996/09/21 06:22:54 downsj Exp $ */ /* vi:set ts=4 sw=4: * * VIM - Vi IMproved by Bram Moolenaar *************** *** 37,50 **** */ static int overstrike = FALSE; /* typing mode */ - /* - * The next two variables contain the bounds of any range given in a command. - * They are set by do_cmdline(). - */ - static linenr_t line1, line2; - - static int forceit; - static int regname; static int quitmore = 0; static int cmd_numfiles = -1; /* number of files found by filename completion */ --- 37,42 ---- *************** *** 70,85 **** static int ccheck_abbr __ARGS((int)); static char_u *do_one_cmd __ARGS((char_u **, int *, int)); static int buf_write_all __ARGS((BUF *)); ! static int do_write __ARGS((char_u *, int)); static char_u *getargcmd __ARGS((char_u **)); static void backslash_halve __ARGS((char_u *p, int expand_wildcards)); static void do_make __ARGS((char_u *)); static int do_arglist __ARGS((char_u *)); static int is_backslash __ARGS((char_u *str)); ! static int check_readonly __ARGS((void)); ! static int check_changed __ARGS((BUF *, int, int)); static int check_changed_any __ARGS((void)); ! static int check_more __ARGS((int)); static void vim_strncpy __ARGS((char_u *, char_u *, int)); static int nextwild __ARGS((int)); static int showmatches __ARGS((char_u *)); --- 62,77 ---- static int ccheck_abbr __ARGS((int)); static char_u *do_one_cmd __ARGS((char_u **, int *, int)); static int buf_write_all __ARGS((BUF *)); ! static int do_write __ARGS((char_u *, linenr_t, linenr_t, int, int)); static char_u *getargcmd __ARGS((char_u **)); static void backslash_halve __ARGS((char_u *p, int expand_wildcards)); static void do_make __ARGS((char_u *)); static int do_arglist __ARGS((char_u *)); static int is_backslash __ARGS((char_u *str)); ! static int check_readonly __ARGS((int)); ! static int check_changed __ARGS((BUF *, int, int, int)); static int check_changed_any __ARGS((void)); ! static int check_more __ARGS((int, int)); static void vim_strncpy __ARGS((char_u *, char_u *, int)); static int nextwild __ARGS((int)); static int showmatches __ARGS((char_u *)); *************** *** 315,320 **** --- 307,313 ---- if (lookfor && c != K_S_DOWN && c != K_S_UP && c != K_DOWN && c != K_UP && c != K_PAGEDOWN && c != K_PAGEUP && + c != K_KPAGEDOWN && c != K_KPAGEUP && (cmd_numfiles > 0 || (c != Ctrl('P') && c != Ctrl('N')))) { vim_free(lookfor); *************** *** 545,556 **** --- 538,551 ---- case Ctrl('B'): /* begin of command line */ case K_HOME: + case K_KHOME: cmdpos = 0; cmdspos = 1; goto cmdline_not_changed; case Ctrl('E'): /* end of command line */ case K_END: + case K_KEND: cmdpos = cmdlen; cmdbuff[cmdlen] = NUL; cmdspos = strsize(cmdbuff) + 1; *************** *** 580,586 **** --- 575,583 ---- case K_S_UP: case K_S_DOWN: case K_PAGEUP: + case K_KPAGEUP: case K_PAGEDOWN: + case K_KPAGEDOWN: if (hislen == 0) /* no history */ goto cmdline_not_changed; *************** *** 596,602 **** { /* one step backwards */ if (c == K_UP || c == K_S_UP || c == Ctrl('P') || ! c == K_PAGEUP) { if (hiscnt == hislen) /* first time */ hiscnt = hisidx[histype]; --- 593,599 ---- { /* one step backwards */ if (c == K_UP || c == K_S_UP || c == Ctrl('P') || ! c == K_PAGEUP || c == K_KPAGEUP) { if (hiscnt == hislen) /* first time */ hiscnt = hisidx[histype]; *************** *** 1164,1177 **** --- 1161,1178 ---- long argt; register linenr_t lnum; long n = 0; /* init to shut up gcc */ + linenr_t line1 = 1, line2 = 1; /* the command range */ int addr_count; /* number of address specs */ + int forceit = FALSE; /* '!' after command */ FPOS pos; int append = FALSE; /* write with append */ int usefilter = FALSE; /* no read/write but filter */ + int regname = 0; /* register name flag */ char_u *nextcomm = NULL; /* no next command yet */ int amount = 0; /* for ":>"; init for gcc */ char_u *errormsg = NULL; /* error message */ WIN *old_curwin = NULL; /* init for GCC */ + static int if_level = 0; /* depth in :if */ /* when not editing the last file :q has to be typed twice */ if (quitmore) *************** *** 1206,1211 **** --- 1207,1215 ---- */ addr_count = 0; + if (if_level) + goto skip_address; + --cmd; do { *************** *** 1261,1266 **** --- 1265,1271 ---- if (lnum == MAXLNUM) addr_count = 0; } + skip_address: /* * 4. parse command *************** *** 1287,1292 **** --- 1292,1299 ---- * ":3|..." prints line 3 * ":|" prints current line */ + if (if_level) /* skip this if inside :if */ + goto doend; if (*cmd == '|') { cmdidx = CMD_print; *************** *** 1341,1357 **** break; if (i == 0 || cmdidx == CMD_SIZE) { ! STRCPY(IObuff, "Not an editor command"); ! if (!sourcing) { ! STRCAT(IObuff, ": "); ! STRNCAT(IObuff, *cmdlinep, 40); } - errormsg = IObuff; goto doend; } } if (*p == '!') /* forced commands */ { ++p; --- 1348,1380 ---- break; if (i == 0 || cmdidx == CMD_SIZE) { ! if (if_level == 0) { ! STRCPY(IObuff, "Not an editor command"); ! if (!sourcing) ! { ! STRCAT(IObuff, ": "); ! STRNCAT(IObuff, *cmdlinep, 40); ! } ! errormsg = IObuff; } goto doend; } } + /* + * Handle the future ":if" command. + * For version 4 everything between ":if" and ":endif" is ignored. + */ + if (cmdidx == CMD_if) + ++if_level; + if (if_level) + { + if (cmdidx == CMD_endif) + --if_level; + goto doend; + } + if (*p == '!') /* forced commands */ { ++p; *************** *** 1571,1577 **** line2 = curbuf->b_ml.ml_line_count; } - regname = 0; /* accept numbered register only when no count allowed (:put) */ if ((argt & REGSTR) && *arg != NUL && is_yank_buffer(*arg, FALSE) && !((argt & COUNT) && isdigit(*arg))) --- 1594,1599 ---- *************** *** 1646,1655 **** #define SPEC_CCWORD 3 "", /* cursor path name */ #define SPEC_CFILE 4 "" /* autocommand file name */ ! #define SPEC_AFILE 5 }; ! #define SPEC_COUNT 6 /* * Decide to expand wildcards *before* replacing '%', '#', etc. If --- 1668,1679 ---- #define SPEC_CCWORD 3 "", /* cursor path name */ #define SPEC_CFILE 4 + #ifdef AUTOCMD "" /* autocommand file name */ ! # define SPEC_AFILE 5 ! #endif }; ! #define SPEC_COUNT (sizeof(spec_str) / sizeof(char *)) /* * Decide to expand wildcards *before* replacing '%', '#', etc. If *************** *** 1660,1665 **** --- 1684,1695 ---- for (p = arg; *p; ++p) { /* + * Quick check if this cannot be the start of a special string. + */ + if (vim_strchr((char_u *)"%#<", *p) == NULL) + continue; + + /* * Check if there is something to do. */ for (spec_idx = 0; spec_idx < SPEC_COUNT; ++spec_idx) *************** *** 1733,1738 **** --- 1763,1769 ---- buf = q; break; + #ifdef AUTOCMD case SPEC_AFILE: /* file name for autocommand */ q = autocmd_fname; if (q == NULL) *************** *** 1741,1746 **** --- 1772,1778 ---- goto doend; } break; + #endif } len = STRLEN(q); /* length of new string */ *************** *** 1771,1783 **** /* ":h" - head, remove "/filename" */ /* ":h" can be repeated */ while (p[n] == ':' && p[n + 1] == 'h') { n += 2; ! while (tail > q && ispathsep(tail[-1])) --tail; len = tail - q; ! while (tail > q && !ispathsep(tail[-1])) --tail; } --- 1803,1817 ---- /* ":h" - head, remove "/filename" */ /* ":h" can be repeated */ + /* Don't remove the first "/" or "c:\" */ while (p[n] == ':' && p[n + 1] == 'h') { n += 2; ! s = get_past_head(q); ! while (tail > s && ispathsep(tail[-1])) --tail; len = tail - q; ! while (tail > s && !ispathsep(tail[-1])) --tail; } *************** *** 1975,1985 **** */ case CMD_quit: /* if more files or windows we won't exit */ ! if (check_more(FALSE) == OK && only_one_window()) exiting = TRUE; ! if (check_changed(curbuf, FALSE, FALSE) || ! check_more(TRUE) == FAIL || ! (only_one_window() && check_changed_any())) { exiting = FALSE; settmode(1); --- 2009,2019 ---- */ case CMD_quit: /* if more files or windows we won't exit */ ! if (check_more(FALSE, forceit) == OK && only_one_window()) exiting = TRUE; ! if (check_changed(curbuf, FALSE, FALSE, forceit) || ! check_more(TRUE, forceit) == FAIL || ! (only_one_window() && !forceit && check_changed_any())) { exiting = FALSE; settmode(1); *************** *** 1995,2001 **** */ case CMD_qall: exiting = TRUE; ! if (!check_changed_any()) getout(0); exiting = FALSE; settmode(1); --- 2029,2035 ---- */ case CMD_qall: exiting = TRUE; ! if (forceit || !check_changed_any()) getout(0); exiting = FALSE; settmode(1); *************** *** 2043,2054 **** case CMD_xit: case CMD_wq: /* if more files or windows we won't exit */ ! if (check_more(FALSE) == OK && only_one_window()) exiting = TRUE; if (((cmdidx == CMD_wq || curbuf->b_changed) && ! do_write(arg, FALSE) == FAIL) || ! check_more(TRUE) == FAIL || ! (only_one_window() && check_changed_any())) { exiting = FALSE; settmode(1); --- 2077,2088 ---- case CMD_xit: case CMD_wq: /* if more files or windows we won't exit */ ! if (check_more(FALSE, forceit) == OK && only_one_window()) exiting = TRUE; if (((cmdidx == CMD_wq || curbuf->b_changed) && ! do_write(arg, line1, line2, FALSE, forceit) == FAIL) || ! check_more(TRUE, forceit) == FAIL || ! (only_one_window() && !forceit && check_changed_any())) { exiting = FALSE; settmode(1); *************** *** 2083,2090 **** EMSG2("\"%s\" is readonly, use ! to write anyway", buf->b_xfilename); ++error; } ! else if (buf_write_all(buf) == FAIL) ! ++error; } } if (exiting) --- 2117,2132 ---- EMSG2("\"%s\" is readonly, use ! to write anyway", buf->b_xfilename); ++error; } ! else ! { ! if (buf_write_all(buf) == FAIL) ! ++error; ! #ifdef AUTOCMD ! /* an autocommand may have deleted the buffer */ ! if (!buf_valid(buf)) ! buf = firstbuf; ! #endif ! } } } if (exiting) *************** *** 2103,2109 **** case CMD_recover: /* recover file */ recoverymode = TRUE; ! if (!check_changed(curbuf, FALSE, TRUE) && (*arg == NUL || setfname(arg, NULL, TRUE) == OK)) ml_recover(); recoverymode = FALSE; --- 2145,2151 ---- case CMD_recover: /* recover file */ recoverymode = TRUE; ! if (!check_changed(curbuf, FALSE, TRUE, forceit) && (*arg == NUL || setfname(arg, NULL, TRUE) == OK)) ml_recover(); recoverymode = FALSE; *************** *** 2147,2153 **** i = curwin->w_arg_idx - (int)line2; line1 = 1; line2 = curbuf->b_ml.ml_line_count; ! if (do_write(arg, FALSE) == FAIL) break; goto donextfile; --- 2189,2195 ---- i = curwin->w_arg_idx - (int)line2; line1 = 1; line2 = curbuf->b_ml.ml_line_count; ! if (do_write(arg, line1, line2, FALSE, forceit) == FAIL) break; goto donextfile; *************** *** 2159,2165 **** * argument list is not redefined. */ if (!(p_hid || cmdidx == CMD_snext) && ! check_changed(curbuf, TRUE, FALSE)) break; if (*arg != NUL) /* redefine file list */ --- 2201,2207 ---- * argument list is not redefined. */ if (!(p_hid || cmdidx == CMD_snext) && ! check_changed(curbuf, TRUE, FALSE, forceit)) break; if (*arg != NUL) /* redefine file list */ *************** *** 2199,2212 **** if (p_hid) other = otherfile(fix_fname(arg_files[i])); if ((!p_hid || !other) && ! check_changed(curbuf, TRUE, !other)) break; } curwin->w_arg_idx = i; if (i == arg_count - 1) arg_had_last = TRUE; (void)do_ecmd(0, arg_files[curwin->w_arg_idx], ! NULL, do_ecmd_cmd, p_hid, do_ecmd_lnum, FALSE); break; case CMD_previous: --- 2241,2256 ---- if (p_hid) other = otherfile(fix_fname(arg_files[i])); if ((!p_hid || !other) && ! check_changed(curbuf, TRUE, !other, forceit)) break; } curwin->w_arg_idx = i; if (i == arg_count - 1) arg_had_last = TRUE; (void)do_ecmd(0, arg_files[curwin->w_arg_idx], ! NULL, do_ecmd_cmd, do_ecmd_lnum, ! (p_hid ? ECMD_HIDE : 0) + ! (forceit ? ECMD_FORCEIT : 0)); break; case CMD_previous: *************** *** 2319,2325 **** if (usefilter) /* input lines to shell command */ do_bang(1, line1, line2, FALSE, arg, TRUE, FALSE); else ! (void)do_write(arg, append); break; /* --- 2363,2369 ---- if (usefilter) /* input lines to shell command */ do_bang(1, line1, line2, FALSE, arg, TRUE, FALSE); else ! (void)do_write(arg, line1, line2, append, forceit); break; /* *************** *** 2366,2373 **** if ((cmdidx == CMD_new) && *arg == NUL) { setpcmark(); ! (void)do_ecmd(0, NULL, NULL, do_ecmd_cmd, TRUE, ! (linenr_t)1, FALSE); } else if (cmdidx != CMD_split || *arg != NUL) { --- 2410,2417 ---- if ((cmdidx == CMD_new) && *arg == NUL) { setpcmark(); ! (void)do_ecmd(0, NULL, NULL, do_ecmd_cmd, (linenr_t)1, ! ECMD_HIDE + (forceit ? ECMD_FORCEIT : 0)); } else if (cmdidx != CMD_split || *arg != NUL) { *************** *** 2375,2382 **** if (cmdidx == CMD_view || cmdidx == CMD_sview) readonlymode = TRUE; setpcmark(); ! (void)do_ecmd(0, arg, NULL, do_ecmd_cmd, p_hid, ! do_ecmd_lnum, FALSE); readonlymode = n; } else --- 2419,2427 ---- if (cmdidx == CMD_view || cmdidx == CMD_sview) readonlymode = TRUE; setpcmark(); ! (void)do_ecmd(0, arg, NULL, do_ecmd_cmd, do_ecmd_lnum, ! (p_hid ? ECMD_HIDE : 0) + ! (forceit ? ECMD_FORCEIT : 0)); readonlymode = n; } else *************** *** 2385,2390 **** --- 2430,2436 ---- * old window to new file */ if ((cmdidx == CMD_new || cmdidx == CMD_split) && *arg != NUL && curwin != old_curwin && + win_valid(old_curwin) && old_curwin->w_buffer != curbuf) old_curwin->w_alt_fnum = curbuf->b_fnum; break; *************** *** 2541,2551 **** postponed_split = TRUE; /*FALLTHROUGH*/ case CMD_tag: ! do_tag(arg, 0, addr_count ? (int)line2 : 1); break; case CMD_pop: ! do_tag((char_u *)"", 1, addr_count ? (int)line2 : 1); break; case CMD_tags: --- 2587,2597 ---- postponed_split = TRUE; /*FALLTHROUGH*/ case CMD_tag: ! do_tag(arg, 0, addr_count ? (int)line2 : 1, forceit); break; case CMD_pop: ! do_tag((char_u *)"", 1, addr_count ? (int)line2 : 1, forceit); break; case CMD_tags: *************** *** 2772,2777 **** --- 2818,2831 ---- case CMD_put: yankbuffer = regname; + /* + * ":0put" works like ":1put!". + */ + if (line2 == 0) + { + line2 = 1; + forceit = TRUE; + } curwin->w_cursor.lnum = line2; do_put(forceit ? BACKWARD : FORWARD, -1L, FALSE); break; *************** *** 2940,2946 **** } case CMD_cc: ! qf_jump(0, addr_count ? (int)line2 : 0); break; case CMD_cfile: --- 2994,3000 ---- } case CMD_cc: ! qf_jump(0, addr_count ? (int)line2 : 0, forceit); break; case CMD_cfile: *************** *** 2957,2963 **** (void)do_set(arg); } if (qf_init() == OK) ! qf_jump(0, 0); /* display first error */ break; case CMD_clist: --- 3011,3017 ---- (void)do_set(arg); } if (qf_init() == OK) ! qf_jump(0, 0, forceit); /* display first error */ break; case CMD_clist: *************** *** 2965,2980 **** break; case CMD_cnext: ! qf_jump(FORWARD, addr_count ? (int)line2 : 1); break; case CMD_cNext: case CMD_cprevious: ! qf_jump(BACKWARD, addr_count ? (int)line2 : 1); break; case CMD_cquit: ! getout(1); /* this does not always work. why? */ case CMD_mark: case CMD_k: --- 3019,3035 ---- break; case CMD_cnext: ! qf_jump(FORWARD, addr_count ? (int)line2 : 1, forceit); break; case CMD_cNext: case CMD_cprevious: ! qf_jump(BACKWARD, addr_count ? (int)line2 : 1, forceit); break; case CMD_cquit: ! getout(1); /* this does not always pass on the exit ! code to the Manx compiler. why? */ case CMD_mark: case CMD_k: *************** *** 3095,3101 **** } if (did_emsg) nextcomm = NULL; /* cancel nextcomm at an error */ - forceit = FALSE; /* reset now so it can be used in getfile() */ if (nextcomm && *nextcomm == NUL) /* not really a next command */ nextcomm = NULL; return nextcomm; --- 3150,3155 ---- *************** *** 3107,3114 **** * return FAIL for failure, OK otherwise */ int ! autowrite(buf) BUF *buf; { if (!p_aw || (!forceit && buf->b_p_ro) || buf->b_filename == NULL) return FAIL; --- 3161,3169 ---- * return FAIL for failure, OK otherwise */ int ! autowrite(buf, forceit) BUF *buf; + int forceit; { if (!p_aw || (!forceit && buf->b_p_ro) || buf->b_filename == NULL) return FAIL; *************** *** 3127,3133 **** --- 3182,3195 ---- return; for (buf = firstbuf; buf; buf = buf->b_next) if (buf->b_changed && !buf->b_p_ro) + { (void)buf_write_all(buf); + #ifdef AUTOCMD + /* an autocommand may have deleted the buffer */ + if (!buf_valid(buf)) + buf = firstbuf; + #endif + } } /* *************** *** 3139,3146 **** buf_write_all(buf) BUF *buf; { ! return (buf_write(buf, buf->b_filename, buf->b_sfilename, ! (linenr_t)1, buf->b_ml.ml_line_count, 0, 0, TRUE, FALSE)); } /* --- 3201,3219 ---- buf_write_all(buf) BUF *buf; { ! int retval; ! #ifdef AUTOCMD ! BUF *old_curbuf = curbuf; ! #endif ! ! retval = (buf_write(buf, buf->b_filename, buf->b_sfilename, ! (linenr_t)1, buf->b_ml.ml_line_count, ! FALSE, FALSE, TRUE, FALSE)); ! #ifdef AUTOCMD ! if (curbuf != old_curbuf) ! MSG("Warning: Entered other buffer unexpectedly (check autocommands)"); ! #endif ! return retval; } /* *************** *** 3153,3161 **** * return FAIL for failure, OK otherwise */ static int ! do_write(fname, append) ! char_u *fname; ! int append; { int other; char_u *sfname = NULL; /* init to shut up gcc */ --- 3226,3236 ---- * return FAIL for failure, OK otherwise */ static int ! do_write(fname, line1, line2, append, forceit) ! char_u *fname; ! linenr_t line1, line2; ! int append; ! int forceit; { int other; char_u *sfname = NULL; /* init to shut up gcc */ *************** *** 3179,3185 **** * writing to the current file is not allowed in readonly mode * and need a file name */ ! if (!other && (check_readonly() || check_fname() == FAIL)) return FAIL; if (!other) --- 3254,3260 ---- * writing to the current file is not allowed in readonly mode * and need a file name */ ! if (!other && (check_readonly(forceit) || check_fname() == FAIL)) return FAIL; if (!other) *************** *** 3229,3252 **** * - NULL to start an empty buffer * sfname: the short file name (or NULL) * command: the command to be executed after loading the file - * hide: if TRUE don't free the current buffer * newlnum: put cursor on this line number (if possible) ! * set_help: set b_help flag of (new) buffer before opening file * * return FAIL for failure, OK otherwise */ int ! do_ecmd(fnum, fname, sfname, command, hide, newlnum, set_help) int fnum; char_u *fname; char_u *sfname; char_u *command; - int hide; linenr_t newlnum; ! int set_help; { int other_file; /* TRUE if editing another file */ ! int oldbuf = FALSE; /* TRUE if using existing buffer */ BUF *buf; if (fnum != 0) --- 3304,3333 ---- * - NULL to start an empty buffer * sfname: the short file name (or NULL) * command: the command to be executed after loading the file * newlnum: put cursor on this line number (if possible) ! * flags: ! * ECMD_HIDE: if TRUE don't free the current buffer ! * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file ! * ECMD_OLDBUF: use existing buffer if it exists ! * ECMD_FORCEIT: ! used for Ex command * * return FAIL for failure, OK otherwise */ int ! do_ecmd(fnum, fname, sfname, command, newlnum, flags) int fnum; char_u *fname; char_u *sfname; char_u *command; linenr_t newlnum; ! int flags; { int other_file; /* TRUE if editing another file */ ! int oldbuf; /* TRUE if using existing buffer */ ! #ifdef AUTOCMD ! int auto_buf = FALSE; /* TRUE if autocommands brought us ! into the buffer unexpectedly */ ! #endif BUF *buf; if (fnum != 0) *************** *** 3286,3295 **** /* * if the file was changed we may not be allowed to abandon it * - if we are going to re-edit the same file ! * - or if we are the only window on this file and if hide is FALSE */ ! if ((!other_file || (curbuf->b_nwindows == 1 && !hide)) && ! check_changed(curbuf, FALSE, !other_file)) { if (fnum == 0 && other_file && fname != NULL) setaltfname(fname, sfname, (linenr_t)1); --- 3367,3377 ---- /* * if the file was changed we may not be allowed to abandon it * - if we are going to re-edit the same file ! * - or if we are the only window on this file and if ECMD_HIDE is FALSE */ ! if (((!other_file && !(flags & ECMD_OLDBUF)) || ! (curbuf->b_nwindows == 1 && !(flags & ECMD_HIDE))) && ! check_changed(curbuf, FALSE, !other_file, (flags & ECMD_FORCEIT))) { if (fnum == 0 && other_file && fname != NULL) setaltfname(fname, sfname, (linenr_t)1); *************** *** 3321,3377 **** if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ { oldbuf = FALSE; ! buf->b_nwindows = 1; } else /* existing memfile */ { oldbuf = TRUE; - ++buf->b_nwindows; buf_check_timestamp(buf); } /* ! * make the (new) buffer the one used by the current window ! * if the old buffer becomes unused, free it if hide is FALSE * If the current buffer was empty and has no file name, curbuf * is returned by buflist_new(). */ if (buf != curbuf) { #ifdef AUTOCMD apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); #endif #ifdef VIMINFO ! curbuf->b_last_cursor = curwin->w_cursor; #endif ! buf_copy_options(curbuf, buf, TRUE); ! close_buffer(curwin, curbuf, !hide, FALSE); ! curwin->w_buffer = buf; ! curbuf = buf; } curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } ! else if (check_fname() == FAIL) ! return FAIL; /* * If we get here we are sure to start editing */ /* don't redraw until the cursor is in the right line */ ++RedrawingDisabled; ! if (set_help) curbuf->b_help = TRUE; /* * other_file oldbuf * FALSE FALSE re-edit same file, buffer is re-used ! * FALSE TRUE not posible * TRUE FALSE start editing new file, new buffer * TRUE TRUE start editing in existing buffer (nothing to do) */ ! if (!other_file) /* re-use the buffer */ { if (newlnum == 0) newlnum = curwin->w_cursor.lnum; --- 3403,3496 ---- if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ { oldbuf = FALSE; ! buf->b_nwindows = 0; } else /* existing memfile */ { oldbuf = TRUE; buf_check_timestamp(buf); } /* ! * Make the (new) buffer the one used by the current window. ! * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. * If the current buffer was empty and has no file name, curbuf * is returned by buflist_new(). */ if (buf != curbuf) { #ifdef AUTOCMD + BUF *old_curbuf; + char_u *new_name = NULL; + + /* + * Be careful: The autocommands may delete any buffer and change + * the current buffer. + * - If the buffer we are going to edit is deleted, give up. + * - If we ended up in the new buffer already, need to skip a few + * things, set auto_buf. + */ + old_curbuf = curbuf; + if (buf->b_xfilename != NULL) + new_name = strsave(buf->b_xfilename); apply_autocmds(EVENT_BUFLEAVE, NULL, NULL); + if (!buf_valid(buf)) /* new buffer has been deleted */ + { + EMSG2("Autocommands unexpectedly deleted new buffer %s", + new_name == NULL ? (char_u *)"" : new_name); + vim_free(new_name); + return FAIL; + } + vim_free(new_name); + if (buf == curbuf) /* already in new buffer */ + auto_buf = TRUE; + else + { + if (curbuf == old_curbuf) #endif + { #ifdef VIMINFO ! curbuf->b_last_cursor = curwin->w_cursor; #endif ! buf_copy_options(curbuf, buf, TRUE, FALSE); ! } ! close_buffer(curwin, curbuf, !(flags & ECMD_HIDE), FALSE); ! curwin->w_buffer = buf; ! curbuf = buf; ! ++curbuf->b_nwindows; ! #ifdef AUTOCMD ! } ! #endif } + else + ++curbuf->b_nwindows; curwin->w_pcmark.lnum = 1; curwin->w_pcmark.col = 0; } ! else ! { ! if (check_fname() == FAIL) ! return FAIL; ! oldbuf = (flags & ECMD_OLDBUF); ! } /* * If we get here we are sure to start editing */ /* don't redraw until the cursor is in the right line */ ++RedrawingDisabled; ! if (flags & ECMD_SET_HELP) curbuf->b_help = TRUE; /* * other_file oldbuf * FALSE FALSE re-edit same file, buffer is re-used ! * FALSE TRUE re-edit same file, nothing changes * TRUE FALSE start editing new file, new buffer * TRUE TRUE start editing in existing buffer (nothing to do) */ ! if (!other_file && !oldbuf) /* re-use the buffer */ { if (newlnum == 0) newlnum = curwin->w_cursor.lnum; *************** *** 3382,3399 **** } /* * Check if we are editing the w_arg_idx file in the argument list. */ check_arg_idx(); - if (!oldbuf) /* need to read the file */ - (void)open_buffer(); #ifdef AUTOCMD ! else ! apply_autocmds(EVENT_BUFENTER, NULL, NULL); #endif ! win_init(curwin); ! maketitle(); if (command == NULL) { --- 3501,3533 ---- } /* + * Reset cursor position, could be used by autocommands. + */ + adjust_cursor(); + + /* * Check if we are editing the w_arg_idx file in the argument list. */ check_arg_idx(); #ifdef AUTOCMD ! if (!auto_buf) #endif ! { ! /* ! * Careful: open_buffer() and apply_autocmds() may change the current ! * buffer and window. ! */ ! if (!oldbuf) /* need to read the file */ ! (void)open_buffer(); ! #ifdef AUTOCMD ! else ! apply_autocmds(EVENT_BUFENTER, NULL, NULL); ! check_arg_idx(); ! #endif ! win_init(curwin); ! maketitle(); ! } if (command == NULL) { *************** *** 3411,3417 **** * Did not read the file, need to show some info about the file. * Do this after setting the cursor. */ ! if (oldbuf) fileinfo(did_cd, TRUE, FALSE); if (command != NULL) --- 3545,3555 ---- * Did not read the file, need to show some info about the file. * Do this after setting the cursor. */ ! if (oldbuf ! #ifdef AUTOCMD ! && !auto_buf ! #endif ! ) fileinfo(did_cd, TRUE, FALSE); if (command != NULL) *************** *** 3471,3479 **** { for ( ; *p; ++p) if (is_backslash(p) - #if defined(MSDOS) || defined(WIN32) - && p[1] != '*' && p[1] != '?' - #endif #if defined(UNIX) || defined(OS2) && !(expand_wildcards && vim_strchr((char_u *)" *?[{`$\\", p[1])) --- 3609,3614 ---- *************** *** 3495,3501 **** autowrite_all(); vim_remove(p_ef); ! sprintf((char *)IObuff, "%s %s %s", arg, p_sp, p_ef); MSG_OUTSTR(":!"); msg_outtrans(IObuff); /* show what we are doing */ do_shell(IObuff); --- 3630,3636 ---- autowrite_all(); vim_remove(p_ef); ! sprintf((char *)IObuff, "%s%s%s %s %s", p_shq, arg, p_shq, p_sp, p_ef); MSG_OUTSTR(":!"); msg_outtrans(IObuff); /* show what we are doing */ do_shell(IObuff); *************** *** 3507,3513 **** #endif if (qf_init() == OK) ! qf_jump(0, 0); /* display first error */ vim_remove(p_ef); } --- 3642,3648 ---- #endif if (qf_init() == OK) ! qf_jump(0, 0, FALSE); /* display first error */ vim_remove(p_ef); } *************** *** 3608,3615 **** char_u *str; { #ifdef BACKSLASH_IN_FILENAME ! return (str[0] == '\\' && str[1] != NUL && ! !(isfilechar(str[1]) && str[1] != '\\')); #else return (str[0] == '\\' && str[1] != NUL); #endif --- 3743,3750 ---- char_u *str; { #ifdef BACKSLASH_IN_FILENAME ! return (str[0] == '\\' && str[1] != NUL && str[1] != '*' && str[1] != '?' ! && !(isfilechar(str[1]) && str[1] != '\\')); #else return (str[0] == '\\' && str[1] != NUL); #endif *************** *** 3643,3649 **** } static int ! check_readonly() { if (!forceit && curbuf->b_p_ro) { --- 3778,3785 ---- } static int ! check_readonly(forceit) ! int forceit; { if (!forceit && curbuf->b_p_ro) { *************** *** 3657,3670 **** * return TRUE if buffer was changed and cannot be abandoned. */ static int ! check_changed(buf, checkaw, mult_win) BUF *buf; int checkaw; /* do autowrite if buffer was changed */ int mult_win; /* check also when several windows for the buffer */ { if ( !forceit && buf->b_changed && (mult_win || buf->b_nwindows <= 1) && ! (!checkaw || autowrite(buf) == FAIL)) { emsg(e_nowrtmsg); return TRUE; --- 3793,3807 ---- * return TRUE if buffer was changed and cannot be abandoned. */ static int ! check_changed(buf, checkaw, mult_win, forceit) BUF *buf; int checkaw; /* do autowrite if buffer was changed */ int mult_win; /* check also when several windows for the buffer */ + int forceit; { if ( !forceit && buf->b_changed && (mult_win || buf->b_nwindows <= 1) && ! (!checkaw || autowrite(buf, forceit) == FAIL)) { emsg(e_nowrtmsg); return TRUE; *************** *** 3682,3709 **** BUF *buf; int save; ! if (!forceit) { ! for (buf = firstbuf; buf != NULL; buf = buf->b_next) { ! if (buf->b_changed) { ! /* There must be a wait_return for this message, do_buffer ! * will cause a redraw */ ! exiting = FALSE; ! if (EMSG2("No write since last change for buffer \"%s\"", ! buf->b_xfilename == NULL ? (char_u *)"No File" : ! buf->b_xfilename)) ! { ! save = no_wait_return; ! no_wait_return = FALSE; ! wait_return(FALSE); ! no_wait_return = save; ! } ! (void)do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, ! buf->b_fnum, 0); ! return TRUE; } } } return FALSE; --- 3819,3842 ---- BUF *buf; int save; ! for (buf = firstbuf; buf != NULL; buf = buf->b_next) { ! if (buf->b_changed) { ! /* There must be a wait_return for this message, do_buffer ! * will cause a redraw */ ! exiting = FALSE; ! if (EMSG2("No write since last change for buffer \"%s\"", ! buf->b_xfilename == NULL ? (char_u *)"No File" : ! buf->b_xfilename)) { ! save = no_wait_return; ! no_wait_return = FALSE; ! wait_return(FALSE); ! no_wait_return = save; } + (void)do_buffer(DOBUF_GOTO, DOBUF_FIRST, FORWARD, buf->b_fnum, 0); + return TRUE; } } return FALSE; *************** *** 3733,3740 **** * return OK otherwise */ static int ! check_more(message) int message; /* when FALSE check only, no messages */ { if (!forceit && only_one_window() && arg_count > 1 && !arg_had_last && quitmore == 0) --- 3866,3874 ---- * return OK otherwise */ static int ! check_more(message, forceit) int message; /* when FALSE check only, no messages */ + int forceit; { if (!forceit && only_one_window() && arg_count > 1 && !arg_had_last && quitmore == 0) *************** *** 3758,3769 **** * 'lnum' is the line number for the cursor in the new file (if non-zero). */ int ! getfile(fnum, fname, sfname, setpm, lnum) int fnum; char_u *fname; char_u *sfname; int setpm; linenr_t lnum; { int other; --- 3892,3904 ---- * 'lnum' is the line number for the cursor in the new file (if non-zero). */ int ! getfile(fnum, fname, sfname, setpm, lnum, forceit) int fnum; char_u *fname; char_u *sfname; int setpm; linenr_t lnum; + int forceit; { int other; *************** *** 3778,3784 **** if (other) ++no_wait_return; /* don't wait for autowrite message */ if (other && !forceit && curbuf->b_nwindows == 1 && ! !p_hid && curbuf->b_changed && autowrite(curbuf) == FAIL) { if (other) --no_wait_return; --- 3913,3919 ---- if (other) ++no_wait_return; /* don't wait for autowrite message */ if (other && !forceit && curbuf->b_nwindows == 1 && ! !p_hid && curbuf->b_changed && autowrite(curbuf, forceit) == FAIL) { if (other) --no_wait_return; *************** *** 3798,3804 **** return 0; /* it's in the same file */ } ! if (do_ecmd(fnum, fname, sfname, NULL, p_hid, lnum, FALSE) == OK) return -1; /* opened another file */ return 1; /* error encountered */ } --- 3933,3940 ---- return 0; /* it's in the same file */ } ! if (do_ecmd(fnum, fname, sfname, NULL, lnum, ! (p_hid ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0)) == OK) return -1; /* opened another file */ return 1; /* error encountered */ } *************** *** 3958,3965 **** static char_u **cmd_files = NULL; /* list of input files */ static int findex; static char_u *orig_save = NULL; /* kept value of orig */ ! int i, found = 0; ! int multmatch = FALSE; long_u len; char_u *setsuf; int fnamelen, setsuflen; --- 4094,4101 ---- static char_u **cmd_files = NULL; /* list of input files */ static int findex; static char_u *orig_save = NULL; /* kept value of orig */ ! int i, j; ! int non_suf_match; /* number without matching suffix */ long_u len; char_u *setsuf; int fnamelen, setsuflen; *************** *** 4036,4056 **** else { /* ! * If the pattern starts with a '~', replace the home diretory ! * with '~' again. */ ! if (*str == '~' && (options & WILD_HOME_REPLACE)) ! { ! for (i = 0; i < cmd_numfiles; ++i) ! { ! p = home_replace_save(NULL, cmd_files[i]); ! if (p != NULL) ! { ! vim_free(cmd_files[i]); ! cmd_files[i] = p; ! } ! } ! } /* * Insert backslashes into a file name before a space, \, %, # and --- 4172,4181 ---- else { /* ! * May change home directory back to "~" */ ! if (options & WILD_HOME_REPLACE) ! tilde_replace(str, cmd_numfiles, cmd_files); /* * Insert backslashes into a file name before a space, \, %, # and *************** *** 4079,4087 **** if (mode != WILD_ALL && mode != WILD_LONGEST) { if (cmd_numfiles > 1) /* more than one match; check suffix */ { ! found = -2; for (i = 0; i < cmd_numfiles; ++i) { fnamelen = STRLEN(cmd_files[i]); --- 4204,4213 ---- if (mode != WILD_ALL && mode != WILD_LONGEST) { + non_suf_match = 1; if (cmd_numfiles > 1) /* more than one match; check suffix */ { ! non_suf_match = 0; for (i = 0; i < cmd_numfiles; ++i) { fnamelen = STRLEN(cmd_files[i]); *************** *** 4098,4112 **** } if (setsuflen) /* suffix matched: ignore file */ continue; ! if (found >= 0) ! { ! multmatch = TRUE; ! break; ! } ! found = i; } } ! if (multmatch || found < 0) { /* Can we ever get here unless it's while expanding * interactively? If not, we can get rid of this all --- 4224,4240 ---- } if (setsuflen) /* suffix matched: ignore file */ continue; ! /* ! * Move the name without matching suffix to the front ! * of the list. This makes CTRL-N work nice. ! */ ! p = cmd_files[i]; ! for (j = i; j > non_suf_match; --j) ! cmd_files[j] = cmd_files[j - 1]; ! cmd_files[non_suf_match++] = p; } } ! if (non_suf_match != 1) { /* Can we ever get here unless it's while expanding * interactively? If not, we can get rid of this all *************** *** 4117,4127 **** emsg(e_toomany); else beep_flush(); - found = 0; /* return first one */ - multmatch = TRUE; /* for found < 0 */ } ! if (found >= 0 && !(multmatch && mode == WILD_EXPAND_FREE)) ! ss = strsave(cmd_files[found]); } } } --- 4245,4253 ---- emsg(e_toomany); else beep_flush(); } ! if (!(non_suf_match != 1 && mode == WILD_EXPAND_FREE)) ! ss = strsave(cmd_files[0]); } } } *************** *** 4187,4192 **** --- 4313,4345 ---- } /* + * For each file name in files[num_files]: + * If 'orig_pat' starts with "~/", replace the home directory with "~". + */ + void + tilde_replace(orig_pat, num_files, files) + char_u *orig_pat; + int num_files; + char_u **files; + { + int i; + char_u *p; + + if (orig_pat[0] == '~' && ispathsep(orig_pat[1])) + { + for (i = 0; i < num_files; ++i) + { + p = home_replace_save(NULL, files[i]); + if (p != NULL) + { + vim_free(files[i]); + files[i] = p; + } + } + } + } + + /* * show all matches for completion on the command line */ static int *************** *** 4738,4744 **** int cmdidx; long argt; char_u delim; ! int forced = FALSE; int usefilter = FALSE; /* filter instead of file name */ expand_pattern = buff; --- 4891,4897 ---- int cmdidx; long argt; char_u delim; ! int forceit = FALSE; int usefilter = FALSE; /* filter instead of file name */ expand_pattern = buff; *************** *** 4866,4872 **** if (*p == '!') /* forced commands */ { ! forced = TRUE; ++p; } --- 5019,5025 ---- if (*p == '!') /* forced commands */ { ! forceit = TRUE; ++p; } *************** *** 4894,4900 **** if (cmdidx == CMD_read) { ! usefilter = forced; /* :r! filter if forced */ if (*arg == '!') /* :r !filter */ { ++arg; --- 5047,5053 ---- if (cmdidx == CMD_read) { ! usefilter = forceit; /* :r! filter if forced */ if (*arg == '!') /* :r !filter */ { ++arg; *************** *** 5116,5122 **** case CMD_vmenu: case CMD_vnoremenu: case CMD_vunmenu: case CMD_imenu: case CMD_inoremenu: case CMD_iunmenu: case CMD_cmenu: case CMD_cnoremenu: case CMD_cunmenu: ! return gui_set_context_in_menu_cmd(cmd, arg, forced); break; #endif default: --- 5269,5275 ---- case CMD_vmenu: case CMD_vnoremenu: case CMD_vunmenu: case CMD_imenu: case CMD_inoremenu: case CMD_iunmenu: case CMD_cmenu: case CMD_cnoremenu: case CMD_cunmenu: ! return gui_set_context_in_menu_cmd(cmd, arg, forceit); break; #endif default: *************** *** 5194,5200 **** expand_context == EXPAND_BOOL_SETTINGS) ret = ExpandSettings(prog, num_file, file); else if (expand_context == EXPAND_TAGS) ! ret = find_tags(NULL, prog, num_file, file, FALSE); #ifdef AUTOCMD else if (expand_context == EXPAND_EVENTS) ret = ExpandEvents(prog, num_file, file); --- 5347,5353 ---- expand_context == EXPAND_BOOL_SETTINGS) ret = ExpandSettings(prog, num_file, file); else if (expand_context == EXPAND_TAGS) ! ret = find_tags(NULL, prog, num_file, file, FALSE, FALSE); #ifdef AUTOCMD else if (expand_context == EXPAND_EVENTS) ret = ExpandEvents(prog, num_file, file);