This add dired-goto-file to mg. Comments/ok? Mark
Index: dired.c =================================================================== RCS file: /cvs/src/usr.bin/mg/dired.c,v retrieving revision 1.90 diff -u -p -u -p -r1.90 dired.c --- dired.c 28 Jun 2019 13:35:02 -0000 1.90 +++ dired.c 29 Jun 2019 16:47:06 -0000 @@ -51,6 +51,7 @@ static int d_backline(int, int); static int d_killbuffer_cmd(int, int); static int d_refreshbuffer(int, int); static int d_filevisitalt(int, int); +static int d_gotofile(int, int); static void reaper(int); static struct buffer *refreshbuffer(struct buffer *); static int createlist(struct buffer *); @@ -127,7 +128,10 @@ static PF direda[] = { d_del, /* d */ d_findfile, /* e */ d_findfile, /* f */ - d_refreshbuffer /* g */ + d_refreshbuffer, /* g */ + rescan, /* h */ + rescan, /* i */ + d_gotofile /* j */ }; static PF diredn[] = { @@ -186,7 +190,7 @@ static struct KEYMAPE (7) diredmap = { CCHR('Z'), '+', diredcz, (KEYMAP *) & metamap }, { - 'a', 'g', direda, NULL + 'a', 'j', direda, NULL }, { 'n', 'x', diredn, NULL @@ -208,6 +212,7 @@ dired_init(void) funmap_add(d_findfile, "dired-find-file"); funmap_add(d_ffotherwindow, "dired-find-file-other-window"); funmap_add(d_del, "dired-flag-file-deletion"); + funmap_add(d_gotofile, "dired-goto-file"); funmap_add(d_forwline, "dired-next-line"); funmap_add(d_otherwindow, "dired-other-window"); funmap_add(d_backline, "dired-previous-line"); @@ -1071,6 +1076,51 @@ createlist(struct buffer *bp) nlp = lforw(lp); } return (ret); +} + +int +d_gotofile(int f, int n) +{ + struct line *lp, *nlp; + struct buffer *curbp; + char fpath[NFILEN], fname[NFILEN]; + char *p, *fnp = NULL; + int tmp; + + if (getbufcwd(fpath, sizeof(fpath)) != TRUE) + fpath[0] = '\0'; + fnp = eread("Goto file: ", fpath, NFILEN, + EFNEW | EFCR | EFFILE | EFDEF); + if (fnp == NULL) + return (ABORT); + else if (fnp[0] == '\0') + return (FALSE); + + (void)xbasename(fname, fpath, NFILEN); + curbp = curwp->w_bufp; + tmp = 0; + for (lp = bfirstlp(curbp); lp != curbp->b_headp; lp = nlp) { + tmp++; + if ((p = findfname(lp, p)) == NULL) { + nlp = lforw(lp); + continue; + } + if (strcmp(fname, p) == 0) { + curwp->w_dotp = lp; + curwp->w_dotline = tmp; + (void)d_warpdot(curwp->w_dotp, &curwp->w_doto); + tmp--; + break; + } + nlp = lforw(lp); + } + if (tmp == curbp->b_lines - 1) { + ewprintf("File not found %s", fname); + return (FALSE); + } else { + ewprintf(""); + return (TRUE); + } } /* Index: mg.1 =================================================================== RCS file: /cvs/src/usr.bin/mg/mg.1,v retrieving revision 1.115 diff -u -p -u -p -r1.115 mg.1 --- mg.1 17 Jun 2019 11:39:26 -0000 1.115 +++ mg.1 29 Jun 2019 16:47:06 -0000 @@ -983,6 +983,8 @@ dired-do-copy dired-flag-file-deletion .It g dired-revert +.It j +dired-goto-file .It o dired-find-file-other-window .It p @@ -1025,6 +1027,8 @@ is executed. .It dired-find-file-other-window Open the file on the current line of the dired buffer in a different window. +.It dired-goto-file +Move the cursor to a file name in the dired buffer. .It dired-next-line Move the cursor to the next line. .It dired-other-window