Commits

ZyX_I committed 16c962e

Some refactoring

Comments (0)

Files changed (1)

                 \               '@/resources': '0.0',
                 \                     '@/fwc': '0.3',
                 \                 '@/options': '0.0',}, 0)
-    call map(['hg', 'comm', 'rec'], 'extend(s:F, {v:val : {}})')
+    call map(['hg', 'comm', 'rec', 'com'], 'extend(s:F, {v:val : {}})')
     lockvar 1 s:F
     "▶2 Команды
     call FraworLoad('@/commands')
 call s:_f.mapgroup.add('AuRecordLeft', {
             \   'save': {'lhs': ',A', 'rhs': s:F.rec.gml('save')},
         \}, {'mode': 'n', 'silent': 1, 'dontmap': 1, 'leader': ','})
+"▶2 com
+"▶3 com.parsedate string -> [year, month, day, hour, minute, second]
+" Date must have one of the following formats (XXX it is not validated):
+" %Y-%m-%d %H:%M:%S
+" %Y-%m-%d %H:%M
+" %Y-%m-%d
+"    %m-%d %H:%M:%S
+"    %m-%d %H:%M
+"    %m-%d
+"          %H:%M:%S
+"          %H:%M
+function s:F.com.parsedate(str)
+    let parts=split(a:str)
+    if len(parts)==1
+        if stridx(parts[0], ':')==-1
+            let day=parts[0]
+            let time=0
+        else
+            let day=0
+            let time=parts[0]
+        endif
+    else
+        let [day, time]=parts
+    endif
+    let r=[]
+    if day is# 0
+        let r+=[0, 0, 0]
+    else
+        let parts=split(day, '-')
+        if len(parts)==2
+            let r+=[0]
+        else
+            let year=remove(parts, 0)
+            if len(year)<=2
+                let y=str2nr(year)
+                let cy=str2nr(strftime('%y'))
+                let c=str2nr(strftime('%Y')[:-3])
+                if y<=cy
+                    let year=''.((c*100)+y)
+                else
+                    let year=''.(((c-1)*100)+y)
+                endif
+            endif
+            let r+=[year]
+        endif
+        let r+=map(parts, 'len(v:val)==1 ? "0".v:val : v:val')
+    endif
+    if time is# 0
+        let r+=[0, 0, 0]
+    else
+        let parts=map(split(time, ':'), 'len(v:val)==1 ? "0".v:val : v:val')
+        let r+=parts
+        if len(parts)==2
+            let r+=[0]
+        endif
+    endif
+    return r
+endfunction
+"▶3 com.runcommap
+function s:F.com.runcommap(action, ...)
+    let buf=get(a:000, 0, bufnr('%'))
+    let bvar=s:bufvars[buf]
+    if a:action is# 'commit'
+        let message=join(getline(1, '$'), "\n")
+        call bvar.repo.functions.commit(bvar.repo, message, bvar.files,
+                    \                   bvar.user, bvar.date, bvar.closebranch)
+        if !a:0
+            bwipeout!
+            stopinsert
+        endif
+    elseif a:action is# 'discard'
+        if !a:0
+            bwipeout!
+        endif
+    endif
+    if has_key(bvar, 'sbvar')
+        call s:F.rec.unload(bvar.sbvar)
+    endif
+endfunction
+"▶3 comfunc
+let s:defdate=['strftime("%Y")',
+            \  'strftime("%m")',
+            \  'strftime("%d")',
+            \  '"00"',
+            \  '"00"',
+            \  '"00"']
+function s:comfunc.function(opts, ...)
+    let repo=a:opts.repo
+    if type(repo)!=type({})
+        call s:_f.throw('nrepo')
+    endif
+    "▶4 Get file list
+    let types=get(a:opts, 'type', 0)
+    if a:0
+        let filepats=map(copy(a:000), 's:F.comm.globtopattern('.
+                    \                 'repo.functions.reltorepo(repo, v:val))')
+        let status=repo.functions.status(bvar.repo)
+        let files=[]
+        for [type, files] in items(status)
+            if type is# 'clean' || (types isnot 0 && index(types, type)==-1)
+                continue
+            endif
+            for pattern in filepats
+                if file=~#pattern
+                    let files+=[file]
+                    break
+                endif
+            endfor
+        endfor
+    elseif filereadable(expand('%'))
+        let files=[join(s:_r.os.path.split(s:_r.os.path.relpath(expand('%'),
+                    \                                          repo.path))[1:],
+                    \  '/')]
+    else
+        call s:_f.throw('nocfile')
+    endif
+    "▲4
+    let user=''
+    let date=''
+    let message=''
+    let cb=get(a:opts, 'closebranch', 0)
+    for key in filter(['user', 'date', 'message'], 'has_key(a:opts, v:val)')
+        let l:{key}=a:opts[key]
+    endfor
+    "▶4 Normalize date
+    if has_key(a:opts, 'date')
+        let date=substitute(date, '_', ' ', '')
+        let dparts=map(s:F.com.parsedate(date), 'v:val is 0 ? '.
+                    \                               'eval(s:defdate[v:key]) : '.
+                    \                               'v:val')
+        let date=join(dparts[:2], '-').' '.join(dparts[3:], ':')
+    endif
+    "▲4
+    if empty(message)
+        let epath=escape(repo.path, ':\')
+        let euser=escape(user, ':\')
+        execute 'silent new'
+                    \fnameescape('aurum://commit:'.epath.':'.euser.':'.date.':'.
+                    \                                        cb.':'.
+                    \            join(map(copy(files), 'escape(v:val, "\\;")'),
+                    \                 ';'))
+        startinsert
+    else
+        call repo.functions.commit(repo, message, files, user, date,
+                    \              get(a:opts, 'closebranch', 0))
+    endif
+endfunction
+let s:comfunc['@FWC']=['-onlystrings '.
+            \          '{  repo '.substitute(s:repoarg, '\V"."', '":"', '').
+            \          ' *?type      (in [modified added removed deleted '.
+            \                            'uknown ignored] ~start)'.
+            \          '  ?message   (type "")'.
+            \          '  ?user      (type "")'.
+            \          '  ?date      match /\v%(^%(\d*\d\d-)?'.
+            \                                   '%(%(1[0-2]|0?[1-9])-'.
+            \                                     '%(3[01]|0?[1-9]|[12]\d)))?'.
+            \                                '%(%(^|[ _])%(2[0-3]|[01]\d)'.
+            \                                           '\:[0-5]\d'.
+            \                                           '%(\:[0-5]\d)?)?$/'.
+            \          ' !?closebranch'.
+            \          '}'.
+            \          '+ type ""', 'filter']
+call add(s:comcomp,
+            \substitute(substitute(s:comfunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''),
+            \'\V+ type ""', '+ (path)', ''))
+"▶3 AuCommitMessage mapping group
+function s:F.comm.gmc(...)
+    return ':<C-u>call call(<SID>Eval("s:F.com.runcommap"),'.string(a:000).','.
+                \          '{})<CR>'
+endfunction
+call s:_f.mapgroup.add('AuCommitMessage', {
+            \ 'commit': {'lhs': 'C', 'rhs': s:F.comm.gmc('commit') },
+            \'discard': {'lhs': 'X', 'rhs': s:F.comm.gmc('discard')},
+        \}, {'mode': 'in', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶2 comm
 "▶3 comm.reltorepo :: repo, path → rpath
 function s:F.comm.reltorepo(repo, path)
                 \'\V\\{'.char2nr('\').'}', '\\\\', 'g'),
                 \'\V\\{\(\d\+\)}', '\=nr2char(submatch(1))', 'g').'\v($|\/)'
 endfunction
-"▶3 comm.runcommap
-function s:F.comm.runcommap(action, ...)
-    let buf=get(a:000, 0, bufnr('%'))
-    let bvar=s:bufvars[buf]
-    if a:action is# 'commit'
-        let message=join(getline(1, '$'), "\n")
-        call bvar.repo.functions.commit(bvar.repo, message, bvar.files,
-                    \                   bvar.user, bvar.date, bvar.closebranch)
-        if !a:0
-            bwipeout!
-            stopinsert
-        endif
-    elseif a:action is# 'discard'
-        if !a:0
-            bwipeout!
-        endif
-    endif
-    if has_key(bvar, 'sbvar')
-        call s:F.rec.unload(bvar.sbvar)
-    endif
-endfunction
 "▶3 comm.encodeopts :: opts → String
 function s:F.comm.encodeopts(opts)
     let r=''
     augroup END
 endfunction
 let s:_augroups+=['AurumDiff']
-"▶3 comm.parsedate string -> [year, month, day, hour, minute, second]
-" Date must have one of the following formats (XXX it is not validated):
-" %Y-%m-%d %H:%M:%S
-" %Y-%m-%d %H:%M
-" %Y-%m-%d
-"    %m-%d %H:%M:%S
-"    %m-%d %H:%M
-"    %m-%d
-"          %H:%M:%S
-"          %H:%M
-function s:F.comm.parsedate(str)
-    let parts=split(a:str)
-    if len(parts)==1
-        if stridx(parts[0], ':')==-1
-            let day=parts[0]
-            let time=0
-        else
-            let day=0
-            let time=parts[0]
-        endif
-    else
-        let [day, time]=parts
-    endif
-    let r=[]
-    if day is# 0
-        let r+=[0, 0, 0]
-    else
-        let parts=split(day, '-')
-        if len(parts)==2
-            let r+=[0]
-        else
-            let year=remove(parts, 0)
-            if len(year)<=2
-                let y=str2nr(year)
-                let cy=str2nr(strftime('%y'))
-                let c=str2nr(strftime('%Y')[:-3])
-                if y<=cy
-                    let year=''.((c*100)+y)
-                else
-                    let year=''.(((c-1)*100)+y)
-                endif
-            endif
-            let r+=[year]
-        endif
-        let r+=map(parts, 'len(v:val)==1 ? "0".v:val : v:val')
-    endif
-    if time is# 0
-        let r+=[0, 0, 0]
-    else
-        let parts=map(split(time, ':'), 'len(v:val)==1 ? "0".v:val : v:val')
-        let r+=parts
-        if len(parts)==2
-            let r+=[0]
-        endif
-    endif
-    return r
-endfunction
 "▶2 auefunc
 let s:bufvars={}
 "▶3 comm.repotuplesplit :: str, UInt → (repo, String, ...)
         call s:_f.mapgroup.map('AuCommitMessage', bufnr('%'))
         setlocal modifiable noreadonly bufhidden=wipe
         augroup AuCommitMessage
-            autocmd BufWriteCmd <buffer> call s:F.comm.runcommap('commit')
+            autocmd BufWriteCmd <buffer> call s:F.com.runcommap('commit')
         augroup END
         setlocal buftype=acwrite
     "▶3 copy command (file)
     let s:bufvars[buf].command=command
 endfunction
 let s:_augroups+=['AuCommitMessage']
-"▶3 AuCommitMessage mapping group
-function s:F.comm.gmc(...)
-    return ':<C-u>call call(<SID>Eval("s:F.comm.runcommap"),'.string(a:000).','.
-                \          '{})<CR>'
-endfunction
-call s:_f.mapgroup.add('AuCommitMessage', {
-            \ 'commit': {'lhs': 'C', 'rhs': s:F.comm.gmc('commit') },
-            \'discard': {'lhs': 'X', 'rhs': s:F.comm.gmc('discard')},
-        \}, {'mode': 'in', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶2 glogfunc
 function s:glogfunc.function(repo, opts)
     if type(a:repo)!=type({})
 call add(s:diffcomp,
             \substitute(s:difffunc['@FWC'][0],
             \'\vfile\s+type\s*\V""', 'file path', ''))
-"▶2 comfunc
-let s:defdate=['strftime("%Y")',
-            \  'strftime("%m")',
-            \  'strftime("%d")',
-            \  '"00"',
-            \  '"00"',
-            \  '"00"']
-function s:comfunc.function(opts, ...)
-    let repo=a:opts.repo
-    if type(repo)!=type({})
-        call s:_f.throw('nrepo')
-    endif
-    let types=get(a:opts, 'type', 0)
-    if a:0
-        let filepats=map(copy(a:000), 's:F.comm.globtopattern('.
-                    \                 'repo.functions.reltorepo(repo, v:val))')
-        let status=repo.functions.status(bvar.repo)
-        let files=[]
-        for [type, files] in items(status)
-            if type is# 'clean' || (types isnot 0 && index(types, type)==-1)
-                continue
-            endif
-            for pattern in filepats
-                if file=~#pattern
-                    let files+=[file]
-                    break
-                endif
-            endfor
-        endfor
-    elseif filereadable(expand('%'))
-        let files=[join(s:_r.os.path.split(s:_r.os.path.relpath(expand('%'),
-                    \                                          repo.path))[1:],
-                    \  '/')]
-    else
-        call s:_f.throw('nocfile')
-    endif
-    let user=''
-    let date=''
-    let message=''
-    let cb=get(a:opts, 'closebranch', 0)
-    for key in filter(['user', 'date', 'message'], 'has_key(a:opts, v:val)')
-        let l:{key}=a:opts[key]
-    endfor
-    if has_key(a:opts, 'date')
-        let date=substitute(date, '_', ' ', '')
-        let dparts=map(s:F.comm.parsedate(date), 'v:val is 0 ? '.
-                    \                               'eval(s:defdate[v:key]) : '.
-                    \                               'v:val')
-        let date=join(dparts[:2], '-').' '.join(dparts[3:], ':')
-    endif
-    " TODO Implement closebranch
-    if empty(message)
-        let epath=escape(repo.path, ':\')
-        let euser=escape(user, ':\')
-        execute 'silent new'
-                    \fnameescape('aurum://commit:'.epath.':'.euser.':'.date.':'.
-                    \                                        cb.':'.
-                    \            join(map(copy(files), 'escape(v:val, "\\;")'),
-                    \                 ';'))
-        startinsert
-    else
-        call repo.functions.commit(repo, message, files, user, date,
-                    \              get(a:opts, 'closebranch', 0))
-    endif
-endfunction
-let s:comfunc['@FWC']=['-onlystrings '.
-            \          '{  repo '.substitute(s:repoarg, '\V"."', '":"', '').
-            \          ' *?type      (in [modified added removed deleted '.
-            \                            'uknown ignored] ~start)'.
-            \          '  ?message   (type "")'.
-            \          '  ?user      (type "")'.
-            \          '  ?date      match /\v%(^%(\d*\d\d-)?'.
-            \                                   '%(%(1[0-2]|0?[1-9])-'.
-            \                                     '%(3[01]|0?[1-9]|[12]\d)))?'.
-            \                                '%(%(^|[ _])%(2[0-3]|[01]\d)'.
-            \                                           '\:[0-5]\d'.
-            \                                           '%(\:[0-5]\d)?)?$/'.
-            \          ' !?closebranch'.
-            \          '}'.
-            \          '+ type ""', 'filter']
-call add(s:comcomp,
-            \substitute(substitute(s:comfunc['@FWC'][0],
-            \'\V|*F.comm.getrepo',  '',           ''),
-            \'\V+ type ""', '+ (path)', ''))
 "▶2 aubwfunc
 function s:aubwfunc.function()
     let buf=+expand('<abuf>')
     if has_key(s:bufvars, buf)
         if s:bufvars[buf].command is# 'commit'
-            call s:F.comm.runcommap('discard', buf)
+            call s:F.com.runcommap('discard', buf)
         endif
         unlet s:bufvars[buf]
     endif