Commits

ZyX_I committed af47ac9

@aurum/annotate: Moved scrollbind/cursorbind/wrap setting to setannbuf
Made it restore old values of scrollbind/cursorbind/wrap
Made setannbuf only check for adjacent windows (winnr±1)
Fixes #31

Comments (0)

Files changed (5)

          respectively. Same for |aurum://status| “rev1” and “rev2” options.
 @aurum/commit:
     1.0: Added fifth argument to _r.commit.commit()
+@aurum/annotate:
+    1.0: Removed one argument to _r.annotate.setannbuf()
 
 vim: ft=help:tw=78

ftplugin/aurumannotate.vim

 execute frawor#Setup('0.0', {'@aurum/repo': '3.0',
             \             '@aurum/bufvars': '0.0',
             \             '@aurum/vimdiff': '0.2',
-            \            '@aurum/annotate': '0.0',
+            \            '@aurum/annotate': '1.0',
             \                '@aurum/edit': '1.2',
             \                 '@/mappings': '0.0',
             \                       '@/os': '0.0',})
 "      wine
 function s:F.runmap(action, ...)
     "▶2 Initialize variables
-    let buf=bufnr('%')
-    let bvar=s:_r.bufvars[buf]
+    let bvar=s:_r.bufvars[bufnr('%')]
     let hex=bvar.revisions[line('.')-1]
     let file=bvar.files[line('.')-1]
     let hasannbuf=has_key(bvar, 'annbuf')
     if hasannbuf
-        let abwnr=bufwinnr(bvar.annbuf)
-        let hasannbuf=(abwnr!=-1)
+        let annwin=bufwinnr(bvar.annbuf)
+        let hasannbuf=(annwin!=-1)
     endif
     "▶2 Various *diff actions
     if a:action[-4:] is# 'diff'
         endif
         let rev2=hex
         if hasannbuf
-            wincmd c
-            execute abwnr.'wincmd w'
-            setlocal noscrollbind
+            close
+            execute annwin.'wincmd w'
         endif
         if a:action[-7:-5] is# 'vim'
             if a:0 && a:1
             let lnr=bvar.linenumbers[line('.')-1]
             if lnr is 0
                 let ablnr=line('.')
-                execute abwnr.'wincmd w'
+                execute annwin.'wincmd w'
                 let line=getline(ablnr)
                 unlet lnr
                 wincmd p
             if exists('lnr')
                 execute lnr
             endif
-            setlocal scrollbind cursorbind
-            let abuf=bufnr('%')
-            let newbvar=s:_r.bufvars[abuf]
-            execute abwnr.'wincmd w'
+            let newbvar=s:_r.bufvars[bufnr('%')]
+            execute annwin.'wincmd w'
         endif
         let existed=s:_r.mrun('silent edit', 'file', bvar.repo, hex, file)
+        let annbuf=bufnr('%')
         if exists('lnr')
             execute lnr
         elseif exists('line')
         if hasannbuf
             if exists('lnr')
                 call s:_r.annotate.foldopen()
-                setlocal scrollbind cursorbind nowrap
             endif
-            call s:_r.annotate.setannbuf(newbvar, abuf, bufnr('%'))
+            wincmd p
+            call s:_r.annotate.setannbuf(newbvar, annbuf)
         endif
     "▶2 `update' action
     elseif a:action is# 'update'
             call s:_f.throw('no'.a:action[:3], hex)
         endif
         call s:_r.run('silent edit', 'annotate', bvar.repo, rev, bvar.file)
-        setlocal scrollbind
-        let abuf=bufnr('%')
-        let newbvar=s:_r.bufvars[abuf]
+        let newbvar=s:_r.bufvars[bufnr('%')]
         if hasannbuf
-            execute abwnr.'wincmd w'
-            setlocal noscrollbind
+            execute annwin.'wincmd w'
         else
             vsplit
             wincmd p
             wincmd p
         endif
         let existed=s:_r.mrun('silent edit', 'file', bvar.repo, rev, bvar.file)
-        setlocal scrollbind
-        call s:_r.annotate.setannbuf(newbvar, abuf, bufnr('%'))
+        let annbuf=bufnr('%')
+        wincmd p
+        call s:_r.annotate.setannbuf(newbvar, annbuf)
     endif
     "▲2
     if exists('existed') && !existed

