changeset 3:14a272d72b0a

Only open file for edit if it's readonly just before writing to it.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 24 Sep 2020 22:50:09 -0700
parents 74b2ef146e82
children 52e1502091e0
files autoload/p44vim.vim
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/p44vim.vim	Thu Sep 24 22:49:05 2020 -0700
+++ b/autoload/p44vim.vim	Thu Sep 24 22:50:09 2020 -0700
@@ -48,8 +48,10 @@
 
 let s:ignore_next_w12 = 0
 
-function! s:auto_edit_buffer() abort
-    call p44vim#p4edit()
+function! s:maybe_auto_edit_buffer() abort
+    if &readonly
+        call p44vim#p4edit()
+    endif
 endfunction
 
 function! s:maybe_ignore_w12() abort
@@ -72,7 +74,7 @@
 
     augroup p44v_auto
         autocmd!
-        autocmd FileChangedRO * call <SID>auto_edit_buffer()
+        autocmd BufWritePre * call <SID>maybe_auto_edit_buffer()
         autocmd FileChangedShell * call <SID>maybe_ignore_w12()
     augroup END
 endfunction