[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vile] empty unmodified buffers

From: Paul Fox
Subject: [vile] empty unmodified buffers
Date: Wed, 17 Nov 2010 20:18:26 -0500

so, this clearly isn't a very important bug, since it's been with us
since at least 9.4, which is the earliest tree i have readily at hand. 
but recently i've found it annoying.  i'm not completely wedded to it,
though (clearly, if i've only noticed it recently), so if other people
think the status quo is good, that's fine.

it used to be that if you edited a file, and mis-typed the name, then
when you edited the correct file, the mis-named buffer would be reused.
this happened because of this snippet from getfile2bp():
            if (!b_is_argument(bp) &&
                !b_is_changed(bp) &&
                is_empty_buf(bp) &&
                !ffexists(bp->b_fname)) {
                /* empty, unmodified, and non-existent --
                   then it's okay to re-use this buffer */
                bp->b_active = FALSE;
                ch_fname(bp, nfname);
                return bp;

the first condition of the 'if' says that buffers that were named
on the commandline shouldn't be destroyed.

somewhere along the line, filefind() (which implements ":e") started
using the same core logic as the code for ":args", and as a result,
the BFARGS flag is now set for all edited files.  this essentially
makes all files look like command-line arguments, and so the buffer
reuse above never happens.

i must be fumble-fingering a lot these days, because i seem to be
accumulating unwanted buffers that i didn't use to notice.  the
downside, of course, are the false positives:  you do ":e newfile",
and realize you need to look at something (":e something"), and
when you go to switch back ("__" or ":e#") you find you have to
retype the ":e newfile" because it's gone.  this is why i'd understand
if the feature's unwanted.

anyway...  here's a patch that puts it back the way it used to be.


--- proto.h.orig        2010-11-17 19:59:08.000000000 -0500
+++ proto.h     2010-11-17 19:59:18.000000000 -0500
@@ -598,6 +598,7 @@
 extern int readin (char *fname, int lockfl, BUFFER *bp, int mflg);
 extern int same_fname (const char *fname, BUFFER *bp, int lengthen);
 extern int set_files_to_edit(const char *prompt, int appflag);
+extern int set_args_to_edit(const char *prompt, int appflag);
 extern int slowreadf (BUFFER *bp, int *nlinep);
 extern int write_enc_region (void);
 extern int writeout (const char *fn, BUFFER *bp, int forced, int msgf);
--- file.c.orig 2010-11-17 19:57:16.000000000 -0500
+++ file.c      2010-11-17 20:00:18.000000000 -0500
@@ -695,8 +695,8 @@
     return s;
-set_files_to_edit(const char *prompt, int appflag)
+static int
+set_files_to_edit_worker(const char *prompt, int appflag, int is_arg)
     int status;
     BUFFER *bp, *bp_next;
@@ -705,7 +705,7 @@
     char *actual;
     BUFFER *firstbp = 0;
-    TRACE((T_CALLED "set_files_to_edit(%s, %d)\n", NONNULL(prompt), appflag));
+    TRACE((T_CALLED "set_files_to_edit_worker(%s, %d, %d)\n", NONNULL(prompt), 
appflag, is_arg));
     if ((status = mlreply_file(prompt, &lastfileedited,
                               FILEC_READ | FILEC_EXPAND,
@@ -715,7 +715,8 @@
                status = FALSE;
-           bp->b_flag |= BFARGS;       /* treat this as an argument */
+           if (is_arg)
+               bp->b_flag |= BFARGS;   /* treat this as an argument */
            if (firstbp == 0) {
                firstbp = bp;
                if (!appflag) {
@@ -737,6 +738,18 @@
+set_files_to_edit(const char *prompt, int appflag)
+    return set_files_to_edit_worker(prompt, appflag, FALSE);
+set_args_to_edit(const char *prompt, int appflag)
+    return set_files_to_edit_worker(prompt, appflag, TRUE);
 filefind(int f GCC_UNUSED, int n GCC_UNUSED)
--- buffer.c.orig       2010-11-17 19:59:29.000000000 -0500
+++ buffer.c    2010-11-17 19:59:39.000000000 -0500
@@ -2345,7 +2345,7 @@
        return FALSE;
-    return set_files_to_edit("Set arguments: ", FALSE);
+    return set_args_to_edit("Set arguments: ", FALSE);
@@ -2357,7 +2357,7 @@
     if (end_named_cmd()) {
        return listbuffers(f, n);
-    return set_files_to_edit("Set arguments: ", FALSE);
+    return set_args_to_edit("Set arguments: ", FALSE);

 paul fox, address@hidden (arlington, ma, where it's 46.8 degrees)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]