netrw and timestamp.vim

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

netrw and timestamp.vim

Lars Wilke
Hi,

i am using timestamp.vim to place Last changed marks inside some
of my scripts. Now if i use netrw (which is really nice:) i have
the problem that the autocommand BufWrite seems not to get executed
anymore. The timestamp isn't updated automatically.

If i execute an :do BufWrite then everything works as expected.

So my question is if anybody knows if this is a bug in timestamp.vim
or in the netrw plugin. I am asking because for me both look ok :)
But my vim scrpting experience is obviously quite limited as something
is wrong here ...

thanks
   --lars
Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

A.J.Mechelynck
----- Original Message -----
From: "Lars Wilke" <[hidden email]>
To: <[hidden email]>
Sent: Wednesday, September 21, 2005 4:56 AM
Subject: netrw and timestamp.vim


> Hi,
>
> i am using timestamp.vim to place Last changed marks inside some
> of my scripts. Now if i use netrw (which is really nice:) i have
> the problem that the autocommand BufWrite seems not to get executed
> anymore. The timestamp isn't updated automatically.
>
> If i execute an :do BufWrite then everything works as expected.
>
> So my question is if anybody knows if this is a bug in timestamp.vim
> or in the netrw plugin. I am asking because for me both look ok :)
> But my vim scrpting experience is obviously quite limited as something
> is wrong here ...
>
> thanks
>   --lars

The BufWrite autocommand event ought to be triggered anyway; but for some
filetypes it may (IIUC) be bypassed if there is a BufWriteCmd autocommand
(see ":help Cmd-event"). Try the following:

    :verbose autocmd BufWrite
    :verbose autocmd BufWriteCmd

(:verbose changes nothing in Vim 6.3, but in recent snapshots of Vim 7.00aa
it does.)

I have no autocommands defined for BufWrite; for BufWriteCmd the standard
plugins define them in groups named Netrw, tar and zip.


Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

A.J.Mechelynck
I'm forwarding this to the list since I'm not a specialist of the plugins in
question.

Next time, please use "Reply to All" rather than "Reply to Sender", so
everyone on the list can try and answer you.

Best regards,
Tony.
----- Original Message -----
From: "Lars Wilke" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Sent: Friday, September 23, 2005 3:07 AM
Subject: Re: netrw and timestamp.vim


> Hi,
>
> first thank you very much for the quick answer.
> So lets see..
>
> * Tony Mechelynck wrote:
>> From: "Lars Wilke" <[hidden email]>
>> >
>> >i am using timestamp.vim to place Last changed marks inside some
>> >of my scripts. Now if i use netrw (which is really nice:) i have
>> >the problem that the autocommand BufWrite seems not to get executed
>> >anymore. The timestamp isn't updated automatically.
>> >
>> >If i execute an :do BufWrite then everything works as expected.
>> >
>> >So my question is if anybody knows if this is a bug in timestamp.vim
>> >or in the netrw plugin. I am asking because for me both look ok :)
>> >But my vim scrpting experience is obviously quite limited as something
>> >is wrong here ...
>>
>> The BufWrite autocommand event ought to be triggered anyway; but for some
>> filetypes it may (IIUC) be bypassed if there is a BufWriteCmd autocommand
>> (see ":help Cmd-event"). Try the following:
>
> Hm, true you take over control of writting the file. I looked at the
> NetWrite() function in the netrw script. Basically it saves the file
> to a temporary one and then triggers the transfer to the remote host
> depending on the used protocol.
>
> But with executing :w the BufWrite autocammands should be triggerd,
> right? Ah, i see, on line 608 in the script there is stated that only
> a portion of the file gets saved to the tempfile. It seems this is the
> reason for not triggering the BufWrite autocommand as
> the manual for BufWrite says that it gets triggered before writting
> the *whole* buffer to a file.
>
> So if i am not mistaken the solution would be that timestamp.vim
> would also register with the FileWritePre autocommand, right?
>
> Hm, i have to admit i thought i understood the following line of vimL.
> But i am irritated by the fact that you only write out a portion of the
> file. How does this portion get merged with the rest of file?
> Especially on the remote host.
>
> " write (selected portion of) file to temporary
>  silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
>
>>    :verbose autocmd BufWrite
>>    :verbose autocmd BufWriteCmd
>
> I am using vim 6.3.86 (standard debian package). Which ships with netrw
> version 44.
>
> The relevant output for the first command is:
>
> TimeStamp  BufWrite
>    *         :call s:timestamp()
>
> and the second
>
> Network  BufWriteCmd
>    ftp://*   exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>    rcp://*   exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>    scp://*   exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>    dav://*   exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>    rsync://* exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>    sftp://*  exe "Nwrite "  .expand("<afile>")|call <SID>NetRestorePosn()
>
> Both look ok to me.
>
>
> Thanks a lot
>
>   --lars
>
>


Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

