Commits

ZyX_I committed 40de853

Make AuAnnotate select proper window

Makes difference in case there is more then one window showing the same buffer.
Fixes #94

Comments (0)

Files changed (5)

autoload/aurum/annotate.vim

 "▶1 
 scriptencoding utf-8
-execute frawor#Setup('1.0', {'@%aurum/cmdutils': '4.3',
+execute frawor#Setup('2.0', {'@%aurum/cmdutils': '4.3',
             \                 '@%aurum/bufvars': '0.0',
             \                    '@%aurum/edit': '1.4',
             \                     '@/functions': '0.1',
 "▶1 unload
 function s:F.unload(bvar)
     if has_key(a:bvar, 'annbuf') && bufexists(a:bvar.annbuf)
-        let annwin=s:F.findwin(a:bvar.annbuf)
-        if annwin==-1
-            let annwin=bufwinnr(a:bvar.annbuf)
-        endif
-        if annwin!=-1
+        let annwin=s:F.findwin(a:bvar.winid)
+        if annwin
             for [o, v] in items(a:bvar.saved)
                 call setwinvar(annwin, '&'.o, v)
             endfor
     endif
     return bvar
 endfunction
-"▶1 findwin :: buf → win
-function s:F.findwin(buf)
+"▶1 findwin :: winid → win
+function s:F.findwin(winid)
     let win=winnr()
-    if win>1 && winbufnr(win-1)==a:buf
+    if win>1 && getwinvar(win-1, 'aurum_annonate_winid') is a:winid
         return win-1
-    elseif winbufnr(win+1)==a:buf
+    elseif getwinvar(win+1, 'aurum_annonate_winid') is a:winid
         return win+1
+    elseif getwinvar(win, 'aurum_annonate_winid') is a:winid
+        return win
     else
-        return -1
+        return 0
     endif
 endfunction
 "▶1 setannbuf
-function s:F.setannbuf(bvar, annbuf)
+function s:F.setannbuf(bvar, annbuf, winid)
     let a:bvar.annbuf=a:annbuf
+    let a:bvar.winid=a:winid
+    setlocal scrollbind cursorbind nowrap
+    let buf=bufnr('%')
+    let annwin=s:F.findwin(a:winid)
+    if !annwin
+        return
+    endif
+    execute annwin.'wincmd w'
     let a:bvar.saved={}
     let a:bvar.saved.scrollbind = &scrollbind
     let a:bvar.saved.cursorbind = &cursorbind
     let a:bvar.saved.wrap       = &wrap
     setlocal scrollbind cursorbind nowrap
-    let buf=bufnr('%')
-    let annwin=s:F.findwin(a:annbuf)
-    if annwin==-1
-        return
-    endif
-    execute annwin.'wincmd w'
-    setlocal scrollbind cursorbind nowrap
     " XXX I was unable to make scrollbinded windows behave sensibly without the 
     "     following command. No matter what I tried, if initially buffer had any 
     "     offset from the top (line("w0")!=1), saved vertical offset of 
             \'}', 'filter']}
 let s:_aufunctions.comp=s:_r.cmdutils.gencompfunc(s:_aufunctions.cmd['@FWC'][0],
             \                                     [], s:_f.fwc.compile)
+let s:lastid=0
 function s:_aufunctions.cmd.function(opts)
     let [hasannbuf, repo, rev, file]=s:_r.cmdutils.getrrf(a:opts, 'noafile',
                 \                                         'annotate')
     let annwin=winnr()
     call s:F.foldopen()
     let lnr=line('.')
+    let winid=s:lastid
+    let s:lastid+=1
+    let w:aurum_annonate_winid=winid
     let anwidth=min([42, winwidth(0)/2-1])
     call s:_r.run('silent leftabove '.anwidth.'vsplit', 'annotate', repo,
                 \ rev, file)
     execute lnr
     setlocal bufhidden=wipe
