ZyX_I committed 72645a9

@aurum/record: Forbid launching two records at the same time in one vim instance
Make AuRecord use aurum://edit to edit buffers, thus not touching
possibly already opened ones. Fixes #16 (no need to unmap
anymore), fixes #15 (no need to reload as well)
The above also fixes ref #14, but only if buffer opened on the
right (likely aurum://file) also got bufhidden=wipe

Comments (0)

Files changed (4)


     let r.hasbuf=1
     return r
+"▶2 rrf.edit : same as copy
+let s:rrf.edit=s:rrf.copy
 "▶2 rrf.status : bvar → (repo, rev), . → (file)
 function s:rrf.status(bvar, opts, act, failmsg)
     let r={}


     if a:force
         let kwargs.force=1
-    "▶2 XXX HACK: use s:prevrevhex to checkout a branch using :AuUpdate
+    "▶2 XXX (hacks): Avoid “detached HEAD” state if possible
     if a:rev=~#'\v^[0-9a-z]{40}$'
         if has_key(s:prevrevhex, a:repo.path) &&
                     \a:rev is# s:prevrevhex[a:repo.path][1] &&


+"▶1 edit
+function s:F.edit(rw, file)
+    if a:rw>=0
+        call s:F.copy(a:rw, a:file)
+        if !a:rw
+            setlocal buftype=acwrite nomodified modifiable noreadonly
+            let s:_r.bufvars[bufnr('%')]={'file': a:file, 'command': 'edit'}
+        endif
+    elseif a:rw==-1
+        let lines=getline(1, '$')
+        if &binary
+            if &endofline
+                let lines+=['']
+            endif
+        else
+            let lines+=['']
+            if &fileformat is# 'dos'
+                call map(lines, 'v:val."\n"')
+            elseif &fileformat is# 'mac'
+                let lines=[join(lines, "\r")]
+            endif
+        endif
+        call writefile(lines, a:file, 'b')
+        setlocal nomodified
+    endif
 "▶1 repotuplesplit :: str, UInt → (repo, String, ...)
 function s:F.repotuplesplit(str, num)
     let tail=a:str
     let tail=amatch[len('aurum://'):]
     let command=tolower(matchstr(tail, '\v^\w+'))
     let tail=tail[len(command)+1:]
-    if command is# 'copy' && a:rw>=0
+    if command is# 'copy' && (a:rw==0 || a:rw==1)
         return s:F.copy(a:rw, tail)
+    elseif command is# 'edit' && abs(a:rw)<=1
+        return s:F.edit(a:rw, tail)
     call s:F.checkcmd(command)
     "▶2 Launch bvar.write if applicable


             \               'filter': '(if type "" earg _  range 0 inf)'},
 let s:_messages={
+            \  'recex': 'There is already one AuRecord tab active '.
+            \           '(found tab with t:aurecid set to "AuRecordTab")',
             \ 'bkpmis': 'Backup file %s not found',
             \'delfail': 'Failed to remove file %s',
             \'renfail': 'Failed to move file %s to %s',
 " TODO investigate why closing record tab is causing next character consumption
 "      under wine
 function s:recfunc.function(opts, ...)
+    if !empty(filter(range(1, tabpagenr('$')),
+                \    'gettabvar(v:val, "aurecid") is# "AuRecordTab"'))
+        call s:_f.throw('recex')
+    endif
     let files=copy(a:000)
     if !empty(files) && a:opts.repo is# ':'
         let repo=s:_r.repo.get(s:_r.os.path.dirname(files[0]))
     let bvar.getwnrs=s:F.getwnrs
     let bvar.recrunmap=s:F.runstatmap
     let bvar.write=s:F.write
+    let bvar.savedundolevels=&undolevels
     if !bvar.startundo
-        setlocal undolevels=-1
+        setglobal undolevels=-1
     setlocal noreadonly buftype=acwrite
     if empty(bvar.chars)
     if a:bvar.startundo
         let a:bvar.undolevels=&undolevels
         let a:bvar.startundo=s:F.curundo()
-        setlocal undolevels=-1
+        setglobal undolevels=-1
 "▶1 supdate
         let a:bvar.prevct=b:changedtick
         if a:bvar.reset
             if has_key(a:bvar, 'undolevels')
-                let &l:undolevels=a:bvar.undolevels
+                let &g:undolevels=a:bvar.undolevels
                 unlet a:bvar.undolevels
             let a:bvar.reset=0
 "▶1 unload
 function s:F.unload(bvar)
     let sbvar=get(a:bvar, 'sbvar', a:bvar)
+    let &g:undolevels=sbvar.savedundolevels
     if bufexists(sbvar.bufnr)
         call setbufvar(sbvar.bufnr, '&modified', 0)
 "▶1 edit
 function s:F.edit(bvar, fname, ro)
     if type(a:fname)==type('')
-        let existed=bufexists(a:fname)
-        execute 'silent edit' fnameescape(a:fname)
+        " XXX Do not handle existance of aurum://edit and aurum://copy buffers: 
+        " they are only used by AuRecord and recfunc forbids to launch new 
+        " record if there is already one active
+        let existed=0
+        execute 'silent edit!' fnameescape(a:fname)
         let existed=call(, ['silent edit']+a:fname, {})
             call s:F.reset(bvar)
             setlocal nomodifiable
             execute lwnr.'wincmd w'
-            call s:F.edit(bvar, fullpath, 0)
+            call s:F.edit(bvar, 'aurum://edit:'.fullpath, 0)
             if ntype is# 'm' || (modified && ntype is# 'a')
                 if !modified
                     let fcontents=bvar.repo.functions.readfile(