diff options
author | 2012-10-12 21:13:46 +0000 | |
---|---|---|
committer | 2012-10-12 21:13:46 +0000 | |
commit | 12c1586153fede2fc4569974aee642fbc50e0050 (patch) | |
tree | 02ccdc4d1d675a4eaa0a8bab0d6e7c3e034ff169 | |
parent | Add $OpenBSD$ CVS Ids. (diff) | |
download | wireguard-openbsd-12c1586153fede2fc4569974aee642fbc50e0050.tar.xz wireguard-openbsd-12c1586153fede2fc4569974aee642fbc50e0050.zip |
- implement "revert-buffer", which reverts the current buffer to what's on disk
- split gotoline() into the argument handling part and the part that actually
goes to the specified line number so it can be re-used by revertbuffer()
input/ok florian@ haesbaert@
-rw-r--r-- | usr.bin/mg/basic.c | 14 | ||||
-rw-r--r-- | usr.bin/mg/buffer.c | 46 | ||||
-rw-r--r-- | usr.bin/mg/def.h | 4 | ||||
-rw-r--r-- | usr.bin/mg/funmap.c | 5 | ||||
-rw-r--r-- | usr.bin/mg/mg.1 | 6 |
5 files changed, 66 insertions, 9 deletions
diff --git a/usr.bin/mg/basic.c b/usr.bin/mg/basic.c index 160d9c1c9e3..9b6af92ec6d 100644 --- a/usr.bin/mg/basic.c +++ b/usr.bin/mg/basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: basic.c,v 1.37 2012/06/18 09:26:03 lum Exp $ */ +/* $OpenBSD: basic.c,v 1.38 2012/10/12 21:13:46 jasper Exp $ */ /* This file is in the public domain */ @@ -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,17 @@ 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++; diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index 5a30aadbf0a..0cc85f20efe 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.81 2012/08/31 18:06:42 lum Exp $ */ +/* $OpenBSD: buffer.c,v 1.82 2012/10/12 21:13:46 jasper Exp $ */ /* This file is in the public domain. */ @@ -861,4 +861,46 @@ 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 (bp->b_fname[0] == 0) { + 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)) { + if (access(bp->b_fname, F_OK|R_OK) != 0) { + if (errno == ENOENT) + ewprintf("File %s no longer exists!", + bp->b_fname); + else + ewprintf("File %s is no longer readable!", + bp->b_fname); + return (FALSE); + } + + /* Save our current line, so we can go back after reloading. */ + lineno = wp->w_dotline; + + /* Prevent readin from asking if we want to kill the buffer. */ + curbp->b_flag &= ~BFCHG; + + if (readin(bp->b_fname)) + return(setlineno(lineno)); + } + + return (FALSE); +} diff --git a/usr.bin/mg/def.h b/usr.bin/mg/def.h index e00a0dd0b68..c24c8505a73 100644 --- a/usr.bin/mg/def.h +++ b/usr.bin/mg/def.h @@ -1,4 +1,4 @@ -/* $OpenBSD: def.h,v 1.125 2012/08/31 18:06:42 lum Exp $ */ +/* $OpenBSD: def.h,v 1.126 2012/10/12 21:13:46 jasper Exp $ */ /* This file is in the public domain. */ @@ -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); diff --git a/usr.bin/mg/funmap.c b/usr.bin/mg/funmap.c index aac58ce53e3..66dd4147f69 100644 --- a/usr.bin/mg/funmap.c +++ b/usr.bin/mg/funmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: funmap.c,v 1.40 2012/06/14 17:21:22 lum Exp $ */ +/* $OpenBSD: funmap.c,v 1.41 2012/10/12 21:13:46 jasper Exp $ */ /* This file is in the public domain */ @@ -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,} }; diff --git a/usr.bin/mg/mg.1 b/usr.bin/mg/mg.1 index bc120809014..baab1863ce1 100644 --- a/usr.bin/mg/mg.1 +++ b/usr.bin/mg/mg.1 @@ -1,7 +1,7 @@ -.\" $OpenBSD: mg.1,v 1.68 2012/07/11 19:56:13 sobrado Exp $ +.\" $OpenBSD: mg.1,v 1.69 2012/10/12 21:13:47 jasper Exp $ .\" This file is in the public domain. .\" -.Dd $Mdocdate: July 11 2012 $ +.Dd $Mdocdate: October 12 2012 $ .Dt MG 1 .Os .Sh NAME @@ -752,6 +752,8 @@ is negative, it is that line from the bottom. .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. |