4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: In diff mode, when using two tabs, each with two diffed buffers,
12 editing a buffer of the other tab messes up the diff. (Matt
14 Solution: Only copy options from a window where the buffer was edited that
15 doesn't have 'diff' set or is for the current tab page.
16 Also fix that window options for a buffer are stored with the
18 Files: src/buffer.c, src/ex_cmds.c, src/ex_cmds2.c, src/ex_docmd.c,
19 src/ex_getln.c, src/if_sniff.c, src/main.c, src/netbeans.c,
20 src/normal.c, src/popupmnu.c, src/proto/buffer.pro,
21 src/proto/ex_cmds.pro src/quickfix.c, src/window.c
24 *** ../vim-7.2.040/src/buffer.c Wed Nov 12 12:51:38 2008
25 --- src/buffer.c Wed Nov 12 17:45:01 2008
28 static char_u *fname_match __ARGS((regprog_T *prog, char_u *name));
30 static void buflist_setfpos __ARGS((buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options));
31 ! static wininfo_T *find_wininfo __ARGS((buf_T *buf));
33 static buf_T *buflist_findname_stat __ARGS((char_u *ffname, struct stat *st));
34 static int otherfile_buf __ARGS((buf_T *buf, char_u *ffname, struct stat *stp));
36 static char_u *fname_match __ARGS((regprog_T *prog, char_u *name));
38 static void buflist_setfpos __ARGS((buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options));
39 ! static wininfo_T *find_wininfo __ARGS((buf_T *buf, int skip_diff_buffer));
41 static buf_T *buflist_findname_stat __ARGS((char_u *ffname, struct stat *st));
42 static int otherfile_buf __ARGS((buf_T *buf, char_u *ffname, struct stat *stp));
47 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
48 ! forceit ? ECMD_FORCEIT : 0);
51 * do_ecmd() may create a new buffer, then we have to delete
55 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
56 ! forceit ? ECMD_FORCEIT : 0, curwin);
59 * do_ecmd() may create a new buffer, then we have to delete
64 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */
65 ! buflist_altfpos(); /* remember curpos */
68 /* Don't restart Select mode after switching to another buffer. */
72 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */
73 ! buflist_altfpos(curwin); /* remember curpos */
76 /* Don't restart Select mode after switching to another buffer. */
83 * Find info for the current window in buffer "buf".
84 * If not found, return the info for the most recently used window.
85 * Returns NULL when there isn't any info.
93 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
94 ! if (wip->wi_win == curwin)
96 ! if (wip == NULL) /* if no fpos for curwin, use the first in the list */
97 ! wip = buf->b_wininfo;
106 + static int wininfo_other_tab_diff __ARGS((wininfo_T *wip));
109 + * Return TRUE when "wip" has 'diff' set and the diff is only for another tab
110 + * page. That's because a diff is local to a tab page.
113 + wininfo_other_tab_diff(wip)
118 + if (wip->wi_opt.wo_diff)
120 + for (wp = firstwin; wp != NULL; wp = wp->w_next)
121 + /* return FALSE when it's a window in the current tab page, thus
122 + * the buffer was in diff mode here */
123 + if (wip->wi_win == wp)
132 * Find info for the current window in buffer "buf".
133 * If not found, return the info for the most recently used window.
134 + * When "skip_diff_buffer" is TRUE avoid windows with 'diff' set that is in
135 + * another tab page.
136 * Returns NULL when there isn't any info.
140 ! find_wininfo(buf, skip_diff_buffer)
142 + int skip_diff_buffer;
146 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
147 ! if (wip->wi_win == curwin
149 ! && (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
154 ! /* If no wininfo for curwin, use the first in the list (that doesn't have
155 ! * 'diff' set and is in another tab page). */
159 ! if (skip_diff_buffer)
161 ! for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
162 ! if (!wininfo_other_tab_diff(wip))
167 ! wip = buf->b_wininfo;
174 clearFolding(curwin);
177 ! wip = find_wininfo(buf);
178 if (wip != NULL && wip->wi_optset)
180 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
182 clearFolding(curwin);
185 ! wip = find_wininfo(buf, TRUE);
186 if (wip != NULL && wip->wi_optset)
188 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
192 static pos_T no_position = {1, 0};
194 ! wip = find_wininfo(buf);
196 return &(wip->wi_fpos);
200 static pos_T no_position = {1, 0};
202 ! wip = find_wininfo(buf, FALSE);
204 return &(wip->wi_fpos);
211 ! * Set alternate cursor position for current window.
212 * Also save the local window option values.
217 ! buflist_setfpos(curbuf, curwin, curwin->w_cursor.lnum,
218 ! curwin->w_cursor.col, TRUE);
226 ! * Set alternate cursor position for the current buffer and window "win".
227 * Also save the local window option values.
230 ! buflist_altfpos(win)
233 ! buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, TRUE);
240 ((P_HID(curwin->w_buffer)
241 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
248 ((P_HID(curwin->w_buffer)
249 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0)
250 ! + ECMD_OLDBUF, curwin);
254 *** ../vim-7.2.040/src/ex_cmds.c Sun Nov 9 13:43:25 2008
255 --- src/ex_cmds.c Wed Nov 12 22:41:41 2008
258 retval = 0; /* it's in the same file */
260 else if (do_ecmd(fnum, ffname, sfname, NULL, lnum,
261 ! (P_HID(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0)) == OK)
262 retval = -1; /* opened another file */
264 retval = 1; /* error encountered */
266 retval = 0; /* it's in the same file */
268 else if (do_ecmd(fnum, ffname, sfname, NULL, lnum,
269 ! (P_HID(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0),
271 retval = -1; /* opened another file */
273 retval = 1; /* error encountered */
276 * ECMD_OLDBUF: use existing buffer if it exists
277 * ECMD_FORCEIT: ! used for Ex command
278 * ECMD_ADDBUF: don't edit, just add to buffer list
280 * return FAIL for failure, OK otherwise
283 ! do_ecmd(fnum, ffname, sfname, eap, newlnum, flags)
287 exarg_T *eap; /* can be NULL! */
291 int other_file; /* TRUE if editing another file */
292 int oldbuf; /* TRUE if using existing buffer */
294 * ECMD_OLDBUF: use existing buffer if it exists
295 * ECMD_FORCEIT: ! used for Ex command
296 * ECMD_ADDBUF: don't edit, just add to buffer list
297 + * oldwin: Should be "curwin" when editing a new buffer in the current
298 + * window, NULL when splitting the window first. When not NULL info
299 + * of the previous buffer for "oldwin" is stored.
301 * return FAIL for failure, OK otherwise
304 ! do_ecmd(fnum, ffname, sfname, eap, newlnum, flags, oldwin)
308 exarg_T *eap; /* can be NULL! */
313 int other_file; /* TRUE if editing another file */
314 int oldbuf; /* TRUE if using existing buffer */
319 curwin->w_alt_fnum = curbuf->b_fnum;
327 curwin->w_alt_fnum = curbuf->b_fnum;
328 ! if (oldwin != NULL)
329 ! buflist_altfpos(oldwin);
336 /* close the link to the current buffer */
338 ! close_buffer(curwin, curbuf,
339 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD);
344 /* close the link to the current buffer */
346 ! close_buffer(oldwin, curbuf,
347 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD);
353 alt_fnum = curbuf->b_fnum;
354 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
355 ! ECMD_HIDE + ECMD_SET_HELP);
357 curwin->w_alt_fnum = alt_fnum;
358 empty_fnum = curbuf->b_fnum;
361 alt_fnum = curbuf->b_fnum;
362 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL,
363 ! ECMD_HIDE + ECMD_SET_HELP,
364 ! #ifdef FEAT_WINDOWS
365 ! NULL /* buffer is still open, don't store info */
371 curwin->w_alt_fnum = alt_fnum;
372 empty_fnum = curbuf->b_fnum;
373 *** ../vim-7.2.040/src/ex_cmds2.c Sun Sep 7 15:49:45 2008
374 --- src/ex_cmds2.c Wed Nov 12 17:46:41 2008
378 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
380 ! (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0) +
381 ! (eap->forceit ? ECMD_FORCEIT : 0)) == FAIL)
382 curwin->w_arg_idx = old_arg_idx;
383 /* like Vi: set the mark where the cursor is in the file. */
384 else if (eap->cmdidx != CMD_argdo)
387 if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
389 ! (P_HID(curwin->w_buffer) ? ECMD_HIDE : 0)
390 ! + (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
391 curwin->w_arg_idx = old_arg_idx;
392 /* like Vi: set the mark where the cursor is in the file. */
393 else if (eap->cmdidx != CMD_argdo)
394 *** ../vim-7.2.040/src/ex_docmd.c Sun Nov 9 13:43:25 2008
395 --- src/ex_docmd.c Wed Nov 12 18:04:22 2008
398 /* ":new" or ":tabnew" without argument: edit an new empty buffer */
400 (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE,
401 ! ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0));
403 else if ((eap->cmdidx != CMD_split
404 #ifdef FEAT_VERTSPLIT
406 /* ":new" or ":tabnew" without argument: edit an new empty buffer */
408 (void)do_ecmd(0, NULL, NULL, eap, ECMD_ONE,
409 ! ECMD_HIDE + (eap->forceit ? ECMD_FORCEIT : 0),
410 ! old_curwin == NULL ? curwin : NULL);
412 else if ((eap->cmdidx != CMD_split
413 #ifdef FEAT_VERTSPLIT
417 + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 )
421 /* Editing the file failed. If the window was split, close it. */
425 + (eap->cmdidx == CMD_badd ? ECMD_ADDBUF : 0 )
427 ! , old_curwin == NULL ? curwin : NULL) == FAIL)
429 /* Editing the file failed. If the window was split, close it. */
431 *** ../vim-7.2.040/src/ex_getln.c Sun Sep 14 14:41:44 2008
432 --- src/ex_getln.c Wed Nov 12 18:06:25 2008
437 /* Create the command-line buffer empty. */
438 ! (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE);
439 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE);
440 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
441 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
445 /* Create the command-line buffer empty. */
446 ! (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL);
447 (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE);
448 set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
449 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
450 *** ../vim-7.2.040/src/if_sniff.c Sat Aug 9 19:41:16 2008
451 --- src/if_sniff.c Wed Nov 12 17:48:46 2008
457 ! do_ecmd(0, (char_u *)fname, NULL, NULL, ECMD_ONE, ECMD_HIDE+ECMD_OLDBUF);
458 curbuf->b_sniff = TRUE;
459 --no_wait_return; /* [ex_docmd.c] */
465 ! do_ecmd(0, (char_u *)fname, NULL, NULL, ECMD_ONE, ECMD_HIDE+ECMD_OLDBUF,
467 curbuf->b_sniff = TRUE;
468 --no_wait_return; /* [ex_docmd.c] */
470 *** ../vim-7.2.040/src/main.c Sun Nov 9 13:43:25 2008
471 --- src/main.c Wed Nov 12 17:49:06 2008
475 (void)do_ecmd(0, arg_idx < GARGCOUNT
476 ? alist_name(&GARGLIST[arg_idx]) : NULL,
477 ! NULL, NULL, ECMD_LASTL, ECMD_HIDE);
478 # ifdef HAS_SWAP_EXISTS_ACTION
479 if (swap_exists_did_quit)
483 (void)do_ecmd(0, arg_idx < GARGCOUNT
484 ? alist_name(&GARGLIST[arg_idx]) : NULL,
485 ! NULL, NULL, ECMD_LASTL, ECMD_HIDE, curwin);
486 # ifdef HAS_SWAP_EXISTS_ACTION
487 if (swap_exists_did_quit)
489 *** ../vim-7.2.040/src/netbeans.c Sun Jul 13 19:18:03 2008
490 --- src/netbeans.c Wed Nov 12 17:49:40 2008
493 buf->displayname = NULL;
495 netbeansReadFile = 0; /* don't try to open disk file */
496 ! do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF);
497 netbeansReadFile = 1;
501 buf->displayname = NULL;
503 netbeansReadFile = 0; /* don't try to open disk file */
504 ! do_ecmd(0, NULL, 0, 0, ECMD_ONE, ECMD_HIDE + ECMD_OLDBUF, curwin);
505 netbeansReadFile = 1;
511 netbeansReadFile = 0; /* don't try to open disk file */
512 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
513 ! ECMD_HIDE + ECMD_OLDBUF);
514 netbeansReadFile = 1;
519 netbeansReadFile = 0; /* don't try to open disk file */
520 do_ecmd(0, (char_u *)buf->displayname, 0, 0, ECMD_ONE,
521 ! ECMD_HIDE + ECMD_OLDBUF, curwin);
522 netbeansReadFile = 1;
527 vim_free(buf->displayname);
528 buf->displayname = nb_unquote(args, NULL);
529 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
530 ! ECMD_HIDE + ECMD_OLDBUF);
532 buf->initDone = TRUE;
535 vim_free(buf->displayname);
536 buf->displayname = nb_unquote(args, NULL);
537 do_ecmd(0, (char_u *)buf->displayname, NULL, NULL, ECMD_ONE,
538 ! ECMD_HIDE + ECMD_OLDBUF, curwin);
540 buf->initDone = TRUE;
542 *** ../vim-7.2.040/src/normal.c Sat Nov 1 13:51:57 2008
543 --- src/normal.c Wed Nov 12 17:49:50 2008
546 autowrite(curbuf, FALSE);
548 (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
549 ! P_HID(curbuf) ? ECMD_HIDE : 0);
550 if (cap->nchar == 'F' && lnum >= 0)
552 curwin->w_cursor.lnum = lnum;
554 autowrite(curbuf, FALSE);
556 (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LAST,
557 ! P_HID(curbuf) ? ECMD_HIDE : 0, curwin);
558 if (cap->nchar == 'F' && lnum >= 0)
560 curwin->w_cursor.lnum = lnum;
561 *** ../vim-7.2.040/src/popupmnu.c Sun Jul 13 19:33:51 2008
562 --- src/popupmnu.c Wed Nov 12 18:08:07 2008
566 /* Don't want to sync undo in the current buffer. */
568 ! res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0);
574 /* Don't want to sync undo in the current buffer. */
576 ! res = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 0, NULL);
580 *** ../vim-7.2.040/src/proto/buffer.pro Sun May 6 13:57:53 2007
581 --- src/proto/buffer.pro Wed Nov 12 17:43:39 2008
584 char_u *getaltfname __ARGS((int errmsg));
585 int buflist_add __ARGS((char_u *fname, int flags));
586 void buflist_slash_adjust __ARGS((void));
587 ! void buflist_altfpos __ARGS((void));
588 int otherfile __ARGS((char_u *ffname));
589 void buf_setino __ARGS((buf_T *buf));
590 void fileinfo __ARGS((int fullname, int shorthelp, int dont_truncate));
592 char_u *getaltfname __ARGS((int errmsg));
593 int buflist_add __ARGS((char_u *fname, int flags));
594 void buflist_slash_adjust __ARGS((void));
595 ! void buflist_altfpos __ARGS((win_T *win));
596 int otherfile __ARGS((char_u *ffname));
597 void buf_setino __ARGS((buf_T *buf));
598 void fileinfo __ARGS((int fullname, int shorthelp, int dont_truncate));
599 *** ../vim-7.2.040/src/proto/ex_cmds.pro Sun Nov 9 13:43:25 2008
600 --- src/proto/ex_cmds.pro Wed Nov 12 17:44:27 2008
603 void do_wqall __ARGS((exarg_T *eap));
604 int not_writing __ARGS((void));
605 int getfile __ARGS((int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, int forceit));
606 ! int do_ecmd __ARGS((int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T newlnum, int flags));
607 void ex_append __ARGS((exarg_T *eap));
608 void ex_change __ARGS((exarg_T *eap));
609 void ex_z __ARGS((exarg_T *eap));
611 void do_wqall __ARGS((exarg_T *eap));
612 int not_writing __ARGS((void));
613 int getfile __ARGS((int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, int forceit));
614 ! int do_ecmd __ARGS((int fnum, char_u *ffname, char_u *sfname, exarg_T *eap, linenr_T newlnum, int flags, win_T *oldwin));
615 void ex_append __ARGS((exarg_T *eap));
616 void ex_change __ARGS((exarg_T *eap));
617 void ex_z __ARGS((exarg_T *eap));
618 *** ../vim-7.2.040/src/quickfix.c Thu Jul 24 18:44:59 2008
619 --- src/quickfix.c Wed Nov 12 18:12:00 2008
626 + win_T *oldwin = curwin;
627 int print_message = TRUE;
634 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
635 ! ECMD_HIDE + ECMD_SET_HELP);
638 ok = buflist_getfile(qf_ptr->qf_fnum,
642 ok = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
643 ! ECMD_HIDE + ECMD_SET_HELP,
644 ! oldwin == curwin ? curwin : NULL);
647 ok = buflist_getfile(qf_ptr->qf_fnum,
652 tabpage_T *prevtab = curtab;
654 + win_T *oldwin = curwin;
656 if (eap->cmdidx == CMD_lopen || eap->cmdidx == CMD_lwindow)
660 win->w_llist->qf_refcount++;
664 /* Use the existing quickfix buffer */
665 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
666 ! ECMD_HIDE + ECMD_OLDBUF);
669 /* Create a new quickfix buffer */
670 ! (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE);
671 /* switch off 'swapfile' */
672 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
673 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
675 win->w_llist->qf_refcount++;
678 + if (oldwin != curwin)
679 + oldwin = NULL; /* don't store info when in another window */
681 /* Use the existing quickfix buffer */
682 (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
683 ! ECMD_HIDE + ECMD_OLDBUF, oldwin);
686 /* Create a new quickfix buffer */
687 ! (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
688 /* switch off 'swapfile' */
689 set_option_value((char_u *)"swf", 0L, NULL, OPT_LOCAL);
690 set_option_value((char_u *)"bt", 0L, (char_u *)"quickfix",
691 *** ../vim-7.2.040/src/window.c Wed Aug 6 18:32:11 2008
692 --- src/window.c Wed Nov 12 18:12:37 2008
695 # ifdef FEAT_SCROLLBIND
696 curwin->w_p_scb = FALSE;
698 ! (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL, ECMD_HIDE);
699 if (nchar == 'F' && lnum >= 0)
701 curwin->w_cursor.lnum = lnum;
703 # ifdef FEAT_SCROLLBIND
704 curwin->w_p_scb = FALSE;
706 ! (void)do_ecmd(0, ptr, NULL, NULL, ECMD_LASTL,
708 if (nchar == 'F' && lnum >= 0)
710 curwin->w_cursor.lnum = lnum;
711 *** ../vim-7.2.040/src/version.c Wed Nov 12 16:04:43 2008
712 --- src/version.c Wed Nov 12 16:54:35 2008
716 { /* Add new patch number below this line */
722 hundred-and-one symptoms of being an internet addict:
723 260. Co-workers have to E-mail you about the fire alarm to get
724 you out of the building.
726 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
727 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
728 \\\ download, build and distribute -- http://www.A-A-P.org ///
729 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///