4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
10 Patch 7.0.060 (after 7.0.51)
11 Problem: Code for temporarily switching to another buffer is duplicated in
13 Solution: Use aucmd_prepbuf() and aucmd_restbuf() also when FEAT_AUTOCMD is
15 Files: src/buffer.c, src/eval.c, src/fileio.c, src/if_ruby.c,
16 src/if_perl.xs, src/quickfix.c, src/structs.h
19 *** ../vim-7.0.059/src/buffer.c Thu Apr 27 01:49:30 2006
20 --- src/buffer.c Wed Aug 16 14:36:17 2006
29 - buf_T *old_curbuf = curbuf;
33 /* Allocate a buffer without putting it in the buffer list. */
41 /* set curwin/curbuf to buf and save a few things */
42 aucmd_prepbuf(&aco, newbuf);
45 - curwin->w_buffer = newbuf;
48 if (ml_open(curbuf) == OK
49 && readfile(buf->b_ffname, buf->b_fname,
57 /* restore curwin/curbuf and a few other things */
60 - curbuf = old_curbuf;
61 - curwin->w_buffer = old_curbuf;
64 if (curbuf != newbuf) /* safety check */
65 wipe_buffer(newbuf, FALSE);
67 *** ../vim-7.0.059/src/eval.c Sun Jul 23 22:07:55 2006
68 --- src/eval.c Wed Aug 16 14:38:32 2006
79 char_u *varname, *bufvarname;
81 char_u nbuf[NUMBUFLEN];
85 if (buf != NULL && varname != NULL && varp != NULL)
87 /* set curbuf to be our buf, temporarily */
89 aucmd_prepbuf(&aco, buf);
91 - save_curbuf = curbuf;
102 /* reset notion of buffer */
103 - #ifdef FEAT_AUTOCMD
106 - curbuf = save_curbuf;
112 *** ../vim-7.0.059/src/fileio.c Sun Apr 30 20:33:48 2006
113 --- src/fileio.c Wed Aug 16 14:39:23 2006
116 int old_ro = buf->b_p_ro;
119 - #ifdef FEAT_AUTOCMD
122 /* set curwin/curbuf for "buf" and save some things */
123 aucmd_prepbuf(&aco, buf);
125 - buf_T *save_curbuf = curbuf;
128 - curwin->w_buffer = buf;
131 /* We only want to read the text from the file, not reset the syntax
132 * highlighting, clear marks, diff status, etc. Force the fileformat
136 curbuf->b_p_ro |= old_ro;
139 - #ifdef FEAT_AUTOCMD
140 /* restore curwin/curbuf and a few other things */
142 /* Careful: autocommands may have made "buf" invalid! */
144 - curwin->w_buffer = save_curbuf;
145 - curbuf = save_curbuf;
154 * Search a window for the current buffer. Save the cursor position and
156 * Set "curbuf" and "curwin" to match "buf".
157 + * When FEAT_AUTOCMD is not defined another version is used, see below.
160 aucmd_prepbuf(aco, buf)
165 * Cleanup after executing autocommands for a (hidden) buffer.
166 * Restore the window as it was (if possible).
167 + * When FEAT_AUTOCMD is not defined another version is used, see below.
177 + #else /* FEAT_AUTOCMD */
180 + * Prepare for executing commands for (hidden) buffer "buf".
181 + * This is the non-autocommand version, it simply saves "curbuf" and sets
182 + * "curbuf" and "curwin" to match "buf".
185 + aucmd_prepbuf(aco, buf)
186 + aco_save_T *aco; /* structure to save values in */
187 + buf_T *buf; /* new curbuf */
189 + aco->save_buf = buf;
191 + curwin->w_buffer = buf;
195 + * Restore after executing commands for a (hidden) buffer.
196 + * This is the non-autocommand version.
200 + aco_save_T *aco; /* structure holding saved values */
202 + curbuf = aco->save_buf;
203 + curwin->w_buffer = curbuf;
206 #endif /* FEAT_AUTOCMD */
209 #if defined(FEAT_AUTOCMD) || defined(FEAT_WILDIGN) || defined(PROTO)
211 *** ../vim-7.0.059/src/if_ruby.c Tue Jun 20 21:08:02 2006
212 --- src/if_ruby.c Wed Aug 16 14:41:11 2006
215 static VALUE set_buffer_line(buf_T *buf, linenr_T n, VALUE str)
217 char *line = STR2CSTR(str);
218 - #ifdef FEAT_AUTOCMD
221 - buf_T *save_curbuf = curbuf;
224 if (n > 0 && n <= buf->b_ml.ml_line_count && line != NULL)
226 - #ifdef FEAT_AUTOCMD
227 /* set curwin/curbuf for "buf" and save some things */
228 aucmd_prepbuf(&aco, buf);
231 - curwin->w_buffer = buf;
234 if (u_savesub(n) == OK) {
235 ml_replace(n, (char_u *)line, TRUE);
242 - #ifdef FEAT_AUTOCMD
243 /* restore curwin/curbuf and a few other things */
245 /* Careful: autocommands may have made "buf" invalid! */
247 ! curwin->w_buffer = save_curbuf;
248 ! curbuf = save_curbuf;
250 update_curbuf(NOT_VALID);
257 /* restore curwin/curbuf and a few other things */
259 /* Careful: autocommands may have made "buf" invalid! */
261 update_curbuf(NOT_VALID);
267 buf_T *buf = get_buf(self);
268 long n = NUM2LONG(num);
269 - #ifdef FEAT_AUTOCMD
272 - buf_T *save_curbuf = curbuf;
275 if (n > 0 && n <= buf->b_ml.ml_line_count)
277 - #ifdef FEAT_AUTOCMD
278 /* set curwin/curbuf for "buf" and save some things */
279 aucmd_prepbuf(&aco, buf);
282 - curwin->w_buffer = buf;
285 if (u_savedel(n, 1) == OK) {
293 - #ifdef FEAT_AUTOCMD
294 /* restore curwin/curbuf and a few other things */
296 /* Careful: autocommands may have made "buf" invalid! */
298 ! curwin->w_buffer = save_curbuf;
299 ! curbuf = save_curbuf;
301 update_curbuf(NOT_VALID);
308 /* restore curwin/curbuf and a few other things */
310 /* Careful: autocommands may have made "buf" invalid! */
312 update_curbuf(NOT_VALID);
317 buf_T *buf = get_buf(self);
318 char *line = STR2CSTR(str);
319 long n = NUM2LONG(num);
320 - #ifdef FEAT_AUTOCMD
323 - buf_T *save_curbuf = curbuf;
326 if (n >= 0 && n <= buf->b_ml.ml_line_count && line != NULL)
328 - #ifdef FEAT_AUTOCMD
329 /* set curwin/curbuf for "buf" and save some things */
330 aucmd_prepbuf(&aco, buf);
333 - curwin->w_buffer = buf;
336 if (u_inssub(n + 1) == OK) {
337 ml_append(n, (char_u *) line, (colnr_T) 0, FALSE);
344 - #ifdef FEAT_AUTOCMD
345 /* restore curwin/curbuf and a few other things */
347 /* Careful: autocommands may have made "buf" invalid! */
349 ! curwin->w_buffer = save_curbuf;
350 ! curbuf = save_curbuf;
352 update_curbuf(NOT_VALID);
359 /* restore curwin/curbuf and a few other things */
361 /* Careful: autocommands may have made "buf" invalid! */
363 update_curbuf(NOT_VALID);
366 *** ../vim-7.0.059/src/if_perl.xs Wed Aug 16 18:19:41 2006
367 --- src/if_perl.xs Wed Aug 16 14:45:15 2006
370 line = SvPV(ST(i),PL_na);
371 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL)
373 - #ifdef FEAT_AUTOCMD
376 /* set curwin/curbuf for "vimbuf" and save some things */
377 aucmd_prepbuf(&aco, vimbuf);
379 - buf_T *save_curbuf = curbuf;
382 - curwin->w_buffer = vimbuf;
384 if (u_savesub(lnum) == OK)
386 ml_replace(lnum, (char_u *)line, TRUE);
387 changed_bytes(lnum, 0);
389 ! #ifdef FEAT_AUTOCMD
390 /* restore curwin/curbuf and a few other things */
392 /* Careful: autocommands may have made "vimbuf" invalid! */
394 - curwin->w_buffer = save_curbuf;
395 - curbuf = save_curbuf;
401 line = SvPV(ST(i),PL_na);
402 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL)
406 /* set curwin/curbuf for "vimbuf" and save some things */
407 aucmd_prepbuf(&aco, vimbuf);
409 if (u_savesub(lnum) == OK)
411 ml_replace(lnum, (char_u *)line, TRUE);
412 changed_bytes(lnum, 0);
415 /* restore curwin/curbuf and a few other things */
417 /* Careful: autocommands may have made "vimbuf" invalid! */
424 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count)
426 - buf_T *save_curbuf = curbuf;
427 - #ifdef FEAT_AUTOCMD
430 /* set curwin/curbuf for "vimbuf" and save some things */
431 aucmd_prepbuf(&aco, vimbuf);
434 ! curwin->w_buffer = vimbuf;
436 if (u_savedel(lnum, 1) == OK)
439 deleted_lines_mark(lnum, 1L);
440 ! if (save_curbuf == curbuf)
443 ! #ifdef FEAT_AUTOCMD
444 /* restore curwin/curbuf and a few other things */
446 /* Careful: autocommands may have made "vimbuf" invalid! */
448 ! curwin->w_buffer = save_curbuf;
449 ! curbuf = save_curbuf;
451 update_curbuf(VALID);
456 if (lnum > 0 && lnum <= vimbuf->b_ml.ml_line_count)
460 /* set curwin/curbuf for "vimbuf" and save some things */
461 aucmd_prepbuf(&aco, vimbuf);
463 if (u_savedel(lnum, 1) == OK)
466 deleted_lines_mark(lnum, 1L);
467 ! if (aco.save_buf == curbuf)
471 /* restore curwin/curbuf and a few other things */
473 /* Careful: autocommands may have made "vimbuf" invalid! */
475 update_curbuf(VALID);
480 line = SvPV(ST(i),PL_na);
481 if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL)
483 - #ifdef FEAT_AUTOCMD
486 /* set curwin/curbuf for "vimbuf" and save some things */
487 aucmd_prepbuf(&aco, vimbuf);
489 - buf_T *save_curbuf = curbuf;
492 - curwin->w_buffer = vimbuf;
494 if (u_inssub(lnum + 1) == OK)
496 ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE);
497 appended_lines_mark(lnum, 1L);
499 ! #ifdef FEAT_AUTOCMD
500 /* restore curwin/curbuf and a few other things */
502 /* Careful: autocommands may have made "vimbuf" invalid! */
504 ! curwin->w_buffer = save_curbuf;
505 ! curbuf = save_curbuf;
507 update_curbuf(VALID);
511 line = SvPV(ST(i),PL_na);
512 if (lnum >= 0 && lnum <= vimbuf->b_ml.ml_line_count && line != NULL)
516 /* set curwin/curbuf for "vimbuf" and save some things */
517 aucmd_prepbuf(&aco, vimbuf);
519 if (u_inssub(lnum + 1) == OK)
521 ml_append(lnum, (char_u *)line, (colnr_T)0, FALSE);
522 appended_lines_mark(lnum, 1L);
525 /* restore curwin/curbuf and a few other things */
527 /* Careful: autocommands may have made "vimbuf" invalid! */
529 update_curbuf(VALID);
532 *** ../vim-7.0.059/src/quickfix.c Tue Jun 20 20:49:42 2006
533 --- src/quickfix.c Wed Aug 16 14:43:06 2006
539 - #ifdef FEAT_AUTOCMD
542 - buf_T *save_curbuf;
545 /* Check if a buffer for the quickfix list exists. Update it. */
546 buf = qf_find_buf(qi);
549 - #ifdef FEAT_AUTOCMD
550 /* set curwin/curbuf to buf and save a few things */
551 aucmd_prepbuf(&aco, buf);
553 - save_curbuf = curbuf;
559 - #ifdef FEAT_AUTOCMD
560 /* restore curwin/curbuf and a few other things */
563 - curbuf = save_curbuf;
566 (void)qf_win_pos_update(qi, 0);
571 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
572 char_u *save_ei = NULL;
574 - #ifndef FEAT_AUTOCMD
575 - buf_T *save_curbuf;
578 char_u *au_name = NULL;
582 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
583 char_u *save_ei = NULL;
586 + #ifdef FEAT_AUTOCMD
587 char_u *au_name = NULL;
592 * need to be done now, in that buffer. And the modelines
593 * need to be done (again). But not the window-local
595 - #if defined(FEAT_AUTOCMD)
596 aucmd_prepbuf(&aco, buf);
598 - save_curbuf = curbuf;
600 - curwin->w_buffer = curbuf;
602 #if defined(FEAT_AUTOCMD) && defined(FEAT_SYN_HL)
603 apply_autocmds(EVENT_FILETYPE, buf->b_p_ft,
604 buf->b_fname, TRUE, buf);
606 do_modelines(OPT_NOWIN);
607 - #if defined(FEAT_AUTOCMD)
610 - curbuf = save_curbuf;
611 - curwin->w_buffer = curbuf;
622 - #ifdef FEAT_AUTOCMD
625 - buf_T *old_curbuf = curbuf;
628 /* Allocate a buffer without putting it in the buffer list. */
629 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
633 /* Init the options. */
634 buf_copy_options(newbuf, BCO_ENTER | BCO_NOHELP);
636 - #ifdef FEAT_AUTOCMD
637 /* set curwin/curbuf to buf and save a few things */
638 aucmd_prepbuf(&aco, newbuf);
641 - curwin->w_buffer = newbuf;
644 /* Need to set the filename for autocommands. */
645 (void)setfname(curbuf, fname, NULL, FALSE);
652 - #ifdef FEAT_AUTOCMD
653 /* restore curwin/curbuf and a few other things */
656 - curbuf = old_curbuf;
657 - curwin->w_buffer = old_curbuf;
660 if (!buf_valid(newbuf))
663 *** ../vim-7.0.059/src/structs.h Sun Apr 9 23:52:16 2006
664 --- src/structs.h Wed Aug 16 19:30:48 2006
669 * Struct to save values in before executing autocommands for a buffer that is
670 ! * not the current buffer.
674 buf_T *save_buf; /* saved curbuf */
675 buf_T *new_curbuf; /* buffer to be used */
676 win_T *save_curwin; /* saved curwin, NULL if it didn't change */
677 win_T *new_curwin; /* new curwin if save_curwin != NULL */
678 pos_T save_cursor; /* saved cursor pos of save_curwin */
679 linenr_T save_topline; /* saved topline of save_curwin */
681 int save_topfill; /* saved topfill of save_curwin */
688 * Struct to save values in before executing autocommands for a buffer that is
689 ! * not the current buffer. Without FEAT_AUTOCMD only "curbuf" is remembered.
693 buf_T *save_buf; /* saved curbuf */
694 + #ifdef FEAT_AUTOCMD
695 buf_T *new_curbuf; /* buffer to be used */
696 win_T *save_curwin; /* saved curwin, NULL if it didn't change */
697 win_T *new_curwin; /* new curwin if save_curwin != NULL */
698 pos_T save_cursor; /* saved cursor pos of save_curwin */
699 linenr_T save_topline; /* saved topline of save_curwin */
701 int save_topfill; /* saved topfill of save_curwin */
706 *** ../vim-7.0.059/src/version.c Wed Aug 16 18:19:41 2006
707 --- src/version.c Wed Aug 16 19:31:01 2006
711 { /* Add new patch number below this line */
717 hundred-and-one symptoms of being an internet addict:
718 164. You got out to buy software, instead of going out for a beer.
720 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
721 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
722 \\\ download, build and distribute -- http://www.A-A-P.org ///
723 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///