Commits

ZyX_I committed 79190c0

Added some mappings to aurum://annotate, improved various diffs

  • Participants
  • Parent commits f4271c2

Comments (0)

Files changed (3)

File ftplugin/aurumannotate.vim

     let d={}
     call map(ann, 'call(s:F.formatann, [bvar.repo, v:val, v:key], d)')
     call setline('.', ann)
+    augroup AuAnnotateNoInsert
+        autocmd InsertEnter <buffer> :call feedkeys("\e", "n")
+    augroup END
 endfunction
+let s:_augroups+=['AuAnnotateNoInsert']
 let s:filetype=expand('<sfile>:t:r')
 call s:_f.augroup.add('AuAnnotate', [['FileType', s:filetype, 0, s:F.setup]])
 call s:F.setup()
+"▶1 getfile :: cs → path
+function s:F.getfile(cs)
+    let file=0
+    if spname=~#'\v^file\d+$'
+        let file=a:cs.files[+spname[4:]]
+    elseif !empty(a:cs.files)
+        if len(a:cs.files)==1
+            let file=a:cs.files[0]
+        else
+            let choice=inputlist(['Select file (0 to cancel):']+
+                        \               map(copy(a:cs.files),
+                        \                   '(v:key+1).". ".v:val'))
+            if choice
+                let file=a:cs.files[choice-1]
+            endif
+        endif
+    endif
+    return file
+endfunction
+"▶1 runmap
+function s:F.runmap(action, ...)
+    let buf=bufnr('%')
+    let bvar=s:_r.aurum.bufvars[buf]
+    let rev=+matchstr(getline('.'), '\m\S\+')
+    let hex=bvar.repo.functions.getrevhex(bvar.repo, rev)
+    let cs=bvar.repo.changesets[hex]
+    let epath=escape(bvar.repo.path, ':\')
+    if a:action[-4:] is# 'diff'
+        let rev1=''
+        let rev2=hex
+        if a:action[:2] is# 'rev'
+            let rev1=get(cs.parents, 0, '')
+        endif
+        if a:action[-7:-5] is# 'vim'
+            if has_key(bvar, 'annbuf') && bufwinnr(bvar.annbuf)!=-1
+                execute bufwinnr(bvar.annbuf).'wincmd w'
+                execute 'setlocal noscrollbind'
+                execute 'bwipeout '.buf
+            elseif empty(rev1)
+                execute 'edit '.fnameescape('aurum://file:'.epath.':'.
+                            \               bvar.rev.':'.bvar.file)
+            endif
+            if !empty(rev1)
+                execute 'edit '.fnameescape('aurum://file:'.epath.':'.
+                            \               rev1.':'.bvar.file)
+            endif
+            call s:_r.aurum.diffsplit(buf, 'aurum://file:'.epath.':'.rev2.':'.
+                        \                  bvar.file)
+        else
+            if empty(rev1)
+                let rev1=bvar.rev
+            endif
+            execute 'edit '.fnameescape('aurum://diff:'.epath.':'.
+                        \               rev1.':'.rev2.':'.
+                        \               ((a:0&&a:1)?(''):(bvar.file)))
+        endif
+    elseif a:action is# 'open'
+        let file=s:F.getfile(cs)
+        if file is 0
+            return
+        endif
+        execute 'edit '.fnameescape('aurum://file:'.epath.':'.hex.':'.file)
+    endif
+endfunction
+"▶1 getrhs
+function s:F.getrhs(...)
+    return ':call(<SID>Eval("s:F.runmap"), '.string(a:000).', {})<CR>'
+endfunction
+"▶1 AuAnnotate mapping group
+call s:_f.mapgroup.add('AuAnnotate', {
+            \    'Enter': {'lhs': '<CR>', 'rhs': s:F.getrhs(   'vimdiff'   )},
+            \    'Diff':  {'lhs':  'd',   'rhs': s:F.getrhs(      'diff'   )},
+            \    'Rdiff': {'lhs':  'c',   'rhs': s:F.getrhs('rev'.'diff'   )},
+            \    'Vdiff': {'lhs':  'D',   'rhs': s:F.getrhs(   'vimdiff'   )},
+            \   'RVdiff': {'lhs':  'C',   'rhs': s:F.getrhs('revvimdiff'   )},
+            \    'Fdiff': {'lhs': 'gd',   'rhs': s:F.getrhs('rev'.'diff', 1)},
+            \     'Open': {'lhs':  'o',   'rhs': s:F.getrhs('open'         )},
+            \}, {'silent': 1})

File ftplugin/aurumgraphlog.vim

     let [blockstart, blockend, hex]=s:F.getblock(bvar)
     let spname=s:F.findCurSpecial(bvar, hex, blockstart[0])
     let cs=bvar.repo.changesets[hex]
+    let file=0
     if spname=~#'\v^file\d+$'
         let file=cs.files[+spname[4:]]
     elseif !empty(cs.files)
         if len(cs.files)==1
             let file=cs.files[0]
         else
-            let file=cs.files[inputlist(['Select file:']+
+            let choice=inputlist(['Select file (0 to cancel):']+
                         \               map(copy(cs.files),
-                        \                   '(v:key+1).". ".v:val'))-1]
+                        \                   '(v:key+1).". ".v:val'))
+            if choice
+                let file=cs.files[choice-1]
+            endif
         endif
     endif