-    call s:F.setannbuf(s:_r.bufvars[bufnr('%')], annbuf)
+    call s:F.setannbuf(s:_r.bufvars[bufnr('%')], annbuf, winid)
 endfunction
 let s:_augroups+=['AuAnnotateBW']
 "▶1 plstrgen
             \         'plstrgen': s:F.plstrgen,})
 "▶1 Post resource
 call s:_f.postresource('annotate', {'setannbuf': s:F.setannbuf,
-            \                        'foldopen': s:F.foldopen,})
+            \                        'foldopen': s:F.foldopen,
+            \                         'findwin': s:F.findwin,})
 "▶1
-call frawor#Lockvar(s:, '_r,_pluginloaded')
+call frawor#Lockvar(s:, '_r,lastid')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲
          a:opts.amend.
 @%aurum/annotate:
     1.0: Removed one argument to _r.annotate.setannbuf().
+    2.0: Add one argument to _r.annotate.setannbuf(): window ID; add 
+         _r.annotate.findwin().
 @%aurum/cmdutils:
     1.0: Removed cmdutils.prevbuf().
     2.0: Splitted it into @aurum/cmdutils and @aurum/computils.

ftplugin/aurumannotate.vim

 setlocal nomodeline
 execute frawor#Setup('0.0', {'@%aurum/bufvars': '0.0',
             \                '@%aurum/vimdiff': '1.1',
-            \               '@%aurum/annotate': '1.0',
+            \               '@%aurum/annotate': '2.0',
             \               '@%aurum/cmdutils': '4.0',
             \               '@%aurum/maputils': '0.1',
             \                   '@%aurum/edit': '1.2',
     let file=bvar.files[line('.')-1]
     let hasannbuf=has_key(bvar, 'annbuf')
     if hasannbuf
-        let annwin=bufwinnr(bvar.annbuf)
-        let hasannbuf=(annwin!=-1)
+        let annwin=s:_r.annotate.findwin(bvar.winid)
+        let hasannbuf=!!annwin
     endif
     "▶2 Various *diff actions
     if a:action[-4:] is# 'diff'
                 call s:_r.annotate.foldopen()
             endif
             wincmd p
-            call s:_r.annotate.setannbuf(newbvar, annbuf)
+            call s:_r.annotate.setannbuf(newbvar, annbuf, bvar.winid)
         endif
     "▶2 `update' action
     elseif a:action is# 'update'
         let existed=s:_r.mrun('silent edit', 'file', bvar.repo, rev, file)
         let annbuf=bufnr('%')
         wincmd p
-        call s:_r.annotate.setannbuf(newbvar, annbuf)
+        call s:_r.annotate.setannbuf(newbvar, annbuf, bvar.winid)
     endif
     "▲2
     if exists('existed') && !existed
 :W{{{1 AuAnnotate
 :silent edit `=g:curtest.'repo/chgrepo.zsh'`
 :W{{{2 buffer
+:call WriteFile('sb: '.&scrollbind.', cb: '.&cursorbind.', w:'.&wrap)
 :Run! AuAnnotate | wincmd p
 :W{{{2
 :call WriteFile('sb: '.&scrollbind.', cb: '.&cursorbind.', w:'.&wrap)
 :bwipeout!
 :
 :bwipeout!
+:W{{{1 Regression: annotate second buffer in a vertical split
+:silent edit `=g:curtest.'repo/chgrepo.zsh'`
+:silent vsplit
+:wincmd l
+:for w in range(1, winnr('$'))|call WriteFile(w.': sb: '.getwinvar(w, '&scrollbind').', cb: '.getwinvar(w, '&cursorbind').', w:'.getwinvar(w, '&wrap'))|endfor
+:R! AuAnnotate
+:WW
+:for w in range(1, winnr('$'))|call WriteFile(w.': sb: '.getwinvar(w, '&scrollbind').', cb: '.getwinvar(w, '&cursorbind').', w:'.getwinvar(w, '&wrap'))|endfor
+:wincmd p
+:WW
+:bwipeout!
+:WW
+:for w in range(1, winnr('$'))|call WriteFile(w.': sb: '.getwinvar(w, '&scrollbind').', cb: '.getwinvar(w, '&cursorbind').', w:'.getwinvar(w, '&wrap'))|endfor
+:
+:bwipeout!
 :source addmessages.vim

test/cmd-annotate.ok

Binary file modified.