vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| A couple of years back, the undo behavior in mg was changed from BUFFER-based to MGWIN-based. I have no idea why this was the case, as this utterly breaks undo across multiple files. (for an example, open a file in mg, edit it. close without saving. Now open a second file and do an undo. Your previous buffer's undo information will be applied to the current buffer, with random and incorrect results) This change effectively reverts this decision, making undo history buffer-based again. This, in conjunction with the other (just-committed) mg undo diff should make undo usable and emacs-like in most circumstances. Please try, and let me know if this behaves unexpectedly, or incorrectly in any circumstance you know of. Index: buffer.c ================================================== ================= RCS file: /cvs/src/usr.bin/mg/buffer.c,v retrieving revision 1.45 diff -u -r1.45 buffer.c --- buffer.c 28 Sep 2005 06:37:52 -0000 1.45 +++ buffer.c 6 Oct 2005 20:18:26 -0000 @@ -126,6 +126,7 @@ BUFFER *bp2; MGWIN *wp; int s; + struct undo_rec *rec, *next; /* * Find some other buffer to display. Try the alternate buffer, @@ -176,6 +177,13 @@ bp1->b_altb = (bp->b_altb == bp1) ? NULL : bp->b_altb; bp1 = bp1->b_bufp; } + rec = LIST_FIRST(&bp->b_undo); + while (rec != NULL) { + next = LIST_NEXT(rec, next); + free_undo_record(rec); + rec = next; + } + free((char *)bp->b_bname); /* Release name block */ free(bp); /* Release buffer block */ return (TRUE); @@ -488,6 +496,9 @@ bp->b_nwnd = 0; bp->b_linep = lp; bp->b_nmodes = defb_nmodes; + LIST_INIT(&bp->b_undo); + bp->b_undoptr = NULL; + memset(&bp->b_undopos, 0, sizeof(bp->b_undopos)); i = 0; do { bp->b_modes[i] = defb_modes[i]; Index: def.h ================================================== ================= RCS file: /cvs/src/usr.bin/mg/def.h,v retrieving revision 1.65 diff -u -r1.65 def.h --- def.h 6 Oct 2005 16:48:00 -0000 1.65 +++ def.h 6 Oct 2005 20:18:27 -0000 @@ -203,10 +203,6 @@ char w_ntrows; /* # of rows of text in window */ char w_force; /* If NZ, forcing row. */ char w_flag; /* Flags. */ - LIST_HEAD(, undo_rec) w_undo; /* Undo actions list */ - int w_undopos; /* Where we were during the */ - /* last undo action. */ - struct undo_rec *w_undoptr; struct LINE *w_wrapline; } MGWIN; #define w_wndp w_list.l_p.l_wp @@ -253,6 +249,10 @@ char b_flag; /* Flags */ char b_fname[NFILEN]; /* File name */ struct fileinfo b_fi; /* File attributes */ + LIST_HEAD(, undo_rec) b_undo; /* Undo actions list */ + int b_undopos; /* Where we were during the */ + /* last undo action. */ + struct undo_rec *b_undoptr; } BUFFER; #define b_bufp b_list.l_p.x_bp #define b_bname b_list.l_name Index: undo.c ================================================== ================= RCS file: /cvs/src/usr.bin/mg/undo.c,v retrieving revision 1.28 diff -u -r1.28 undo.c --- undo.c 6 Oct 2005 16:48:00 -0000 1.28 +++ undo.c 6 Oct 2005 20:18:27 -0000 @@ -155,7 +155,7 @@ { struct undo_rec *rec; - rec = LIST_END(&curwp->w_undo); + rec = LIST_END(&curbp->b_undo); if (rec != NULL) { undo_free_num--; LIST_REMOVE(rec, next); @@ -170,7 +170,7 @@ { struct undo_rec *rec; - if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL) + if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) return (rec->type); return (0); } @@ -205,7 +205,7 @@ rec = new_undo_record(); rec->type = BOUNDARY; - LIST_INSERT_HEAD(&curwp->w_undo, rec, next); + LIST_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -228,7 +228,7 @@ /* * We try to reuse the last undo record to `compress' things. */ - rec = LIST_FIRST(&curwp->w_undo); + rec = LIST_FIRST(&curbp->b_undo); if (rec != NULL && rec->type == INSERT) { if (rec->pos + rec->region.r_size == pos) { rec->region.r_size += reg.r_size; @@ -247,7 +247,7 @@ undo_add_boundary(); - LIST_INSERT_HEAD(&curwp->w_undo, rec, next); + LIST_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -273,7 +273,7 @@ if (offset == llength(lp)) /* if it's a newline... */ undo_add_boundary(); - else if ((rec = LIST_FIRST(&curwp->w_undo)) != NULL) { + else if ((rec = LIST_FIRST(&curbp->b_undo)) != NULL) { /* * Separate this command from the previous one if we're not * just before the previous record... @@ -300,7 +300,7 @@ if (lastrectype() != DELETE) undo_add_boundary(); - LIST_INSERT_HEAD(&curwp->w_undo, rec, next); + LIST_INSERT_HEAD(&curbp->b_undo, rec, next); return (TRUE); } @@ -352,7 +352,7 @@ } num = 0; - for (rec = LIST_FIRST(&curwp->w_undo); rec != NULL; + for (rec = LIST_FIRST(&curbp->b_undo); rec != NULL; rec = LIST_NEXT(rec, next)) { num++; snprintf(buf, sizeof(buf), @@ -422,11 +422,11 @@ dot = find_dot(curwp->w_dotp, curwp->w_doto); - ptr = curwp->w_undoptr; + ptr = curbp->b_undoptr; /* if we moved, make ptr point back to the top of the list */ - if ((ptr == NULL && nulled == TRUE) || curwp->w_undopos != dot) { - ptr = LIST_FIRST(&curwp->w_undo); + if ((ptr == NULL && nulled == TRUE) || curbp->b_undopos != dot) { + ptr = LIST_FIRST(&curbp->b_undo); nulled = TRUE; } @@ -513,9 +513,9 @@ * Record where we are. (we have to save our new position at the end * since we change the dot when undoing....) */ - curwp->w_undoptr = ptr; + curbp->b_undoptr = ptr; - curwp->w_undopos = find_dot(curwp->w_dotp, curwp->w_doto); + curbp->b_undopos = find_dot(curwp->w_dotp, curwp->w_doto); return (rval); } Index: window.c ================================================== ================= RCS file: /cvs/src/usr.bin/mg/window.c,v retrieving revision 1.17 diff -u -r1.17 window.c --- window.c 14 Jun 2005 18:14:40 -0000 1.17 +++ window.c 6 Oct 2005 20:18:27 -0000 @@ -27,27 +27,9 @@ wp->w_wrapline = NULL; if (bp) bp->b_nwnd++; - LIST_INIT(&wp->w_undo); - wp->w_undoptr = NULL; - wp->w_undopos = 0; - return (wp); } -void -free_window(MGWIN *wp) -{ - struct undo_rec *rec, *next; - - rec = LIST_FIRST(&wp->w_undo); - while (rec != NULL) { - next = LIST_NEXT(rec, next); - free_undo_record(rec); - rec = next; - } - free(wp); -} - /* * Reposition dot in the current window to line "n". If the argument is * positive, it is that line. If it is negative it is that line from the @@ -177,7 +159,7 @@ wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; } - free_window(wp); + free(wp); } while (curwp->w_wndp != NULL) { wp = curwp->w_wndp; @@ -188,7 +170,7 @@ wp->w_bufp->b_markp = wp->w_markp; wp->w_bufp->b_marko = wp->w_marko; } - free_window(wp); + free(wp); } lp = curwp->w_linep; i = curwp->w_toprow; @@ -425,7 +407,7 @@ nwp->w_wndp = wp->w_wndp; break; } - free_window(wp); + free(wp); return (TRUE); } |
| Thread Tools | |
| Display Modes | |
|
|