[RFC][Patch] Add swap file age to E325's details

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[RFC][Patch] Add swap file age to E325's details

Nazri Ramliy
I often do stupid things like opening a file that I have
currently open in another vim session in some other
terminal.  Vim helpfully reminds me about this by showing
E325:

           E325: ATTENTION
   Found a swap file by the name ".main.c.swp"
             owned by: mool   dated: Tue May 29 21:09:28 2001
            file name:
             modified: no
            user name: mool   host name: masaka.moolenaar.net
           process ID: 12559 (still running)

Upon reading this message what I normally do is hunt down
the terminal where I have that original vim session running.

The fact that I normally have like seven terminals open
running screen sessions, and each screen may have up to
three or four 'windows' multiplexed do not help much
in finding the original vim session that 'owns' the swap
file.

I have resorted to writing a small shell script that,
given the process ID, tells me which terminal that process
is running from. From there I switched to that terminal and
cycle through the screen windows to find the vim session.

This is further complicated by the possibility that:

        1) the original vim session might have been
           suspended (Ctrl+Z'd)

        2) there's one or more jobs being suspended in the
           same tty
       
        3) another curses program is running in the
           foreground
       
        4) the file in question might be in one of many vim
           tabs

Sounds itchy?

Sometimes this happen a few times throughout the day.
Did I mention I often do stupid things like this?

The script that I wrote helps but only to some extent.

A few days back I got that E325 message and it told me that
the process is still running. I checked the process ID and
it turned out that the process is not vim's. The swap file
was a 'leftover' from a vim session from a previous boot and
it just so happen that the process ID recorded in that swap
file matches with an unrelated process that is currently
running on my system.

I can live with the 'hunting down the original vim' process.
But I can't stand the loss of focus due the shift of my
attention from

        "I want to edit this file now"
to

        "Arrgghhh!! where is that vim session that I have this
        file opened?".

This itch really annoy me.  Attached is a patch that I think
would reduce the itch a bit. It adds the 'age' of the swap
file to the details in that E325 message:

          E325: ATTENTION
  Found a swap file by the name ".main.c.swp"
            owned by: mool
               dated: Tue May 29 21:09:28 2001
                 age: 11471 days 13 hours 9 minutes 28 seconds
           file name:
            modified: no
           user name: mool   host name: masaka.moolenaar.net
          process ID: 12559 (still running)

The age is calculated up to the point when the E325 is
shown.

IMHO age is so much easier to 'grok' than date so it will be
much easier to decide on what to do with the swap file by
looking at its age instead of its last modification date as
shown by the first "dated:' entry - if the age says it's
more than 1 day old and you've just rebooted your system a
while ago then you can immediately know that it's a
'zombified' swap file.

The patch also put the first "dated:" line to a line by
itself. Originally it was on the same line as the 'owner'
line. I think this alignment is better because it's easier
to scan the age and date entries since they all start at the
same column.

Bram if you think it's worthy to be included in the main vim
source (or needs refinement) then I'll update the
documentation too.

Wow this email is a lot longer than I thought it was going
to be.  Sorry I don't have time to make it shorter :)

nazri
--
Clear understanding beats experience.

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe from this group, send email to vim_dev+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

swap_age.patch (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [RFC][Patch] Add swap file age to E325's details

Lech Lorens
On 30-Mar-2010 Nazri Ramliy <[hidden email]> wrote:
>            E325: ATTENTION
>    Found a swap file by the name ".main.c.swp"
>              owned by: mool   dated: Tue May 29 21:09:28 2001

[...]

>           E325: ATTENTION
>   Found a swap file by the name ".main.c.swp"
>             owned by: mool
>                dated: Tue May 29 21:09:28 2001
>                  age: 11471 days 13 hours 9 minutes 28 seconds

I like the modification you proposed. I've often needed to consult the
calendar to make heads or tails of the "dated" field. This makes it
a bit easier.
Thank you!

--
Cheers,
Lech

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.