diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-06-03 08:23:13 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2005-06-03 08:23:13 +0000 |
commit | 87136695717c490b68715ca08ec7ce0a34178515 (patch) | |
tree | de754cea35bb9dc379187c9924f6b71058b602e0 /usr.bin | |
parent | b6bf07802830f1d01d7e66586c6ef32bafea8f8e (diff) |
Clean up find-alternate-file (C-x C-v) so abort returns to original
file, like its emacs ancestor.
ok cloder@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/mg/buffer.c | 7 | ||||
-rw-r--r-- | usr.bin/mg/file.c | 46 |
2 files changed, 47 insertions, 6 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c index bb310e43da0..b5e4351b924 100644 --- a/usr.bin/mg/buffer.c +++ b/usr.bin/mg/buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: buffer.c,v 1.40 2005/05/31 20:38:59 kjell Exp $ */ +/* $OpenBSD: buffer.c,v 1.41 2005/06/03 08:23:12 kjell Exp $ */ /* * Buffer handling. @@ -123,6 +123,7 @@ killbuffer(BUFFER *bp) BUFFER *bp1; BUFFER *bp2; MGWIN *wp; + int s; /* * Find some other buffer to display. Try the alternate buffer, @@ -141,8 +142,8 @@ killbuffer(BUFFER *bp) return (FALSE); } } - if (bclear(bp) != TRUE) - return (TRUE); + if ((s = bclear(bp)) != TRUE) + return (s); for (wp = wheadp; bp->b_nwnd > 0; wp = wp->w_wndp) { if (wp->w_bufp == bp) { bp2 = bp1->b_altb; /* save alternate buffer */ diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index e00a05807e1..bac8b53cb30 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.35 2005/05/30 13:13:50 jason Exp $ */ +/* $OpenBSD: file.c,v 1.36 2005/06/03 08:23:12 kjell Exp $ */ /* * File commands. @@ -73,12 +73,52 @@ filevisit(int f, int n) return (TRUE); } +/* + * Replace the current file with an alternate one. Semantics for finding + * the replacement file are the same as 'filevisit', except the current + * buffer is killed before the switch. If the kill fails, or is aborted, + * revert to the original file. + */ int filevisitalt(int f, int n) { - if (killbuffer(curbp) == ABORT) + BUFFER *bp; + char fname[NFILEN], *bufp, *adjf, *slash; + int status; + + if (curbp->b_fname && curbp->b_fname[0] != '\0') { + strlcpy(fname, curbp->b_fname, sizeof(fname)); + if ((slash = strrchr(fname, '/')) != NULL) { + *(slash + 1) = '\0'; + } + } else + fname[0] = '\0'; + + bufp = eread("Find alternate file: ", fname, NFILEN, + EFNEW | EFCR | EFFILE | EFDEF); + if (bufp == NULL) return (ABORT); - return (filevisit(f, n)); + else if (bufp[0] == '\0') + return (FALSE); + + status = killbuffer(curbp); + if (status == ABORT || status == FALSE) + return (ABORT); + + adjf = adjustname(fname); + if (adjf == NULL) + return (FALSE); + if ((bp = findbuffer(adjf)) == NULL) + return (FALSE); + curbp = bp; + if (showbuffer(bp, curwp, WFHARD) != TRUE) + return (FALSE); + if (bp->b_fname[0] == '\0') { + if ((status = readin(adjf)) != TRUE) + killbuffer(bp); + return (status); + } + return (TRUE); } int |