Tuesday, June 29, 2010

Re: au BufReadPost * if &readonly | set nomodifiable

On 06/05/10 22:26, Ben Fritz wrote:
>
>
> On May 6, 1:22 pm, rudy_b<rudyke...@yahoo.com> wrote:
>> Hey guys thanks for your replies.
>> Still Doesn't work.
>> My gvim version is 7.2.
>> Aince at work I am using a revision control too, that is why having this
>> thing fixed is very helpful for me.
>> I almost shrunk my .vimrc down to this:
>>
>> ----------------------------------------
>> :set nocp
>> :set ru
>>
>> " au BufReadPost * if&readonly | set nomodifiable | endif
>> autocmd BufRead,BufWinEnter * if&ft!='qf' | let&l:modifiable =
>> (&readonly ? 0 : 1) | endif
>> ---------------
>> And I used the last two lines interchangably.
>> But still not good.
>>
>> But, I figured something intresting.
>> I think what is going on (at least from my observation) is that this
>> specific setting is buffer related setting and not a file related. I tried
>> using split function with the name of the second file next to it:
>> :split read_only_file.txt
>> and this worked.
>> BUT, if I do
>> :split .
>> (which is what I usually do) that opens up the directory, where I can select
>> my file, then it is hosed up.
>>
>
> Wow, HEY! I also see the autocmd not working, if I open the file from
> the netrw directory exploration window. In fact, the readonly option
> does not even get set!
>
> If I then use :e in the new buffer (with no arguments) to reload the
> buffer, the readonly and modifiable options get set as desired.
>
> I tried with the .vimrc you sent. I did not try disabling all plugins
> besides netrw, but I don't use very many of them.
>
> The autocmd works fine using splits with your .vimrc and no plugins at
> all. This means the directory listing won't work.
>
>> Then I thought that okay at least I know if I put the name of the file next
>> to that split command, then it will work.
>> BUT, another wired thing is that if I do the same thing on a writable file:
>> :split writable_file.txt
>> and when I try to modify it, it DOENS'T work. meaning that I cannot write
>> into that file.
>>
>
> This, I cannot reproduce.
>
> I opened writeable_file, modifiable was set.
> I :sp nonwriteable_file, nomodifiable was set.
> I :sp writeable_file2, modifiable was set.
>
> This works even when the writeable files do not exist for me.
>
> All this was done with no plugins, and the .vimrc you supplied at the
> top of this post.
>
>> conclusion:
>> this is what is going on:
>>
>> If I use (e: new_file) or (split: new_file) or (vsplit: new_file), then:
>> Regardless of the writability/readability privileges, I CANNOT modify the
>> file. In other words, "nonmodifiable" is set.
>
> Did you make sure to close down Vim, and launch a NEW vim, with the
> new autocmd between loads?
>
>>
>> If I use (e: .) or (split: .) or (vsplit: .), then:
>> I can select my other file, but again, regardless of the
>> writability/readability privileges, I CAN modify the files. In other words,
>> "modifiable" is set.
>>
>
> I can duplicate this. In addition, noreadonly is set regardless of the
> file properties.
>
>
> I am using Vim 7.2.411 on Windows XP.
>
> My netrw plugin starts with:
>
> " netrwPlugin.vim: Handles file transfer and remote directory listing
> across a network
> " PLUGIN SECTION
> " Date: Aug 10, 2008
> " Maintainer: Charles E Campbell, Jr<NdrOchip@ScampbellPfamily.AbizM-
> NOSPAM>
> " GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
>
>
> As a workaround, immediately after loading a file from NetRW, do an :e
> with no arguments to reload the file and set the appropriate readonly/
> modifiable options based on file attributes. I do not know why this is
> not currently working.
>

Hm. Just a wild thought (untested): try the following (which assumes
'nocompatible'):


if has('autocmd')
au VimEnter * augroup nomodif
au VimEnter * au BufReadPost,BufNewFile * if &buftype == ""
\ | let &l:ma = &l:ro | endif
au VimEnter * augroup END
endif


Then restart Vim (every time you make changes to your vimrc, and after
saving your changes) in order to test it.

If it doesn't work: while editing a file where 'modifiable' is not what
you expect:

:verbose setlocal ma? ro? bt?


Best regards,
Tony.
--
A disciple of another sect once came to Drescher as he was
eating his morning meal. "I would like to give you this personality
test", said the outsider, "because I want you to be happy."
Drescher took the paper that was offered him and put it into
the toaster -- "I wish the toaster to be happy too".

--
You received this message from the "vim_use" 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

No comments:

Post a Comment