Thursday, May 6, 2010

Re: au BufReadPost * if &readonly | set nomodifiable

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.

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.

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.

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.

Any idea, why?

Thanks for your time,

--Rudy

Ben Fritz wrote:
>
>
>
> On May 4, 11:43 pm, rudy_b <rudyke...@yahoo.com> wrote:
>> Hi,
>> I have included the autocmd (listed below) in my .vimrc file.
>>  au BufReadPost * if &readonly | set nomodifiable
>>
>> The intention is to not let gvim even modify the read only files
>
> By the way, the reason I use this behavior, is that I use a version-
> control system at work that requires a lock of a file before making
> any changes. Without the lock, the file shows as readonly. Before I
> added the autocmd I gave (not the broken one above!), I would often
> make changes, fail to notice the warning that I was modifying a
> readonly file, and go to :w, which would always fail. :w! doesn't even
> work, since I don't have a lock. Acquiring the lock makes Vim thinks
> the file has changed (and indeed, since I don't have a lock, it may
> have changed in truth), so I found it best just to always set
> nomodifiable until I have the lock.
>
> --
> 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
>
>

--
View this message in context: http://old.nabble.com/au-BufReadPost-*-if--readonly-%7C-set-nomodifiable-tp28456618p28477764.html
Sent from the Vim - General mailing list archive at Nabble.com.

--
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: