On 10/12/2012 02:49 PM, Jasper Lievisse Adriaanse wrote:
Here's an updated diff that doesn't mix buffername with filenames.
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 12:49:21 -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 12:49:21 -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_fname)) {
mg asks two times for confirmation when reverting a changed buffer. I
find that annoying and emacs doesn't do this. We could pretend the
buffer is unchanged by
curbp->b_flag &= ~BFCHG;
before readin (and keep a copy of the BFCHG flag for the error path, but
see below).
+ return(setlineno(lineno));
+ } else {
+ ewprintf("File %s no longer readable!", bp->b_fname);
+ return (FALSE);
The error path is weird.
1) When moving the underlying file out of the way and reverting the
buffer you get an empty buffer and mg says (New file). When you change
the buffer and try to save it you get
Backup error, save anyway? (yes or no)
2) When the underlying file is chmod 000 mg says "File no longer
readable" but the buffer is cleared. The window is not repainted. After
entering a character you see that the buffer is empty.
In both cases emacs shows an error message and leaves the buffer untouched.
+ }
+ }
+
+ 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 12:49:21 -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 12:49:22 -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 12:49:22 -0000
@@ -177,7 +177,7 @@ static PF cXcar[] = {
nextwind, /* o */
prevwind, /* p */
rescan, /* q */
- rescan, /* r */
+ revertbuffer, /* r */
fwiw, C-x r is a prefix in emacs for rectangular editing commands.
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 12:49:23 -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.
--
I remember yesterday, but the memory is in my head now.
Was yesterday real? Or is it only the memory that is real?