summaryrefslogtreecommitdiff
path: root/usr.bin/mg
diff options
context:
space:
mode:
authorKjell Wooding <kjell@cvs.openbsd.org>2005-10-13 05:47:46 +0000
committerKjell Wooding <kjell@cvs.openbsd.org>2005-10-13 05:47:46 +0000
commitb09ffc412d1e814780768090c2e33095042d015d (patch)
treefe5cd8d6719df23182ab6812d4464abdad5d7aa2 /usr.bin/mg
parent9bd1b3d347aac9b6027d99318dbda3cca8eae3e2 (diff)
Fix dired mode. Make deletions work, and keystrokes match emacs.
* dired-other-window should default to current buffer's path. * Remove redundant code (from Han Boetes) * Move initialization (and since we're here, fix mail-mode initialization too) * Remove redundant keymap in dired.c, and replace it with the better one that was being ignored in keymap.c.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r--usr.bin/mg/dired.c205
-rw-r--r--usr.bin/mg/fileio.c3
-rw-r--r--usr.bin/mg/keymap.c122
-rw-r--r--usr.bin/mg/mail.c3
-rw-r--r--usr.bin/mg/main.c7
5 files changed, 133 insertions, 207 deletions
diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
index d76283d35cb..77c6313de71 100644
--- a/usr.bin/mg/dired.c
+++ b/usr.bin/mg/dired.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dired.c,v 1.22 2005/10/11 01:28:29 deraadt Exp $ */
+/* $OpenBSD: dired.c,v 1.23 2005/10/13 05:47:44 kjell Exp $ */
/* This file is in the public domain. */
@@ -19,113 +19,127 @@
#ifndef NO_DIRED
-int d_findfile(int, int);
-
-static PF dired_cmds_1[] = {
- forwline, /* space */
- d_shell_command, /* ! */
- rescan, /* " */
- rescan, /* # */
- rescan, /* $ */
- rescan, /* % */
- rescan, /* & */
- rescan, /* ' */
- rescan, /* ( */
- rescan, /* ) */
- rescan, /* * */
- d_create_directory /* + */
+void dired_init(void);
+
+extern struct keymap_s helpmap, cXmap, metamap;
+
+static PF dirednul[] = {
+ setmark, /* ^@ */
+ gotobol, /* ^A */
+ backchar, /* ^B */
+ rescan, /* ^C */
+ d_del, /* ^D */
+ gotoeol, /* ^E */
+ forwchar, /* ^F */
+ ctrlg, /* ^G */
+#ifndef NO_HELP
+ NULL, /* ^H */
+#endif /* !NO_HELP */
};
-static PF dired_cmds_2[] = {
- rescan, /* a */
- rescan, /* b */
- rescan, /* c */
- rescan, /* d */
- d_findfile, /* e */
- d_findfile, /* f */
- rescan, /* g */
- rescan, /* h */
- rescan, /* i */
- rescan, /* j */
- rescan, /* k */
- rescan, /* l */
- rescan, /* m */
- forwline, /* n */
- d_ffotherwindow, /* o */
- rescan, /* p */
- rescan, /* q */
- rescan, /* r */
- rescan, /* s */
- rescan, /* t */
- rescan, /* u */
- d_findfile, /* v */
- rescan, /* w */
- d_expunge, /* x */
- rescan, /* y */
- rescan /* z */
+static PF diredcl[] = {
+ reposition, /* ^L */
+ d_findfile, /* ^M */
+ forwline, /* ^N */
+ rescan, /* ^O */
+ backline, /* ^P */
+ rescan, /* ^Q */
+ backisearch, /* ^R */
+ forwisearch, /* ^S */
+ rescan, /* ^T */
+ universal_argument, /* ^U */
+ forwpage, /* ^V */
+ rescan, /* ^W */
+ NULL /* ^X */
};
-static PF dired_cmds_3[] = {
- rescan, /* A */
- rescan, /* B */
- d_copy, /* C */
- d_del, /* D */
- rescan, /* E */
- rescan, /* F */
- rescan, /* G */
- rescan, /* H */
- rescan, /* I */
- rescan, /* J */
- rescan, /* K */
- rescan, /* L */
- rescan, /* M */
- rescan, /* N */
- rescan, /* O */
- rescan, /* P */
- rescan, /* Q */
- d_rename, /* R */
- rescan, /* S */
- rescan, /* T */
- rescan, /* U */
- d_findfile, /* V */
- rescan, /* W */
- d_expunge, /* X */
- rescan, /* Y */
- rescan /* Z */
+static PF diredcz[] = {
+ spawncli, /* ^Z */
+ NULL, /* esc */
+ rescan, /* ^\ */
+ rescan, /* ^] */
+ rescan, /* ^^ */
+ rescan, /* ^_ */
+ forwline /* SP */
};
-static PF dired_pf[] = {
- d_findfile, /* ^M */
- rescan, /* ^N */
- d_findfile /* ^O */
+static PF diredc[] = {
+ d_copy, /* c */
+ d_del, /* d */
+ d_findfile, /* e */
+ d_findfile /* f */
+};
+
+static PF diredn[] = {
+ forwline, /* n */
+ d_ffotherwindow, /* o */
+ backline, /* p */
+ rescan, /* q */
+ d_rename, /* r */
+ rescan, /* s */
+ rescan, /* t */
+ d_undel, /* u */
+ rescan, /* v */
+ rescan, /* w */
+ d_expunge /* x */
+};
+
+static PF direddl[] = {
+ d_undelbak /* del */
};
-static struct KEYMAPE (4 + IMAPEXT) diredmap = {
- 4,
- 4 + IMAPEXT,
+#ifndef DIRED_XMAPS
+#define NDIRED_XMAPS 0 /* number of extra map sections */
+#endif /* DIRED_XMAPS */
+
+static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
+ 6 + NDIRED_XMAPS,
+ 6 + NDIRED_XMAPS + IMAPEXT,
rescan,
{
- { CCHR('M'), CCHR('O'), dired_pf, NULL },
- { ' ', '+', dired_cmds_1, NULL },
- { 'A', 'Z', dired_cmds_3, NULL },
- { 'a', 'z', dired_cmds_2, NULL }
+#ifndef NO_HELP
+ {
+ CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap
+ },
+#else /* !NO_HELP */
+ {
+ CCHR('@'), CCHR('G'), dirednul, NULL
+ },
+#endif /* !NO_HELP */
+ {
+ CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap
+ },
+ {
+ CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap
+ },
+ {
+ 'c', 'f', diredc, NULL
+ },
+ {
+ 'n', 'x', diredn, NULL
+ },
+ {
+ CCHR('?'), CCHR('?'), direddl, NULL
+ },
+#ifdef DIRED_XMAPS
+ DIRED_XMAPS, /* map sections for dired mode keys */
+#endif /* DIRED_XMAPS */
}
};
+void
+dired_init(void)
+{
+ maps_add((KEYMAP *)&diredmap, "dired");
+}
/* ARGSUSED */
int
dired(int f, int n)
{
- static int inited = 0;
char dirname[NFILEN], *bufp, *slash;
BUFFER *bp;
- if (inited == 0) {
- maps_add((KEYMAP *)&diredmap, "dired");
- inited = 1;
- }
-
if (curbp->b_fname && curbp->b_fname[0] != '\0') {
(void)strlcpy(dirname, curbp->b_fname, sizeof(dirname));
if ((slash = strrchr(dirname, '/')) != NULL) {
@@ -143,9 +157,7 @@ dired(int f, int n)
return (FALSE);
if ((bp = dired_(bufp)) == NULL)
return (FALSE);
- bp->b_modes[0] = name_mode("fundamental");
- bp->b_modes[1] = name_mode("dired");
- bp->b_nmodes = 1;
+
curbp = bp;
return (showbuffer(bp, curwp, WFHARD | WFMODE));
}
@@ -154,11 +166,20 @@ dired(int f, int n)
int
d_otherwindow(int f, int n)
{
- char dirname[NFILEN], *bufp;
+ char dirname[NFILEN], *bufp, *slash;
BUFFER *bp;
MGWIN *wp;
- dirname[0] = '\0';
+ if (curbp->b_fname && curbp->b_fname[0] != '\0') {
+ (void)strlcpy(dirname, curbp->b_fname, sizeof(dirname));
+ if ((slash = strrchr(dirname, '/')) != NULL) {
+ *(slash + 1) = '\0';
+ }
+ } else {
+ if (getcwd(dirname, sizeof(dirname)) == NULL)
+ dirname[0] = '\0';
+ }
+
if ((bufp = eread("Dired other window: ", dirname, NFILEN,
EFDEF | EFNEW | EFCR)) == NULL)
return (ABORT);
diff --git a/usr.bin/mg/fileio.c b/usr.bin/mg/fileio.c
index ad70091c80b..55275b75ecb 100644
--- a/usr.bin/mg/fileio.c
+++ b/usr.bin/mg/fileio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fileio.c,v 1.50 2005/06/14 18:14:40 kjell Exp $ */
+/* $OpenBSD: fileio.c,v 1.51 2005/10/13 05:47:45 kjell Exp $ */
/* This file is in the public domain. */
@@ -456,6 +456,7 @@ d_makename(LINE *lp, char *fn, int len)
strlcpy(fn, curbp->b_fname, len);
p = lp->l_text;
ep = lp->l_text + llength(lp);
+ p++; /* skip action letter, if any */
for (i = 0; i < NAME_FIELD; i++) {
while (p < ep && isspace(*p))
p++;
diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c
index 4d292bfc84b..920618606f4 100644
--- a/usr.bin/mg/keymap.c
+++ b/usr.bin/mg/keymap.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: keymap.c,v 1.32 2005/10/11 00:50:00 kjell Exp $ */
+/* $OpenBSD: keymap.c,v 1.33 2005/10/13 05:47:45 kjell Exp $ */
/* This file is in the public domain. */
@@ -26,7 +26,7 @@ static PF cHa[] = {
desckey /* c */
};
-static struct KEYMAPE (2 + IMAPEXT) helpmap = {
+struct KEYMAPE (2 + IMAPEXT) helpmap = {
2,
2 + IMAPEXT,
rescan,
@@ -146,7 +146,7 @@ static PF cXcar[] = {
};
#ifndef NO_MACRO
-static struct KEYMAPE (6 + IMAPEXT) cXmap = {
+struct KEYMAPE (6 + IMAPEXT) cXmap = {
6,
6 + IMAPEXT,
#else /* !NO_MACRO */
@@ -252,7 +252,7 @@ static PF metatilde[] = {
delbword /* DEL */
};
-static struct KEYMAPE (8 + IMAPEXT) metamap = {
+struct KEYMAPE (8 + IMAPEXT) metamap = {
8,
8 + IMAPEXT,
rescan,
@@ -443,112 +443,10 @@ static struct KEYMAPE (1 + IMAPEXT) overwmap = {
}
};
-#ifndef NO_DIRED
-static PF dirednul[] = {
- setmark, /* ^@ */
- gotobol, /* ^A */
- backchar, /* ^B */
- rescan, /* ^C */
- d_del, /* ^D */
- gotoeol, /* ^E */
- forwchar, /* ^F */
- ctrlg, /* ^G */
-#ifndef NO_HELP
- NULL, /* ^H */
-#endif /* !NO_HELP */
-};
-
-static PF diredcl[] = {
- reposition, /* ^L */
- forwline, /* ^M */
- forwline, /* ^N */
- rescan, /* ^O */
- backline, /* ^P */
- rescan, /* ^Q */
- backisearch, /* ^R */
- forwisearch, /* ^S */
- rescan, /* ^T */
- universal_argument, /* ^U */
- forwpage, /* ^V */
- rescan, /* ^W */
- NULL /* ^X */
-};
-
-static PF diredcz[] = {
- spawncli, /* ^Z */
- NULL, /* esc */
- rescan, /* ^\ */
- rescan, /* ^] */
- rescan, /* ^^ */
- rescan, /* ^_ */
- forwline /* SP */
-};
-
-static PF diredc[] = {
- d_copy, /* c */
- d_del, /* d */
- d_findfile, /* e */
- d_findfile /* f */
-};
-
-static PF diredn[] = {
- forwline, /* n */
- d_ffotherwindow, /* o */
- backline, /* p */
- rescan, /* q */
- d_rename, /* r */
- rescan, /* s */
- rescan, /* t */
- d_undel, /* u */
- rescan, /* v */
- rescan, /* w */
- d_expunge /* x */
-};
-
-static PF direddl[] = {
- d_undelbak /* del */
-};
-
-#ifndef DIRED_XMAPS
-#define NDIRED_XMAPS 0 /* number of extra map sections */
-#endif /* DIRED_XMAPS */
-
-static struct KEYMAPE (6 + NDIRED_XMAPS + IMAPEXT) diredmap = {
- 6 + NDIRED_XMAPS,
- 6 + NDIRED_XMAPS + IMAPEXT,
- rescan,
- {
-#ifndef NO_HELP
- {
- CCHR('@'), CCHR('H'), dirednul, (KEYMAP *) & helpmap
- },
-#else /* !NO_HELP */
- {
- CCHR('@'), CCHR('G'), dirednul, NULL
- },
-#endif /* !NO_HELP */
- {
- CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap
- },
- {
- CCHR('Z'), ' ', diredcz, (KEYMAP *) & metamap
- },
- {
- 'c', 'f', diredc, NULL
- },
- {
- 'n', 'x', diredn, NULL
- },
- {
- CCHR('?'), CCHR('?'), direddl, NULL
- },
-#ifdef DIRED_XMAPS
- DIRED_XMAPS, /* map sections for dired mode keys */
-#endif /* DIRED_XMAPS */
- }
-};
-#endif /* !NO_DIRED */
+/*
+ * The basic (root) keyboard map
+ */
MAPS fundamental_mode = { (KEYMAP *)&fundmap, "fundamental" };
/*
@@ -574,9 +472,6 @@ static MAPS map_table[] = {
#ifndef NO_HELP
{(KEYMAP *) &helpmap, "help",},
#endif
-#ifndef NO_DIRED
- {(KEYMAP *) &diredmap, "dired",},
-#endif
{NULL, NULL}
};
@@ -596,6 +491,9 @@ maps_init(void)
}
}
+/*
+ * Insert a new (named) keymap at the head of the keymap list.
+ */
int
maps_add(KEYMAP *map, const char *name)
{
diff --git a/usr.bin/mg/mail.c b/usr.bin/mg/mail.c
index 0ddfa6fcfab..f14ca04de13 100644
--- a/usr.bin/mg/mail.c
+++ b/usr.bin/mg/mail.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mail.c,v 1.6 2005/08/09 00:53:48 kjell Exp $ */
+/* $OpenBSD: mail.c,v 1.7 2005/10/13 05:47:45 kjell Exp $ */
/*
* This file is in the public domain.
*
@@ -10,6 +10,7 @@
#include "kbd.h"
#include "funmap.h"
+void mail_init(void);
static int fake_self_insert(int, int);
static int mail(int, int);
diff --git a/usr.bin/mg/main.c b/usr.bin/mg/main.c
index a51fc4bd0c7..8aeae100bc3 100644
--- a/usr.bin/mg/main.c
+++ b/usr.bin/mg/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.41 2005/08/09 00:53:48 kjell Exp $ */
+/* $OpenBSD: main.c,v 1.42 2005/10/13 05:47:45 kjell Exp $ */
/* This file is in the public domain. */
@@ -63,7 +63,12 @@ main(int argc, char **argv)
{
extern void grep_init(void);
extern void theo_init(void);
+ extern void mail_init(void);
+#ifndef NO_DIRED
+ extern void dired_init(void);
+ dired_init();
+#endif /* !NO_DIRED */
grep_init();
theo_init();
mail_init();