Seems I broke something between testing and sending out the diff. Updating diff coming later.
On Fri, Oct 12, 2012 at 12:40:47PM +0200, Christiano F. Haesbaert wrote: > I want this baaaaaadlyyy, ill have a look. > On Oct 12, 2012 12:30 PM, "Jasper Lievisse Adriaanse" <jas...@openbsd.org> > wrote: > > > Hi, > > > > Here's a diff that implement revert-buffer (C-x r). I've split gotoline > > into > > the 'goto-line' specifics and the code that actually jumps to the line so > > it > > can be re-used by revert-buffer to restore the current line. > > > > OK? > > > > -- > > Cheers, > > Jasper > > > > "Stay Hungry. Stay Foolish" > > > > Index: basic.c > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/basic.c,v > > retrieving revision 1.37 > > diff -p -u -r1.37 basic.c > > --- basic.c 18 Jun 2012 09:26:03 -0000 1.37 > > +++ basic.c 12 Oct 2012 10:25:14 -0000 > > @@ -485,7 +485,6 @@ swapmark(int f, int n) > > int > > gotoline(int f, int n) > > { > > - struct line *clp; > > char buf[32], *bufp; > > const char *err; > > > > @@ -501,6 +500,16 @@ gotoline(int f, int n) > > return (FALSE); > > } > > } > > + return(setlineno(n)); > > +} > > + > > +/* > > + * Set the line number and switch to it. > > + */ > > +int > > +setlineno(int n){ > > + struct line *clp; > > + > > if (n >= 0) { > > if (n == 0) > > n++; > > Index: buffer.c > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/buffer.c,v > > retrieving revision 1.81 > > diff -p -u -r1.81 buffer.c > > --- buffer.c 31 Aug 2012 18:06:42 -0000 1.81 > > +++ buffer.c 12 Oct 2012 10:25:14 -0000 > > @@ -861,4 +861,35 @@ checkdirty(struct buffer *bp) > > > > return (TRUE); > > } > > - > > + > > +/* > > + * Revert the current buffer to whatever is on disk. > > + */ > > +/* ARGSUSED */ > > +int > > +revertbuffer(int f, int n){ > > + struct mgwin *wp = wheadp; > > + struct buffer *bp = wp->w_bufp; > > + char fbuf[NFILEN + 32]; > > + int lineno; > > + > > + if (!strlen(bp->b_fname)) { > > + ewprintf("Cannot revert buffer not associated with any > > files."); > > + return (FALSE); > > + } > > + > > + snprintf(fbuf, sizeof(fbuf), "Revert buffer from file %s", > > bp->b_fname); > > + > > + if (eyorn(fbuf)) { > > + /* Save our current line, so we can go back it after > > reloading the file. */ > > + lineno = wp->w_dotline; > > + if (readin(bp->b_list.l_name)) { > > + return(setlineno(lineno)); > > + } else { > > + ewprintf("File %s no longer readable!", > > bp->b_fname); > > + return (FALSE); > > + } > > + } > > + > > + return (FALSE); > > +} > > Index: def.h > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/def.h,v > > retrieving revision 1.125 > > diff -p -u -r1.125 def.h > > --- def.h 31 Aug 2012 18:06:42 -0000 1.125 > > +++ def.h 12 Oct 2012 10:25:14 -0000 > > @@ -414,6 +414,7 @@ int notmodified(int, int); > > int popbuftop(struct buffer *, int); > > int getbufcwd(char *, size_t); > > int checkdirty(struct buffer *); > > +int revertbuffer(int, int); > > > > /* display.c */ > > int vtresize(int, int, int); > > @@ -494,6 +495,7 @@ int setmark(int, int); > > int clearmark(int, int); > > int swapmark(int, int); > > int gotoline(int, int); > > +int setlineno(int); > > > > /* random.c X */ > > int showcpos(int, int); > > Index: funmap.c > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/funmap.c,v > > retrieving revision 1.40 > > diff -p -u -r1.40 funmap.c > > --- funmap.c 14 Jun 2012 17:21:22 -0000 1.40 > > +++ funmap.c 12 Oct 2012 10:25:15 -0000 > > @@ -196,7 +196,8 @@ static struct funmap functnames[] = { > > {csprevmatch, "cscope-prev-symbol",}, > > {csnextfile, "cscope-next-file",}, > > {csprevfile, "cscope-prev-file",}, > > - {cscreatelist, "cscope-create-list-of-files-to-index"}, > > + {cscreatelist, "cscope-create-list-of-files-to-index",}, > > + {revertbuffer, "revert-buffer",}, > > {NULL, NULL,} > > }; > > > > Index: keymap.c > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/keymap.c,v > > retrieving revision 1.50 > > diff -p -u -r1.50 keymap.c > > --- keymap.c 7 Jun 2012 15:15:04 -0000 1.50 > > +++ keymap.c 12 Oct 2012 10:25:15 -0000 > > @@ -177,7 +177,7 @@ static PF cXcar[] = { > > nextwind, /* o */ > > prevwind, /* p */ > > rescan, /* q */ > > - rescan, /* r */ > > + revertbuffer, /* r */ > > savebuffers, /* s */ > > rescan, /* t */ > > undo /* u */ > > Index: mg.1 > > =================================================================== > > RCS file: /cvs/src/usr.bin/mg/mg.1,v > > retrieving revision 1.68 > > diff -p -u -r1.68 mg.1 > > --- mg.1 11 Jul 2012 19:56:13 -0000 1.68 > > +++ mg.1 12 Oct 2012 10:25:15 -0000 > > @@ -249,6 +249,8 @@ other-window > > other-window > > .It C-x p > > previous-window > > +.It C-x r > > +revert-buffer > > .It C-x s > > save-some-buffers > > .It C-x u > > @@ -752,6 +754,8 @@ is negative, it is that line from the bo > > .It redraw-display > > Refresh the display. > > Recomputes all window sizes in case something has changed. > > +.It revert-buffer > > +Revert the current buffer to the latest file on disk. > > .It save-buffer > > Save the contents of the current buffer if it has been changed, > > optionally creating a backup copy. > > > > -- Cheers, Jasper "Stay Hungry. Stay Foolish"