Based on discussion with mark & nima,
I think we can overwrite dired keybindings
with the ones that warp the dot to the file name.

This also fixes an issue Mark encountereted with
filenames that contain spaces.

Since this is a huge diff, I need some heavy testing ;-).

Index: dired.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.48
diff -u -p -r1.48 dired.c
--- dired.c     23 Jan 2011 00:45:03 -0000      1.48
+++ dired.c     12 Aug 2011 17:45:41 -0000
@@ -36,6 +36,10 @@ static int    d_rename(int, int);
 static int      d_shell_command(int, int);
 static int      d_create_directory(int, int);
 static int      d_makename(struct line *, char *, size_t);
+static int      d_forwpage(int, int);
+static int      d_backpage(int, int);
+static int      d_forwline(int, int);
+static int      d_backline(int, int);
 static void     reaper(int);
 
 extern struct keymap_s helpmap, cXmap, metamap;
@@ -57,15 +61,15 @@ static PF dirednul[] = {
 static PF diredcl[] = {
        reposition,             /* ^L */
        d_findfile,             /* ^M */
-       forwline,               /* ^N */
+       d_forwline,             /* ^N */
        rescan,                 /* ^O */
-       backline,               /* ^P */
+       d_backline,             /* ^P */
        rescan,                 /* ^Q */
        backisearch,            /* ^R */
        forwisearch,            /* ^S */
        rescan,                 /* ^T */
        universal_argument,     /* ^U */
-       forwpage,               /* ^V */
+       d_forwpage,             /* ^V */
        rescan,                 /* ^W */
        NULL                    /* ^X */
 };
@@ -77,7 +81,7 @@ static PF diredcz[] = {
        rescan,                 /* ^] */
        rescan,                 /* ^^ */
        rescan,                 /* ^_ */
-       forwline,               /* SP */
+       d_forwline,             /* SP */
        d_shell_command,        /* ! */
        rescan,                 /* " */
        rescan,                 /* # */
@@ -99,9 +103,9 @@ static PF diredc[] = {
 };
 
 static PF diredn[] = {
-       forwline,               /* n */
+       d_forwline,             /* n */
        d_ffotherwindow,        /* o */
-       backline,               /* p */
+       d_backline,             /* p */
        rescan,                 /* q */
        d_rename,               /* r */
        rescan,                 /* s */
@@ -116,13 +120,32 @@ static PF direddl[] = {
        d_undelbak              /* del */
 };
 
+static PF diredbp[] = {
+       d_backpage              /* v */ 
+};
+
+static PF dirednull[] = {
+       NULL
+};
+
 #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,
+static struct KEYMAPE (1 + IMAPEXT) d_backpagemap = {
+       1,
+       1 + IMAPEXT,
+       rescan,                 
+       {
+               {
+               'v', 'v', diredbp, NULL
+               }
+       }
+};
+
+static struct KEYMAPE (7 + NDIRED_XMAPS + IMAPEXT) diredmap = {
+       7 + NDIRED_XMAPS,
+       7 + NDIRED_XMAPS + IMAPEXT,
        rescan,
        {
 #ifndef NO_HELP
@@ -138,6 +161,10 @@ static struct KEYMAPE (6 + NDIRED_XMAPS 
                        CCHR('L'), CCHR('X'), diredcl, (KEYMAP *) & cXmap
                },
                {
+                       CCHR('['), CCHR('['), dirednull, (KEYMAP *) & 
+                       d_backpagemap
+               },
+               {
                        CCHR('Z'), '+', diredcz, (KEYMAP *) & metamap
                },
                {
@@ -592,6 +619,118 @@ d_makename(struct line *lp, char *fn, si
        return ((lgetc(lp, 2) == 'd') ? TRUE : FALSE);
 }
 
+static int
+d_forwpage(int f, int n) 
+{
+       char tline[256], *anchor, *last, *col[9];
+       int lim = 0, z = 9;
+
+       while (z--)
+               col[z] = NULL;
+       forwpage(f | FFRAND, n);
+       (void) strlcpy(tline, curwp->w_dotp->l_text, sizeof
+       (tline));
+       for ((anchor = strtok_r(tline, " ", &last)); anchor;
+           (anchor = strtok_r(NULL, " ", &last))) {
+               if (lim <= 8)
+                       col[lim++] = anchor;
+       }
+       col[lim] = NULL;
+       if (col[8] == NULL ||
+          strstr(curwp->w_dotp->l_text, col[8]) == NULL)
+               curwp->w_doto = 0;
+       else {
+               curwp->w_doto =
+               strstr(curwp->w_dotp->l_text, col[8]) -
+               curwp->w_dotp->l_text;
+       }                
+       return TRUE;
+}
+
+static int 
+d_backpage (int f, int n)
+{
+       char tline[256], *anchor, *last, *col[9];
+       int lim = 0, z = 9;
+
+       while (z--)
+               col[z] = NULL;
+       backpage(f | FFRAND, n);
+       (void) strlcpy(tline, curwp->w_dotp->l_text, sizeof
+       (tline));
+       for ((anchor = strtok_r(tline, " ", &last)); anchor;
+       (anchor = strtok_r(NULL, " ", &last))) {
+               if (lim <= 8)
+                       col[lim++] = anchor;
+        }
+       col[lim] = NULL;
+       if (col[8] == NULL ||
+          strstr(curwp->w_dotp->l_text, col[8]) == NULL)
+               curwp->w_doto = 0;
+       else {
+               curwp->w_doto =
+               strstr(curwp->w_dotp->l_text, col[8]) -
+               curwp->w_dotp->l_text;
+       }
+       return TRUE;
+}
+
+static int
+d_forwline (int f, int n)
+{
+       char tline[256], *anchor, *last, *col[9];
+       int lim = 0, z = 9;
+
+       while (z--)
+               col[z] = NULL;
+       forwline(f | FFRAND, n);
+       (void) strlcpy(tline, curwp->w_dotp->l_text, sizeof
+       (tline));
+       for ((anchor = strtok_r(tline, " ", &last)); anchor;
+       (anchor = strtok_r(NULL, " ", &last))) {
+               if (lim <= 8)
+                       col[lim++] = anchor;
+       }
+       col[lim] = NULL;
+       if (col[8] == NULL ||
+          strstr(curwp->w_dotp->l_text, col[8]) == NULL)
+               curwp->w_doto = 0;
+       else {
+               curwp->w_doto =
+               strstr(curwp->w_dotp->l_text, col[8]) -
+               curwp->w_dotp->l_text;
+       }
+       return TRUE;
+}
+
+static int
+d_backline (int f, int n)
+{
+       char tline[256], *anchor, *last, *col[9];
+       int lim = 0, z = 9;
+
+       while (z--)
+               col[z] = NULL;
+       backline(f | FFRAND, n);
+       (void) strlcpy(tline, curwp->w_dotp->l_text, sizeof
+       (tline));
+       for ((anchor = strtok_r(tline, " ", &last)); anchor;
+       (anchor = strtok_r(NULL, " ", &last))) {
+               if (lim <= 8)
+                       col[lim++] = anchor;
+       }
+       col[lim] = NULL;
+       if (col[8] == NULL ||
+          strstr(curwp->w_dotp->l_text, col[8]) == NULL)
+               curwp->w_doto = 0;
+       else {
+               curwp->w_doto =
+               strstr(curwp->w_dotp->l_text, col[8]) -
+               curwp->w_dotp->l_text;
+       }
+       return TRUE;
+}
+
 /*
  * XXX dname needs to have enough place to store an additional '/'.
  */
@@ -600,11 +739,15 @@ dired_(char *dname)
 {
        struct buffer   *bp;
        FILE    *dirpipe;
-       char     line[256];
-       int      len, ret, counter, warp;
+       char     line[256], tline[256], *anchor, *last, *col[8];
+       int      len, ret, counter, warp, lim, z;
        counter = 0;
        warp = 0;
+       lim = 0;
+       z = 9;
 
+       while (z--)
+               col[z] = NULL;  
        if ((fopen(dname,"r")) == NULL) {
                if (errno == EACCES)
                        ewprintf("Permission denied");
@@ -646,12 +789,22 @@ dired_(char *dname)
                                warp = counter;
                }
        }
+       (void) strlcpy(tline, line, sizeof(line));
+       for ((anchor = strtok_r(tline, " ", &last)); anchor;
+           (anchor = strtok_r(NULL, " ", &last))) {
+               if (lim <= 8)
+                       col[lim++] = anchor;
+       }
+       col[lim] = NULL;
        if ((strrchr(line,' ')) != NULL) {
                if (strcmp((strrchr(line,' '))," ..") == 0) 
                        warp = counter - 1;
        }               
-       if ((strrchr(line,' ')) != NULL)
-               bp->b_doto = strrchr(line,' ') - line + 1;
+       if (col[8] == NULL ||
+          strstr(line, col[8]) == NULL)
+               bp->b_doto = 0;
+       else
+               bp->b_doto = strstr(line, col[8]) - line;
        if (pclose(dirpipe) == -1) {
                ewprintf("Problem closing pipe to ls : %s",
                    strerror(errno));

Reply via email to