summaryrefslogtreecommitdiff
path: root/usr.bin/mg/file.c
diff options
context:
space:
mode:
authorChad Loder <cloder@cvs.openbsd.org>2005-05-27 08:52:31 +0000
committerChad Loder <cloder@cvs.openbsd.org>2005-05-27 08:52:31 +0000
commit141f6c9496a550f50379a449e7eca41c9b368813 (patch)
treee83deba491a5479747ab582eb0e2bd917f7cdf4e /usr.bin/mg/file.c
parent5ae6cd1060db9ededd174ac3a42926ed709e8c1c (diff)
In find file, behave like emacs: the default starting directory for
completion is the directory of the current buffer's file, if any, rather than the working directory from where you launched mg. Prodding by reyk, ok reyk and fgont
Diffstat (limited to 'usr.bin/mg/file.c')
-rw-r--r--usr.bin/mg/file.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c
index 69dfd6d7159..a901f6e8d86 100644
--- a/usr.bin/mg/file.c
+++ b/usr.bin/mg/file.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: file.c,v 1.33 2005/04/21 19:16:21 beck Exp $ */
+/* $OpenBSD: file.c,v 1.34 2005/05/27 08:52:30 cloder Exp $ */
/*
* File commands.
@@ -39,9 +39,18 @@ int
filevisit(int f, int n)
{
BUFFER *bp;
- char fname[NFILEN], *bufp, *adjf;
+ char fname[NFILEN], *bufp, *adjf, *slash;
+
+ 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 file: ", fname, NFILEN, EFNEW | EFCR | EFFILE);
+ bufp = eread("Find file: ", fname, NFILEN, EFNEW | EFCR | EFFILE | EFDEF);
if (bufp == NULL)
return (ABORT);
else if (bufp[0] == '\0')