Charles E Campbell Jr
From: "Lars Wilke" <[hidden email]>
 > Hm, i have to admit i thought i understood the following line of vimL.
 > But i am irritated by the fact that you only write out a portion of the
 > file. How does this portion get merged with the rest of file?
 > Especially on the remote host.
 >
 > " write (selected portion of) file to temporary
 >  silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile


So you would prohibit people using netrw from writing a selected portion
of a file?

    ie.  :[range]w -url-

To what purpose?

Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

Lars Wilke
* Charles E. Campbell, Jr. wrote:

> From: "Lars Wilke" <[hidden email]>
> > Hm, i have to admit i thought i understood the following line of vimL.
> > But i am irritated by the fact that you only write out a portion of the
> > file. How does this portion get merged with the rest of file?
> > Especially on the remote host.
> >
> > " write (selected portion of) file to temporary
> >  silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
>
> So you would prohibit people using netrw from writing a selected portion
> of a file?

???

I would nothing, the line above is cut'n paste from the netrw script.

I just wondered how the mechanism works, as i understood the Nwrite()
function it saves a range to a tempfile and the triggers the transfer
to the remote machine. But how is this fragment merged with the file on
the remote machine. Yeah, i guess i do not really understand the Nwrite
function but i stated something like that before :)

>    ie.  :[range]w -url-
>
> To what purpose?

Sorry, i am not sure i understand your question.
The reason for me asking at all is only that i want to update a timestamp
in a file which in turn is edited via netrw. The update of the timestamp
didn't happen. So i wondered why and if this is a bug somewhere or if
timestamp.vim could be adapted to cope with the usage of netrw.
So i figured it could be because of the usage of the BufWrite autocommand
in the timestamp.vim script.

Through the comment above the vimL line i noticed the difference between
the BufWrite and FileWritePre autocommand. My final question was then,
if it would make sense to register with the FileWritePre hook, too.
Though i am not sure if that would change anything if only a range got
saved and send to a remote machine. As the range might not include
the line which contains the 'Last changed:' stamp.

I am sorry if i didn't make myself clear enough. English is not my
mother tongue...anyway thank you very much for your help.

regards
   --lars
Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

A.J.Mechelynck
----- Original Message -----
From: "Lars Wilke" <[hidden email]>
To: "Charles E. Campbell, Jr." <[hidden email]>
Cc: <[hidden email]>
Sent: Friday, September 23, 2005 9:52 PM
Subject: Re: netrw and timestamp.vim