-    return [hex, exists('file') ? file : 0]
+    return [hex, file]
 endfunction
 "▶1 open
 function s:F.open()

File plugin/aurum.vim

     let file=bufname('%')
     let file=s:_r.os.path.relpath(file, repo.path)
     let file=join(s:_r.os.path.split(file)[1:], '/')
+    let annbuf=bufnr('%')
     setlocal scrollbind
     execute 'leftabove 42vsplit '.fnameescape(
                 \'aurum://annotate::.:'.file)
     setlocal scrollbind
+    let s:bufvars[bufnr('%')].annbuf=annbuf
 endfunction
 "▶3 difffunc
 function s:difffunc.function(...)
     let rev1=repo.functions.getrevhex(repo, get(a:000, 0, '.'))
     let rev2=a:0>1?repo.functions.getrevhex(repo, a:2):0
     if rev2 is 0
-        execute 'diffsplit '.fnameescape('aurum://file::'.rev1.':'.file)
+        call s:F.comm.diffsplit(bufnr('%'), 'aurum://file::'.rev1.':'.file)
     else
         execute 'edit '.fnameescape('aurum://file::'.rev1.':'.file)
         execute 'diffsplit '.fnameescape('aurum://file::'.rev2.':'.file)
 "▶3 aubwfunc
 function s:aubwfunc.function()
     let buf=+expand('<abuf>')
-    unlet s:bufvars[buf]
+    if has_key(s:bufvars, buf)
+        unlet s:bufvars[buf]
+    endif
 endfunction
+"▶3 comm.diffrestore
+let s:diffsaveopts=['diff', 'foldcolumn', 'foldenable', 'foldmethod',
+            \       'foldlevel', 'scrollbind', 'cursorbind', 'wrap']
+function s:F.comm.diffrestore(buf, onenter)
+    if !bufexists(a:buf)
+        return
+    endif
+    let bvar=s:bufvars[a:buf]
+    if a:onenter
+        if has_key(bvar, 'diffbuf')
+            if bufexists(bvar.diffbuf)
+                return
+            else
+                call s:F.comm.diffrestore(a:buf, 0)
+            endif
+        elseif !has_key(bvar, 'diffsaved')
+            return
+        endif
+        augroup AurumDiff
+            autocmd! BufEnter <buffer>
+        augroup END
+        if b:changedtick!=bvar.diffsaved.changedtick
+            return
+        endif
+        let curpos=getpos('.')
+        call winrestview(bvar.diffsaved.winview)
+        normal! zR
+        for line in bvar.diffsaved.closedfolds
+            execute line.'foldclose'
+        endfor
+        call setpos('.', curpos)
+        unlet bvar.diffsaved
+    else
+        for option in s:diffsaveopts
+            call setbufvar(a:buf, '&'.option, bvar.diffsaved[option])
+        endfor
+        unlet bvar.diffbuf
+        if bufnr('%')==a:buf
+            call s:F.comm.diffrestore(a:buf, 1)
+        endif
+    endif
+endfunction
+"▶3 comm.diffsplit
+function s:F.comm.diffsplit(srcbuf, difftarget)
+    if !has_key(s:bufvars, a:srcbuf)
+        let s:bufvars[a:srcbuf]={}
+    endif
+    let bvar=s:bufvars[a:srcbuf]
+    let diffsaved={}
+    let bvar.diffsaved=diffsaved
+    for option in s:diffsaveopts
+        let diffsaved[option]=getbufvar(a:srcbuf, '&'.option)
+    endfor
+    let diffsaved.winview=winsaveview()
+    let diffsaved.changedtick=b:changedtick
+    let closedfolds=[]
+    let diffsaved.closedfolds=closedfolds
+    for line in range(1, line('$'))
+        if foldclosed(line)!=-1
+            execute line.'foldopen'
+            call insert(closedfolds, line)
+        endif
+    endfor
+    echom string(closedfolds)
+    execute 'diffsplit' fnameescape(a:difftarget)
+    let bvar.diffbuf=bufnr('%')
+    augroup AurumDiff
+        execute 'autocmd BufWipeOut <buffer> '.
+                    \':call s:F.comm.diffrestore('.a:srcbuf.', 0)'
+        execute 'autocmd BufEnter <buffer='.a:srcbuf.'> '.
+                    \':call s:F.comm.diffrestore('.a:srcbuf.', 1)'
+    augroup END
+endfunction
+let s:_augroups+=['AurumDiff']
 "▶3 Post aurum resource
-call s:_f.postresource('aurum', {'bufvars': s:bufvars}, 1)
+call s:_f.postresource('aurum', {'bufvars': s:bufvars,
+            \                  'diffsplit': s:F.comm.diffsplit}, 1)
 "▶1
 call frawor#Lockvar(s:, 'repos,_pluginloaded,bufvars')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