Download raw body.
mg: move up directory in dired
Sorry the formatting is a little broken, I seem to have overestimated
my email client's ability to not mess with formatting when sending
plain text.
On Sat, 2024-06-01 at 15:22 -0400, Dante wrote:
> Hi,
>
> This is my first patch to OpenBSD, please let me know if I did
> anything wrong.
>
> This patch adds beheviour to mach Emacs dired mode. When you're in a
> dired buffer and press the caret key '^', it will open the parent
> directory.
> Thanks,
> Dante
>
> diff --git a/usr.bin/mg/dired.c b/usr.bin/mg/dired.c
> index 5cb747c37..de6a73833 100644
> --- a/usr.bin/mg/dired.c
> +++ b/usr.bin/mg/dired.c
> @@ -34,6 +34,7 @@ static int d_otherwindow(int, int);
> static int d_undel(int, int);
> static int d_undelbak(int, int);
> static int d_findfile(int, int);
> +static int d_updirectory(int, int);
> static int d_ffotherwindow(int, int);
> static int d_expunge(int, int);
> static int d_copy(int, int);
> @@ -122,6 +123,10 @@ static PF diredcz[] = {
> d_create_directory /* + */
> };
>
> +static PF diredcaret[] = {
> + d_updirectory /* ^ */
> +};
> +
> static PF direda[] = {
> d_filevisitalt, /* a */
> rescan, /* b */
> @@ -172,9 +177,9 @@ static struct KEYMAPE (1) d_backpagemap = {
> }
> };
>
> -static struct KEYMAPE (7) diredmap = {
> - 7,
> - 7,
> +static struct KEYMAPE (8) diredmap = {
> + 8,
> + 8,
> rescan,
> {
> {
> @@ -190,6 +195,9 @@ static struct KEYMAPE (7) diredmap = {
> {
> CCHR('Z'), '+', diredcz, (KEYMAP *) &
> metamap
> },
> + {
> + '^', '^', diredcaret, NULL
> + },
> {
> 'a', 'j', direda, NULL
> },
> @@ -363,6 +371,29 @@ d_findfile(int f, int n)
> return (readin(fname));
> }
>
> +int
> +d_updirectory(int f, int n)
> +{
> + struct buffer *bp;
> + int ret;
> + char fname[NFILEN];
> +
> + ret = snprintf(fname, sizeof(fname), "%s..", curbp-
> >b_fname);
> + if (ret < 0 || ret >= (int)sizeof(fname))
> + return (ABORT); /* Name is too long. */
> +
> + bp = dired_(fname);
> + if (bp == NULL)
> + return (FALSE);
> + curbp = bp;
> + if (showbuffer(bp, curwp, WFFULL) != TRUE)
> + return (FALSE);
> + if (bp->b_fname[0] != 0)
> + return (TRUE);
> + return (readin(fname));
> +}
> +
> int
> d_ffotherwindow(int f, int n)
> {
>
mg: move up directory in dired