no backup of RCS files

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

no backup of RCS files

Michael Weiser
Hi,

I'm trying to configure vim to do backups but not on files which are
already in RCS, i.e. have a ,v file next to them. So I guess I'd have to
check if a file <filename>,v or RCS/<filename>,v exists but I have
absolutely no clue of how to go about it.

Is there some experienced vimrc hacker here who could start me off?

Thanks in advance.
--
Michael
Reply | Threaded
Open this post in threaded view
|

Re: no backup of RCS files

Mikołaj Machowski
Dnia czwartek 23 czerwiec 2005 20:08, Michael Weiser napisa?:
> Hi,
>
> I'm trying to configure vim to do backups but not on files which are
> already in RCS, i.e. have a ,v file next to them. So I guess I'd have to
> check if a file <filename>,v or RCS/<filename>,v exists but I have
> absolutely no clue of how to go about it.
>
> Is there some experienced vimrc hacker here who could start me off?
>
I understand there is rcs filetype. Create your own
filetype plugin with entry

if filereadable(expand("%:p").',v') ||
filereadable(expand("%:p:h").'/RCS/'.expand("%:p:t").',v')
    set nobackup
endif

:help filereadable()
:help expand()
:help write-filetype-plugin


Note: It is possible you will have to place this in after directory:

:help after-directory

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim-list(s) Users Map: (last change 15 May)
 http://skawina.eu.org/mikolaj/vimlist
CLEWN - http://clewn.sf.net

Reply | Threaded
Open this post in threaded view
|

Re: no backup of RCS files

Hari Krishna Dara
In reply to this post by Michael Weiser

On Thu, 23 Jun 2005 at 8:08pm, Michael Weiser wrote:

> Hi,
>
> I'm trying to configure vim to do backups but not on files which are
> already in RCS, i.e. have a ,v file next to them. So I guess I'd have to
> check if a file <filename>,v or RCS/<filename>,v exists but I have
> absolutely no clue of how to go about it.
>
> Is there some experienced vimrc hacker here who could start me off?
>
> Thanks in advance.
>

The 'backup' option that controls this behavior is global, so you can't
really make this check early and change the behavior. But onething you
can probably do is to "tinker" with it just before writing the file,
when the BufWritePre autocommand is generated. I don't know if this will
work, and it might not actually work as expected if you write multiple
files at the same time (depending on how Vim generates the
BufWritePre/BufWritePost autocommand pairs). Try the below and see if it
works (untested):

function! DisableBackupIfInRCS(bufName)
    if (filereadable(bufName.',v') ||
            \ filereadable(fnamemodify(bufName, ':p:h').'/RCS/'.
            \ fnamemodify(bufName, ':p:t').',v'
        set nobackup
    endif
endfunction

aug NobackupWhenRCS
    au!
    au BufWritePre * :call DisableBackupIfInRCS(expand('<afile>'))
    au BufWritePost * :set backup
aug END

You can further tailor this based on the filetype. This also assumes you
having 'backup' on is the default, so BufWritePost unconditionally turns
it on.

--
HTH,
Hari


               
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: no backup of RCS files

Michael Weiser
On Thu, Jun 23, 2005 at 01:17:54PM -0700, Hari Krishna Dara wrote:

> > Is there some experienced vimrc hacker here who could start me off?

> The 'backup' option that controls this behavior is global, so you can't
> really make this check early and change the behavior. But onething you
> can probably do is to "tinker" with it just before writing the file,
> when the BufWritePre autocommand is generated. I don't know if this will
> work, and it might not actually work as expected if you write multiple
> files at the same time (depending on how Vim generates the
> BufWritePre/BufWritePost autocommand pairs). Try the below and see if it
> works (untested):

> function! DisableBackupIfInRCS(bufName)
>     if (filereadable(bufName.',v') ||
>    \ filereadable(fnamemodify(bufName, ':p:h').'/RCS/'.
>    \ fnamemodify(bufName, ':p:t').',v'
> set nobackup
>     endif
> endfunction

> aug NobackupWhenRCS
>     au!
>     au BufWritePre * :call DisableBackupIfInRCS(expand('<afile>'))
>     au BufWritePost * :set backup
> aug END

> You can further tailor this based on the filetype. This also assumes you
> having 'backup' on is the default, so BufWritePost unconditionally turns
> it on.

Thanks very much. I tried it and after some minor syntax corrections it
works nicely. I'll just use it and see how it goes. My version now
looks like this:

if has("vms")
  set nobackup " do not keep a backup file, use versions instead
else
  set backup " keep a backup file

  function! DisableBackupIfInRCS(bufName)
    if (filereadable(a:bufName.',v') ||
      \ filereadable(fnamemodify(a:bufName, ':p:h').'/RCS/'.
      \ fnamemodify(a:bufName, ':p:t').',v'))
      set nobackup
    endif
  endfunction
               
  aug NobackupWhenRCS
    au!
    au BufWritePre * :call DisableBackupIfInRCS(expand('<afile>'))
    au BufWritePost * :set backup
  aug END
endif

Thanks again!
--
Michael
I hate forms!