Commits

ZyX_I committed 95bb194

Added :AuCommit (untested)
Made some commands use opts.repo to define repository instead of first optional argument

Comments (0)

Files changed (1)

     let s:reccomp=[]
     call s:_f.command.add('AuRecord', s:recfunc, {'nargs': '*',
                 \                              'complete': s:reccomp})
+    let s:comfunc={}
+    let s:comcomp=[]
+    call s:_f.command.add('AuCommit', s:comfunc, {'nargs': '*',
+                \                              'complete': s:comcomp})
     "▶2 Autocommands
     call FraworLoad('@/autocommands')
     let s:auefunc={}
 endfunction
 "▶2 rec
 "▶3 recfunc
-function s:recfunc.function(repo, opts, ...)
+function s:recfunc.function(opts, ...)
     tabnew
     let t:aurecid='AuRecordTab'
     let w:aurecid='AuRecordLeft'
     rightbelow vsplit
     let w:aurecid='AuRecordRight'
-    let epath=escape(a:repo.path, ':\')
+    let repo=a:opts.repo
+    let epath=escape(repo.path, ':\')
     let files=copy(a:000)
-    call map(files, 'join('.
-                \   's:_r.os.path.split('.
-                \   's:_r.os.path.relpath(v:val, a:repo.path))[1:], "/")')
+    call map(files, 'repo.functions.reltorepo(repo, v:val)')
     let opts='record:1'
     if !empty(files)
         let opts.=',files:'.join(map(copy(files), 'escape(v:val,"\\;:,")'), ';')
         autocmd BufUnload <buffer> :call s:F.rec.unload(
                     \                               s:bufvars[expand('<abuf>')])
     augroup END
+    if empty(bvar.chars)
+        bwipeout!
+    endif
 endfunction
 let s:_augroups+=['AuRecordStatus']
-let s:recfunc['@FWC']=['['.s:repoarg.'] '.
-            \          '{!addremove   :=(0)'.
+let s:recfunc['@FWC']=['{ repo '.s:repoarg.
+            \          ' !addremove   :=(0)'.
             \          ' ?message           type ""'.
             \          ' ?date              type ""'.
             \          ' ?user              type ""'.
             \'\V|*F.comm.getrepo',  '',           ''),
             \'\V+ type ""', '+ (path)', ''))
 "▶3 rec.reset
-function s:F.rec.reset(bvar, msgid)
-    call s:_f.warn(a:msgid)
+function s:F.rec.reset(bvar)
     for idx in range(0, len(a:bvar.lines)-1)
-        call setline(idx+1, s:statchars[a:bvar.statuses[idx]].bvar.lines[idx])
+        call setline(idx+1, s:statchars[a:bvar.statuses[idx]].a:bvar.lines[idx])
     endfor
     let a:bvar.prevct=b:changedtick
     let a:bvar.reset=1
 "▶3 rec.runstatmap
 let s:statchars='-^+*'
 function s:F.rec.runstatmap(action)
+    "▶4 buf, bvar, reset
     let buf=bufnr('%')
     let bvar=s:bufvars[buf]
     setlocal modifiable noreadonly
     if b:changedtick!=bvar.prevct
-        call s:F.rec.reset(bvar, 'uchngs')
+        call s:_f.warn('uchngs')
+        call s:F.rec.reset(bvar)
         setlocal readonly nomodifiable
         return
     endif
+    "▶4 add/ignore
     if a:action[-3:] is# 'add' || a:action[-6:] is# 'ignore'
         if a:action[0] is# 'v'
             let sline=line("'<")
             endif
             call setline(line, s:statchars[status].bvar.lines[line-1])
         endfor
+    "▶4 discard
     elseif a:action is# 'discard'
         call s:F.rec.unload(bvar)
         return
+    "▶4 undo
     elseif a:action is# 'undo'
         if bvar.reset || undotree().seq_cur<=bvar.startundo
             setlocal readonly nomodifiable
             silent redo
         endif
         " TODO Undo modified files
+    "▶4 redo
     elseif a:action is# 'redo'
         if bvar.reset || undotree().seq_cur<=bvar.startundo
             setlocal readonly nomodifiable
         for line in range(1, line('$'))
             let bvar.statuses[line-1]=stridx(s:statchars, getline(line)[0])
         endfor
+        " TODO Redo modified files
+    "▶4 edit
     elseif a:action is# 'edit'
         let [lwnr, rwnr, swnr]=s:F.rec.getwnrs()
         let file=bvar.lines[line('.')-1][2:]
                 execute swnr.'wincmd w'
                 let status=3
                 let bvar.statuses[line('.')-1]=status
-                call setline('.', s:statchars[status].bvar.lines[line('.')-1])
-                let bvar.prevct=b:changedtick
+                call s:F.rec.reset(bvar)
                 setlocal readonly nomodifiable
                 execute lwnr.'wincmd w'
             else
                 endif
             endif
         endif
+    "▶4 commit
     elseif a:action is# 'commit'
         let epath=escape(bvar.repo.path, ':\')
         let files=filter(copy(bvar.files), 'bvar.statuses[v:key]>1')
-        aboveleft execute 'new' fnameescape('aurum://noop:commit:'.epath.':'.
+        aboveleft execute 'new' fnameescape('aurum://commit:'.epath.':'.
                     \join(map(copy(files), 'escape(v:val, "\\;")'), ';'))
         let cbvar=s:bufvars[bufnr('%')]
-        let cbvar.repo=bvar.repo
-        let cbvar.files=files
         let cbvar.sbvar=bvar
-        call s:_f.mapgroup.map('AuRecordCommit', bufnr('%'))
-        set modifiable noreadonly
         startinsert
         return
     endif
+    "▶4 bvar.prevct, bvar.reset, bvar.undolevels
     if bufnr('%')==buf
         if b:changedtick!=bvar.prevct
             let bvar.prevct=b:changedtick
     let [lwnr, rwnr, swnr]=s:F.rec.getwnrs()
     execute swnr.'wincmd w'
 endfunction
-"▶3 rec.runcommmap
-function s:F.rec.runcommmap(action)
-    let bvar=s:bufvars[bufnr('%')]
-    if a:action is# 'commit'
-        let message=join(getline(1, '$'), "\n")
-        call bvar.repo.functions.commit(bvar.repo, message, bvar.files)
-        call s:F.rec.unload(bvar.sbvar)
-    elseif a:action is# 'discard'
-        call s:F.rec.unload(bvar.sbvar)
-    endif
-endfunction
 "▶3 rec mappings
 function s:F.rec.gm(...)
     return ':<C-u>call call(<SID>Eval("s:F.rec.runstatmap"),'.string(a:000).','.
     return ':<C-u>call call(<SID>Eval("s:F.rec.runleftmap"),'.string(a:000).','.
                 \          '{})<CR>'
 endfunction
-function s:F.rec.gmc(...)
-    return ':<C-u>call call(<SID>Eval("s:F.rec.runcommmap"),'.string(a:000).','.
-                \          '{})<CR>'
-endfunction
 call s:_f.mapgroup.add('AuRecord', {
             \    'add': {'lhs': 'A', 'rhs': s:F.rec.gm('add')    },
             \ 'ignore': {'lhs': 'I', 'rhs': s:F.rec.gm('ignore') },
 call s:_f.mapgroup.add('AuRecordLeft', {
             \   'save': {'lhs': ',A', 'rhs': s:F.rec.gml('save')},
         \}, {'mode': 'n', 'silent': 1, 'dontmap': 1, 'leader': ','})
-call s:_f.mapgroup.add('AuRecordCommit', {
-            \ 'commit': {'lhs': 'C', 'rhs': s:F.rec.gmc('commit') },
-            \'discard': {'lhs': 'X', 'rhs': s:F.rec.gmc('discard')},
-        \}, {'mode': 'n', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶2 comm
+"▶3 comm.reltorepo :: repo, path → rpath
+function s:F.comm.reltorepo(repo, path)
+    return join(s:_r.os.path.split(s:_r.os.path.relpath(a:path,
+                \                                       a:repo.path))[1:], '/')
+endfunction
 "▶3 comm.difftobuffer
 function s:F.comm.difftobuffer(repo, buf, ...)
     let diff=call(a:repo.functions.diff, [a:repo]+a:000, {})
         return 0
     endif
     let repo.type=repotype
-    let repo.functions=s:F[repotype]
+    if !has_key(repo, 'functions')
+        let repo.functions=copy(s:F[repotype])
+    endif
     if !has_key(repo.functions, 'difftobuffer')
         let repo.functions.difftobuffer=s:F.comm.difftobuffer
     endif
+    if !has_key(repo.functions, 'reltorepo')
+        let repo.functions.reltorepo=s:F.comm.reltorepo
+    endif
     return repo
 endfunction
 "▶3 comm.globtopattern :: glob → pattern
         "▶5 Filter out requested files
         call map(csfiles, 'join(s:_r.os.path.split(v:val)[1:], "/")')
         let filelist=[]
-        for pattern in map(split(files, '\v%(\\@<!\\%(\\\\)*)@<!,'),
+        for pattern in map(split(files, '\v%(\\@<!\\%(\\\\)*)@<!;'),
                     \      's:F.comm.globtopattern(v:val)')
             let filelist+=filter(csfiles, 'v:val=~#pattern && '.
                         \                 'index(filelist, v:val)==-1')
         let s:bufvars[buf]={'repo': repo, 'opts': opts,}
         setlocal filetype=aurumstatus bufhidden=wipe
         runtime ftplugin/aurumstatus.vim
+    "▶4 commit command  (repo:files)
+    elseif command is# 'commit'
+        let [repo, files]=s:F.comm.repotuplesplit(tail, 1)
+        let bvar={}
+        let bvar.files=map(split(files, '\v%(\\@<!\\%(\\\\)*)@<!;'),
+                    \      'substitute(v:val, ''\v\\([\;])'', "\\1", "g")')
+        let bvar.repo=repo
+        let s:bufvars[buf]=bvar
+        call s:_f.mapgroup.map('AuCommitMessage', bufnr('%'))
+        setlocal modifiable noreadonly bufhidden=wipe
+        augroup AuCommitMessage
+            autocmd BufWipeOut <buffer>
+                        \ call s:F.comm.runcommap('discard', expand('<abuf>'))
+            autocmd BufWriteCmd <buffer>
+                        \ call s:F.comm.runcommap('commit')
+        augroup END
+        setlocal buftype=acwrite
     "▶4 copy command (file)
     elseif command is# 'copy'
         let fcontents=readfile(tail)
         endif
     endif
 endfunction
+let s:_augroups+=['AuCommitMessage']
+"▶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)
+    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 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': 'n', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶3 glogfunc
 function s:glogfunc.function(repo, opts)
     if type(a:repo)!=type({})
     endif
     new
     if has_key(a:opts, 'files')
-        call map(a:opts.files, 'join('.
-                    \          's:_r.os.path.split('.
-                    \          's:_r.os.path.relpath(v:val, a:repo.path))[1:],'.
-                    \               '"/")')
+        call map(a:opts.files, 'repo.functions.reltorepo(repo, v:val)')
     endif
     let s:bufvars[bufnr('%')]={'repo': a:repo, 'opts': a:opts}
     setlocal filetype=aurumgraphlog bufhidden=wipe
 function s:statfunc.function(repo, opts)
     let opts=[]
     if has_key(a:opts, 'files')
-        call map(a:opts.files, 'join('.
-                    \          's:_r.os.path.split('.
-                    \          's:_r.os.path.relpath(v:val, a:repo.path))[1:],'.
-                    \               '"/")')
+        call map(a:opts.files, 'repo.functions.reltorepo(repo, v:val)')
     endif
     for [key, value] in items(a:opts)
         let opt=key.':'
         execute 'diffsplit '.fnameescape('aurum://file::'.rev2.':'.file)
     endif
 endfunction
+"▶3 comfunc
+function s:comfunc(opts, ...)
+    let files=((a:0)?(a:000):([bufname('%')]))
+    let repo=a:opts.repo
+    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
+    else
+        let files=join(s:_r.os.path.split(s:_r.os.path.relpath(expand('%'),
+                    \                                          repo.path))[1:],
+                    \  '/')
+    endif
+    if has_key(a:opts, 'message')
+        call repo.functions.commit(repo, a:opts.message, files)
+    else
+        let epath=escape(repo.path, ':\')
+        execute 'new' fnameescape('aurum://commit:'.epath.':'.
+                    \             join(map(copy(files), 'escape(v:val, "\\;")'),
+                    \                  ';')
+    endif
+endfunction
+let s:comfunc['@FWC']=['{  repo '.s:repoarg.
+            \          ' *?type      (in [modified added removed deleted '.
+            \                            'uknown ignored] ~start)'.
+            \          '  ?message   (type "")'.
+            \          '}'.
+            \          '+ type ""']
+call add(s:comcomp,
+            \substitute(substitute(s:comfunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''),
+            \'\V+ type ""', '+ (path)', ''))
 "▶3 aubwfunc
 function s:aubwfunc.function()
     let buf=+expand('<abuf>')
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.