plugin/aurum/annotate.vim

 "▶1 
 scriptencoding utf-8
 if !exists('s:_pluginloaded')
-    execute frawor#Setup('0.0', {'@/table': '0.1',
+    execute frawor#Setup('1.0', {'@/table': '0.1',
                 \        '@aurum/cmdutils': '0.0',
                 \         '@aurum/bufvars': '0.0',
                 \            '@aurum/edit': '1.0',
     endif
     return self[a:cs.hex]
 endfunction
+"▶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
+            for [o, v] in items(a:bvar.saved)
+                call setwinvar(annwin, '&'.o, v)
+            endfor
+        endif
+    endif
+endfunction
 "▶1 setup
 "▶2 getcs :: rev + self → cs + self
 function s:F.getcs(rev)
     let bvar.files=map(copy(ann), 'v:val[0]')
     let bvar.linenumbers=map(copy(ann), 'v:val[2]')
     let bvar.revisions=map(copy(css), 'v:val.hex')
+    let bvar.bwfunc=s:F.unload
     let lines=map(copy(css), 'call(s:F.formatann, [a:repo, v:val, v:key, '.
                 \                                  nl.'],d)')
     if a:read
     endif
     return bvar
 endfunction
+"▶1 findwin :: buf → win
+function s:F.findwin(buf)
+    let win=winnr()
+    if win>1 && winbufnr(win-1)==a:buf
+        return win-1
+    elseif winbufnr(win+1)==a:buf
+        return win+1
+    else
+        return -1
+    endif
+endfunction
 "▶1 setannbuf
-function s:F.setannbuf(bvar, buf, annbuf)
+function s:F.setannbuf(bvar, annbuf)
     let a:bvar.annbuf=a:annbuf
-    if bufwinnr(a:annbuf)!=-1
-        execute bufwinnr(a:annbuf).'wincmd w'
-        augroup AuAnnotateBW
-            execute 'autocmd BufWipeOut,BufHidden <buffer='.a:annbuf.'> '.
-                        \':if bufexists('.a:buf.') | '.
-                        \   'call feedkeys("\<C-\>\<C-n>'.
-                        \                 ':silent! bw '.a:buf.'\n") | '.
-                        \ 'endif'
-        augroup END
+    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
+    augroup AuAnnotateBW
+        execute 'autocmd BufWipeOut,BufHidden <buffer='.a:annbuf.'> '.
+                    \':if bufexists('.buf.') | '.
+                    \   'call feedkeys("\<C-\>\<C-n>'.
+                    \                 ':silent! bw '.buf.'\n") | '.
+                    \ 'endif'
+    augroup END
 endfunction
 let s:_augroups+=['AuAnnotateBW']
 "▶1 foldopen
             setlocal bufhidden=wipe
         endif
     endif
+    let annwin=winnr()
     call s:F.foldopen()
-    setlocal scrollbind cursorbind nowrap
     let lnr=line('.')
     let anwidth=min([42, winwidth(0)/2-1])
     call s:_r.run('silent leftabove '.anwidth.'vsplit', 'annotate', repo,
                 \ rev, file)
     execute lnr
-    setlocal scrollbind cursorbind
     setlocal bufhidden=wipe
-    let buf=bufnr('%')
-    call s:F.setannbuf(s:_r.bufvars[buf], buf, annbuf)
+    call s:F.setannbuf(s:_r.bufvars[bufnr('%')], annbuf)
 endfunction
 let s:_augroups+=['AuAnnotateBW']
 let s:annfunc['@FWC']=['-onlystrings'.

test/cmd-annotate.in

 :W{{{2 buffer
 :Run! AuAnnotate | wincmd p
 :W{{{2
+:call WriteFile('sb: '.&scrollbind.', cb: '.&cursorbind.', w:'.&wrap)
 :call WriteFile(bufname('%'), 'w$: '.winnr('$').', w0: '.winnr())
 :bwipeout!
+:call WriteFile('sb: '.&scrollbind.', cb: '.&cursorbind.', w:'.&wrap)
 :bwipeout!
 :W{{{1 AuAnnotate file
 :W{{{2 buffer

Binary file modified.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.