Commits

ZyX_I  committed a1b577f

@aurum/log: Made message generator use real leading column width
Added @-@ and @.@ expr “variables”
Some fixes to line width determination code
Fixes #24

  • Participants
  • Parent commits f03805f

Comments (0)

Files changed (2)

File doc/aurum.txt

            prepended to the first line.
 expr       Use this expression instead of default to get resulting string. 
            Inside an expression “@@@” refers to original data, “@N@” - to Nth 
-           positional parameter (count starts from zero), “@<@” - to string 
-           that should be prepended to every line (valid for complex multiline 
-           template strings).
+           positional parameter (count starts from zero), “@-@” - to number of 
+           leading columns taken by graph lines, “@.@” - to current 
+           |aurum-changeset| object, “@<@” - to string that should be 
+           prepended to every line (valid for complex multiline template 
+           strings).
 synreg     Pass this regular expression to “syn match”. Useful if you override 
            output of the {word} using “expr” keyword.
 pref, suf  For some single-line statements (currently: rev, parents, children, 
                required to do the job (see below). It will be done in any case 
                by log generator function.
     2. "next" function must accept value returned by "start" function and 
-       return |aurum-cs| object. Returned objects must be sorted in 
+       return |aurum-changeset| object. Returned objects must be sorted in 
        topological order like described under |aurum-rf-getchangesets|.
 
     Value of "changesets" key will be used to view full repository history.
          added skipping of $rev if |aurum-repo.hasrevisions| is false, made it 
          separate graph from content using non-breaking spaces.
     0.2: Added |:AuLog| procinput option.
+    0.3: Added @-@ and @.@ expr “variables”.
 @aurum/status:
     1.0: Renamed |:AuStatus| “rev1” and “rev2” options to “rev” and “wdrev” 
          respectively. Same for |aurum://status| “rev1” and “rev2” options.

File plugin/aurum/log.vim

 "▶1
 scriptencoding utf-8
 if !exists('s:_pluginloaded')
-    execute frawor#Setup('0.2', {'@/table': '0.1',
+    execute frawor#Setup('0.3', {'@/table': '0.1',
                 \        '@aurum/cmdutils': '0.0',
                 \         '@aurum/bufvars': '0.0',
                 \            '@aurum/edit': '1.1',
                 \             mapexpr)
     return a:special
 endfunction
+"▶2 glog.gettext :: skip, cs, opts, repo, width → Text
+let s:skiptext={'skip': 1, 'text': [], 'special': {}}
+function s:F.glog.gettext(skip, ...)
+    if a:skip
+        return deepcopy(s:skiptext)
+    else
+        return call(a:2.templatefunc, a:000, {})
+    endif
+endfunction
 "▶2 glog.utf
-function s:F.glog.utf(state, type, char, text, coldata)
+function s:F.glog.utf(state, type, coldata, char, skip, cs, opts, repo)
     let [idx, edges, ncols, coldiff]=a:coldata
+    let text=s:F.glog.gettext(a:skip, a:cs, a:opts, a:repo, ncols)
     let add_padding_line=0
-    let lnum = (has_key(a:text, 'text') ? len(a:text.text) : 0)
+    let lnum = (has_key(text, 'text') ? len(text.text) : 0)
     if coldiff==-1
         call s:F.glog.fix_long_right_edges(edges)
         if lnum>2
     call s:F.glog.draw_edges(edges, nodeline, shift_interline)
     let joined_nl=join(nodeline, '')
     let joined_sil=join(shift_interline, '')
-    if has_key(a:text, 'skip')
-        let a:text.text=[]
+    if has_key(text, 'skip')
+        let text.text=[]
         if joined_nl!~#'\v^[*| ]+$'
-            let a:text.text+=[joined_nl]
+            let text.text+=[joined_nl]
         endif
         if joined_sil!~#'\v^[| ]+$' &&
                     \joined_sil isnot# tr(joined_nl, a:char, '|')
-            let a:text.text+=[joined_sil]
+            let text.text+=[joined_sil]
         endif
-        return a:text
+        return text
     endif
     let lines=[joined_nl]
     if add_padding_line
         let extra_interline=repeat('| ', ncols+coldiff)
         let lines+=repeat([extra_interline], ltdiff)
     else
-        call extend(a:text.text, repeat([''], -ltdiff))
+        call extend(text.text, repeat([''], -ltdiff))
     endif
     let indentation_level=2*max([ncols, ncols+coldiff])
     let a:state[0]=coldiff
     let a:state[1]=idx
     call map(lines, 'printf("%-*s ", indentation_level, v:val)')
-    let curspecial=a:text.special
+    let curspecial=text.special
     let shiftlen=len(lines[0])
-    call s:F.glog.addcols(a:text.special, shiftlen)
-    let a:text.block_r=[[0, shiftlen],
-                \       [len(a:text.text)-1,
-                \        max(map(copy(lines), 'len(v:val)'))]]
+    call s:F.glog.addcols(text.special, shiftlen)
+    let text.block_r=[[0, shiftlen],
+                \     [len(text.text)-1,
+                \      max(map(copy(lines), 'len(v:val)'))]]
     let curspecial.bullet=[0, stridx(lines[0], a:char), a:char]
-    call map(a:text.text, 'lines[v:key].v:val')
-    return a:text
+    call map(text.text, 'lines[v:key].v:val')
+    return text
 endfunction
 "▶2 glog.graph_init :: repo, [cs] → graph
 let s:defgraph={
         \}
 function s:F.glog.graph_init(showparents, opts, repo)
     let graph=deepcopy(s:defgraph)
+    let graph.opts=a:opts
     let graph.repo=a:repo
     let graph.workcss=a:showparents
     let graph.skipchangesets=a:opts.skipchangesets
     call extend(graph, s:F.graph)
     return graph
 endfunction
-"▶2 glog.show_log :: graph, cs, Text → Text
-function s:F.glog.show_log(graph, cs, text)
+"▶2 glog.show_log :: graph, cs, skip::Bool → Text
+function s:F.glog.show_log(graph, cs, skip)
     let lines=((a:graph.cs is 0)?([]):(a:graph.show_remainder()))
     call a:graph.update(a:cs)
     let lines+=a:graph.show_commit()
-    let skip=has_key(a:text, 'skip')
-    if skip && len(lines)==1 && lines[0]!~#'[^|* ]'
-        return a:text
+    if a:skip && len(lines)==1 && lines[0]!~#'[^|* ]'
+        return deepcopy(s:skiptext)
     endif
     let collen=len(lines[-1])
-    let a:text.block_r[0][1]+=collen
-    let a:text.block_r[1][1]+=collen
-    call s:F.glog.addcols(a:text.special, collen)
-    let lines[-1]=lines[-1][:-2].' '.get(a:text.text, 0, '')
+    let text=s:F.glog.gettext(a:skip, a:cs, a:graph.opts, a:graph.repo, collen)
+    let text.block_r=[[0, collen],
+                \     [len(text.text)-1,
+                \      collen+max(map(copy(text.text), 'len(v:val)'))]]
+    call s:F.glog.addcols(text.special, collen)
+    let lines[-1]=lines[-1][:-2].' '.get(text.text, 0, '')
     let cchar=a:graph.output_commit_char()
     let bidx=stridx(lines[-1], cchar)
     if bidx!=-1
-        let a:text.special.bullet=[0, bidx, cchar]
+        let text.special.bullet=[0, bidx, cchar]
     endif
-    for line in a:text.text[1:]
+    for line in text.text[1:]
         let lines+=[a:graph.next_line()[:-2].' '.line]
     endfor
-    let a:text.text=lines
-    return a:text
+    let text.text=lines
+    return text
 endfunction
 "▶2 s:DateCmp :: cs, cs → -1|0|1
 function s:DateCmp(a, b)
     return {'graph': graph, 'opts': a:opts, 'repo': a:repo}
 endfunction
 function s:iterfuncs.git.proccs(d, cs)
-    if has_key(a:d.opts.skipchangesets, a:cs.hex)
-        let text={'skip': 1, 'text': [], 'special': {}}
+    let skip=has_key(a:d.opts.skipchangesets, a:cs.hex)
+    let text=s:F.glog.show_log(a:d.graph, a:cs, skip)
+    if skip
+        return [text.text, 0, 0]
     else
-        let text=a:d.opts.templatefunc(a:cs, a:d.opts, a:d.repo)
+        return [text.text, text.block_r, text.special]
     endif
-    let text.block_r=[[0, 0],
-                \     [len(text.text)-1,
-                \      max(map(copy(text.text), 'len(v:val)'))]]
-    let text=s:F.glog.show_log(a:d.graph, a:cs, text)
-    return [text.text, text.block_r, text.special]
 endfunction
 "▶2 iterfuncs.hg
 let s:iterfuncs.hg={}
                 \'showparents': get(a:000, 0, []), 'repo': a:repo}
 endfunction
 function s:iterfuncs.hg.proccs(d, cs)
-    if has_key(a:d.opts.skipchangesets, a:cs.hex)
+    let skip=has_key(a:d.opts.skipchangesets, a:cs.hex)
+    if skip
         let char='*'
-        let text={'skip': 1}
-        let skip=1
     else
         let char=((index(a:d.showparents, a:cs.hex)==-1)?('o'):('@'))
-        let text=a:d.opts.templatefunc(a:cs, a:d.opts, a:d.repo)
-        let skip=0
     endif
-    call s:F.glog.utf(a:d.state, 'C', char, text,
-                \     s:F.glog.utfedges(a:d.seen, a:cs.hex, a:cs.parents))
+    let text=s:F.glog.utf(a:d.state, 'C',
+                \     s:F.glog.utfedges(a:d.seen, a:cs.hex, a:cs.parents), char,
+                \     skip, a:cs, a:d.opts, a:d.repo)
     if !has_key(text, 'text') || empty(text.text)
         return [[], 0, 0]
     endif
     if has_key(a:d.opts.skipchangesets, a:cs.hex)
         return [[], 0, 0]
     endif
