logging of edited files

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

logging of edited files

ehannes
Vimmers,

Is there a way to (automaticaly) make a logging of the files edited?

Thanks,
Hans Scholte

Reply | Threaded
Open this post in threaded view
|

Re: logging of edited files

A.J.Mechelynck
Scholte, J.C.M. wrote:
> Vimmers,
>
> Is there a way to (automaticaly) make a logging of the files edited?
>
> Thanks,
> Hans Scholte


I believe that it is possible to log all messages to a file, _including_
messages about files read or written, see ":help :redir"; however, you
would thereby be depriving yourself of the usefulness of the ":redir"
command for other purposes (for instance, redirecting the output of
":version" to the clipboard in order to paste it into an email). Also,
some scripts use ":redir" internally, and you would have to avoid them.

Another possibility would be to cabbrev e -- or maybe to intercept the
BufReadPost, BufNewFile, etc. events -- in order to log the editfile
(and possibly the date, time, etc.) at the end of some logfile: either

        :cabbrev e Edit
or
        :autocmd BufReadPost,BufNewFile * call LogEditFile()

"The details of the solution are left as an exercise to the reader." ;-)


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: logging of edited files

Tim Chase-2
In reply to this post by ehannes
> Is there a way to (automaticaly) make a logging of the files
> edited?

My first thought would be putting the following three lines in my
vimrc file

augroup filelogging
au filelogging BufRead * redir >> /path/to/filelog.txt | echo
expand("%") | redir END
augroup END

This doesn't capture new (":new" or ":enew") buffers, or reading
with ":r" but it should do for regular file editing.  It also has
an annoying side effect that you have to press Enter to dismiss
the "Hit ENTER or type command to continue" message.

One might be able to jockey/tweak the items in the 'shortmess'
setting to eliminate the "Hit ENTER" prompt, but when you start
adding that much code, I'd create a function to simply log the
current file name, and then have my autocmd call that function.

Just a few thoughts.

-tim





Reply | Threaded
Open this post in threaded view
|

RE: logging of edited files

ehannes
In reply to this post by ehannes
Vimmers,

Thank you for your help. I came up with

<snippet>
autocmd BufWritePost * call LogEditFile()

fun! LogEditFile()
   silent! exe ':!echo 'expand("%:p")' >> c:\tmp\logging.txt'
endfunction
</snippet>


When I used BufWrite the function started for 4, 5 times. Does anybody know why?

Thanks, Hans



-----Oorspronkelijk bericht-----
Van: Keith W. Roberts [mailto:[hidden email]]
Verzonden: maandag 7 november 2005 19:59
Aan: Scholte, J.C.M.; [hidden email]
Onderwerp: RE: logging of edited files


----Original Message----
From: Scholte, J.C.M. [mailto:[hidden email]]
Sent: Monday, November 07, 2005 7:36 AM
To: [hidden email]
Subject: logging of edited files

> Vimmers,
>
> Is there a way to (automaticaly) make a logging of the files edited?
>
> Thanks,
> Hans Scholte

Tony and Tim gave you the how ... but I'd use either the BufWrite or
BufWritePost event instead.  I don't think you care who *looks* at a file,
only who *writes* to it.

BTW, this would also catch things like:
        :write somefilename
which I don't think triggers the BufRead event ( though I could be wrong :).

-Keith