mg(1) dired buffer refresh

2013-05-27 Thread Mark Lumsden
In mg dired mode, if you execute these commands:

dired-copy-file
dired-rename-file
dired-create-directory

The dired buffer is not refreshed with the updated action. This diff
fixes that. Comments/oks?

-lum

Index: dired.c
===
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.52
diff -u -p -r1.52 dired.c
--- dired.c 3 Nov 2012 15:36:03 -   1.52
+++ dired.c 27 May 2013 13:35:09 -
@@ -44,6 +44,7 @@ static int d_backpage(int, int);
 static int  d_forwline(int, int);
 static int  d_backline(int, int);
 static void reaper(int);
+static struct buffer   *refreshbuffer(struct buffer *);
 
 extern struct keymap_s helpmap, cXmap, metamap;
 
@@ -422,7 +423,8 @@ d_copy(int f, int n)
ret = (copy(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -455,7 +457,8 @@ d_rename(int f, int n)
ret = (rename(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -638,8 +641,28 @@ d_create_directory(int f, int n)
tocreate);
return (FALSE);
}
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
+}
+
+struct buffer *
+refreshbuffer(struct buffer *bp)
+{
+   char*tmp;
+
+   tmp = strdup(bp-b_fname);
+   killbuffer(bp);
+
+   /* dired_() uses findbuffer() to create new buffer */
+   if ((bp = dired_(tmp)) == NULL) {
+   free(tmp);
+   return (NULL);
+   }
+   free(tmp);
+   curbp = bp;
+
+   return (bp);
 }
 
 static int



mg(1) dired buffer refresh

2013-05-27 Thread Mark Lumsden
In mg dired mode, if you execute these commands:

dired-copy-file
dired-rename-file
dired-create-directory

The dired buffer is not refreshed with the updated action. This diff
fixes that. Comments/oks?

-lum

Index: dired.c
===
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.52
diff -u -p -r1.52 dired.c
--- dired.c 3 Nov 2012 15:36:03 -   1.52
+++ dired.c 27 May 2013 13:35:09 -
@@ -44,6 +44,7 @@ static int d_backpage(int, int);
 static int  d_forwline(int, int);
 static int  d_backline(int, int);
 static void reaper(int);
+static struct buffer   *refreshbuffer(struct buffer *);
 
 extern struct keymap_s helpmap, cXmap, metamap;
 
@@ -422,7 +423,8 @@ d_copy(int f, int n)
ret = (copy(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -455,7 +457,8 @@ d_rename(int f, int n)
ret = (rename(frname, toname) = 0) ? TRUE : FALSE;
if (ret != TRUE)
return (ret);
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
 }
 
@@ -638,8 +641,28 @@ d_create_directory(int f, int n)
tocreate);
return (FALSE);
}
-   bp = dired_(curbp-b_fname);
+   if ((bp = refreshbuffer(curbp)) == NULL)
+   return (FALSE);
return (showbuffer(bp, curwp, WFFULL | WFMODE));
+}
+
+struct buffer *
+refreshbuffer(struct buffer *bp)
+{
+   char*tmp;
+
+   tmp = strdup(bp-b_fname);
+   killbuffer(bp);
+
+   /* dired_() uses findbuffer() to create new buffer */
+   if ((bp = dired_(tmp)) == NULL) {
+   free(tmp);
+   return (NULL);
+   }
+   free(tmp);
+   curbp = bp;
+
+   return (bp);
 }
 
 static int