-    let text=a:d.opts.templatefunc(a:cs, a:d.opts, a:d.repo)
+    let text=a:d.opts.templatefunc(a:cs, a:d.opts, a:d.repo, 2)
     let text.block_r=[[0, 0],
                 \     [len(text.text)-1,
                 \      max(map(copy(text.text), 'len(v:val)'))]]
             \           "$hide#:#$patch\n",
         \}
 "▶2 s:kwexpr
-" TODO Add bisection status
+" TODO Add bisection status and phases
 let s:kwexpr={}
 let s:kwexpr.hide        = [0, '@0@', 0]
 let s:kwexpr.empty       = [0, '@@@']
 " TODO Add tab expansion
 let s:kwexpr.description = [1, 'split(@@@, "\n")']
 let s:kwexpr.patch       = [1, '@@@']
-let s:kwexpr.stat        = [2, 's:F.temp.stat(@@@, a:cs.files, @<@)']
-let s:kwexpr.files       = [2, 's:F.temp.multlfmt(@@@, a:cs.files, '.
+let s:kwexpr.stat        = [2, 's:F.temp.stat(@@@, @.@.files, @<@)']
+let s:kwexpr.files       = [2, 's:F.temp.multlfmt(@@@, @.@.files, '.
             \                                    '@<@, @0@, '.
-            \                                    '"file")', ', ']
-let s:kwexpr.changes     = [2, 's:F.temp.multlfmt(@@@, a:cs.changes, '.
+            \                                    '"file", @-@)', ', ']
+let s:kwexpr.changes     = [2, 's:F.temp.multlfmt(@@@, @.@.changes, '.
             \                                    '@<@, @0@, '.
-            \                                    '"file")', ', ']
-let s:kwexpr.renames     = [2, 's:F.temp.renames(@@@, a:cs.files, '.
+            \                                    '"file", @-@)', ', ']
+let s:kwexpr.renames     = [2, 's:F.temp.renames(@@@, @.@.files, '.
             \                                   '@<@, @0@)', ' to ']
-let s:kwexpr.copies      = [2, 's:F.temp.renames(@@@, a:cs.files, '.
+let s:kwexpr.copies      = [2, 's:F.temp.renames(@@@, @.@.files, '.
             \                                   '@<@, @0@)', ' to ']
 let s:kwmarg={}
-let s:kwmarg.summary='matchstr(a:cs.description, "\\\\v^[^\\n]*")'
+let s:kwmarg.summary='matchstr(@.@.description, "\\\\v^[^\\n]*")'
 let s:kwmarg.stat='a:repo.functions.getstats(a:repo, diff, a:opts)'
 let s:kwmarg.patch='diff'
 let s:kwmarg.empty=''''''
     endfor
     return [rt, special]
 endfunction
-"▶2 temp.multlfmt :: list, idxlist, linebeg, itemsep, itemname → ([String], sp)
-function s:F.temp.multlfmt(list, idxlist, linebeg, itemsep, itemname)
+"▶2 temp.multlfmt :: list, idxlst, lbeg, isep, iname, width → ([String], sp)
+function s:F.temp.multlfmt(list, idxlist, linebeg, itemsep, itemname, width)
     let rt=[a:linebeg]
     let special={}
-    let winwidth=winwidth(0)-10
-    let linewidth=s:_r.strdisplaywidth(a:linebeg)
+    let winwidth=winwidth(0)
+    let initwidth=a:width+s:_r.strdisplaywidth(a:linebeg, a:width)
+    let linewidth=initwidth
     let curfilenum=0
     let ii=-1
     let seplen=len(a:itemsep)
     for item in a:list
         let iwidth=s:_r.strdisplaywidth(item, linewidth)
         if curfilenum && iwidth+linewidth>winwidth
-            let rt+=[a:linebeg.item.a:itemsep]
-            let linewidth=s:_r.strdisplaywidth(rt[-1])
+            let tail=item.a:itemsep
+            let rt+=[a:linebeg.tail]
+            let linewidth=initwidth+s:_r.strdisplaywidth(tail, initwidth)
             let curfilenum=0
         else
             let rt[-1].=item.a:itemsep
-            let linewidth+=iwidth
+            let linewidth+=iwidth+
+                        \  s:_r.strdisplaywidth(a:itemsep, linewidth+iwidth)
         endif
         let cl=len(rt)-1
         let ilen=len(item)
         return s:compilecache[cid]
     endif
     "▶3 Define variables
-    let func=['function d.template(cs, opts, repo)',
+    let func=['function d.template(cs, opts, repo, width)',
                 \'let r={"text": [], "special": {}}',
                 \'let text=r.text',
                 \'let special=r.special',]
                     let marg='a:cs.'.kw
                 endif
                 "▲4
-                let expr=substitute(expr, '@@@', marg, 'g')
+                let expr=substitute(substitute(substitute(expr,
+                            \'\V@@@', marg,      'g'),
+                            \'\V@.@', 'a:cs',    'g'),
+                            \'\V@-@', 'a:width', 'g')
                 "▶3 Process positional parameters
                 for j in range(len(ke)-2)
                     let expr=substitute(expr, '@'.j.'@',