>* Charles E. Campbell, Jr. wrote:
>> From: "Lars Wilke" <[hidden email]>
>> > Hm, i have to admit i thought i understood the following line of vimL.
>> > But i am irritated by the fact that you only write out a portion of the
>> > file. How does this portion get merged with the rest of file?
>> > Especially on the remote host.
>> >
>> > " write (selected portion of) file to temporary
>> >  silent exe a:firstline."," . a:lastline . "w! ".v:cmdarg." ".tmpfile
>>
>> So you would prohibit people using netrw from writing a selected portion
>> of a file?
>
> ???
>
> I would nothing, the line above is cut'n paste from the netrw script.
>
> I just wondered how the mechanism works, as i understood the Nwrite()
> function it saves a range to a tempfile and the triggers the transfer
> to the remote machine. But how is this fragment merged with the file on
> the remote machine. Yeah, i guess i do not really understand the Nwrite
> function but i stated something like that before :)
>
>>    ie.  :[range]w -url-
>>
>> To what purpose?
>
> Sorry, i am not sure i understand your question.
> The reason for me asking at all is only that i want to update a timestamp
> in a file which in turn is edited via netrw. The update of the timestamp
> didn't happen. So i wondered why and if this is a bug somewhere or if
> timestamp.vim could be adapted to cope with the usage of netrw.
> So i figured it could be because of the usage of the BufWrite autocommand
> in the timestamp.vim script.
>
> Through the comment above the vimL line i noticed the difference between
> the BufWrite and FileWritePre autocommand. My final question was then,
> if it would make sense to register with the FileWritePre hook, too.
> Though i am not sure if that would change anything if only a range got
> saved and send to a remote machine. As the range might not include
> the line which contains the 'Last changed:' stamp.
>
> I am sorry if i didn't make myself clear enough. English is not my
> mother tongue...anyway thank you very much for your help.
>
> regards
>   --lars

IIUC, the concerned part of the Netrw plugin takes care of handling
":[range]w[rite][!] {filename}" when the filename is a remote URL, i.e.,
write the indicated range (default: the whole file currently being edited)
to the indicated URL. If the output file already exists, then the write will
fail unless either the command had a bang (:w! rather than just :w) or
'writeany' was on. The "current file" is unchanged in Vim but the write
happens to some _other_ file. There is _no_ merge: either the output file is
created, it is overwritten, or the write fails.

Best regards,
Tony.


Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

Lars Wilke
* Tony Mechelynck wrote:

> [timestamp.vim not function while editing via netrw]
>
> IIUC, the concerned part of the Netrw plugin takes care of handling
> ":[range]w[rite][!] {filename}" when the filename is a remote URL, i.e.,
> write the indicated range (default: the whole file currently being edited)
> to the indicated URL. If the output file already exists, then the write
> will fail unless either the command had a bang (:w! rather than just :w) or
> 'writeany' was on. The "current file" is unchanged in Vim but the write
> happens to some _other_ file. There is _no_ merge: either the output file
> is created, it is overwritten, or the write fails.

Oh Man, then i was dead wrong :(
Hm, then there is no way to what i want at least not that easily.

Oh well, thanks a lot for you guys helping me out.

kind regards

   --lars
Reply | Threaded
Open this post in threaded view
|

Re: netrw and timestamp.vim

A.J.Mechelynck
----- Original Message -----
From: "Lars Wilke" <[hidden email]>
To: "Tony Mechelynck" <[hidden email]>
Cc: "Charles E. Campbell, Jr." <[hidden email]>; <[hidden email]>
Sent: Sunday, September 25, 2005 3:59 AM
Subject: Re: netrw and timestamp.vim


>* Tony Mechelynck wrote:
>> [timestamp.vim not function while editing via netrw]
>>
>> IIUC, the concerned part of the Netrw plugin takes care of handling
>> ":[range]w[rite][!] {filename}" when the filename is a remote URL, i.e.,
>> write the indicated range (default: the whole file currently being
>> edited)
>> to the indicated URL. If the output file already exists, then the write
>> will fail unless either the command had a bang (:w! rather than just :w)
>> or
>> 'writeany' was on. The "current file" is unchanged in Vim but the write
>> happens to some _other_ file. There is _no_ merge: either the output file
>> is created, it is overwritten, or the write fails.
>
> Oh Man, then i was dead wrong :(
> Hm, then there is no way to what i want at least not that easily.
>
> Oh well, thanks a lot for you guys helping me out.
>
> kind regards
>
>   --lars

Maybe use a different command? IIUC, all reads and writes to remote URLs (or
directories whether local or remote) are handled by netrw. For remote files,
netrw mimics as closely as possible what vim does on local files without the
need for a plugin. You might want to use :saveas (which doesn't take a range
and does change the current editfile) or even some other command?


Best regards,
Tony.