Commits

ZyX_I committed e3254b1

Added `read' argument to :AuFile
Made ":" be always the default repository

  • Participants
  • Parent commits 4b8fd98

Comments (0)

Files changed (3)

File plugin/aurum.vim

     " TODO revision completion
     " TODO improve files completion
     " TODO U (update), K and J mappings for aurum://file and aurum://diff
-    " TODO :Au[Read?] (read revision to current buffer) (?: cmd %r)
     " TODO :AuSearch, :AuMove, :Au[Delete?], :AuBrowse
     " TODO {count}K, {count}J
     " TODO Global mappings for most commands
     " TODO aurum#changeset() and aurum#repository()
     " TODO More options
-    " TODO :read aurum://(annotate|status|glog)
     let s:glogfunc={}
     let s:glogcomp=[]
     call s:_f.command.add('AuGlog', s:glogfunc, {'nargs': '*',
     call FraworLoad('@/autocommands')
     let s:auefunc={}
     let s:aubwfunc={}
-    call s:_f.augroup.add('Aurum', [['BufReadCmd',  'aurum://*',0,  s:auefunc],
-                \                   ['FileReadCmd', 'aurum://*',0, [s:auefunc,1]],
-                \                   ['BufDelete',   'aurum://*',0,  s:aubwfunc],
-                \                  ])
+    call s:_f.augroup.add('Aurum',[['BufReadCmd',  'aurum://*',0,[s:auefunc,0]],
+                \                  ['FileReadCmd', 'aurum://*',0,[s:auefunc,1]],
+                \                  ['BufDelete',   'aurum://*',0, s:aubwfunc],
+                \                 ])
     "▲2
     finish
 elseif s:_pluginloaded
             \'recheight': {'default': 0,
             \               'filter': '(if type "" earg _  range 0 inf)'},
         \}
-" XXX There is a code relying on the fact that here exists string `"."' that
-"     is a default argument to getrepo
 let s:patharg='either (path d, match @\v^\w+%(\+\w+)*\V://\v|^\:$@)'
-let s:repoarg=':*F.comm.getrepo(".") ('.s:patharg.
+let s:repoarg=':*F.comm.getrepo(":") ('.s:patharg.
             \                        '|*F.comm.getrepo '.
             \                        '#norepo '.
             \                        'type {})'
-let s:nogetrepoarg=':"." ('.s:patharg.')'
-let s:nogetrepocarg=':":" ('.s:patharg.')'
+let s:nogetrepoarg=':":" ('.s:patharg.')'
 let s:cmds=['new', 'vnew', 'edit',
             \'leftabove vnew', 'rightbelow vnew', 'topleft vnew', 'botright vnew',
             \'aboveleft new',  'belowright new',  'topleft new',  'botright new'
     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 status=repo.functions.status(repo)
         let files=[]
         for [type, files] in items(status)
             if type is# 'clean' || (types isnot 0 && index(types, type)==-1)
     return s:F.com.commit(repo, a:opts, files)
 endfunction
 let s:comfunc['@FWC']=['-onlystrings '.
-            \          '{  repo '.substitute(s:repoarg, '\V"."', '":"', '').
+            \          '{  repo '.s:repoarg.
             \          ' *?type      (in [modified added removed deleted '.
             \                            'uknown ignored] ~start)'.
             \          '  ?message   (type "")'.
             \'discard': {'lhs': 'X', 'rhs': s:F.comm.gmc('discard')},
         \}, {'mode': 'in', 'silent': 1, 'dontmap': 1, 'leader': ','})
 "▶2 comm
+"▶3 comm.setlines
+function s:F.comm.setlines(lines, read)
+    let d={'set': function((a:read)?('append'):('setline'))}
+    if len(a:lines)>1 && empty(a:lines[-1])
+        call d.set('.', a:lines[:-2])
+    else
+        if !a:read
+            setlocal binary noendofline
+        endif
+        call d.set('.', a:lines)
+    endif
+endfunction
 "▶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,
     if oldbuf!=a:buf
         execute 'buffer' a:buf
     endif
-    if len(diff)>1 && empty(diff[-1])
-        call remove(diff, -1)
-    else
-        setlocal binary noendofline
-    endif
-    call setline('.', diff)
+    call s:F.comm.setlines(diff, 0)
     if oldbuf!=a:buf
         execute 'buffer' oldbuf
     endif
         let buf=bufnr('%')
         if has_key(s:bufvars, buf) && has_key(s:bufvars[buf], 'repo')
             let path=s:bufvars[buf].repo.path
-        elseif has_key(s:bufvars, buf) && s:bufvars[buf] is# 'copy'
+        elseif has_key(s:bufvars, buf) && s:bufvars[buf].command is# 'copy'
             let path=s:_r.os.path.dirname(
                         \s:_r.os.path.realpath(s:bufvars[buf].file))
-        elseif empty(expand('%'))
-            let path=s:_r.os.path.realpath('.')
         elseif isdirectory(expand('%:p:h'))
             let path=s:_r.os.path.realpath(expand('%:p:h'))
         else
     return [repo]+strings+[opts]
 endfunction
 "▲3
-function s:auefunc.function(...) abort
+function s:auefunc.function(read) abort
     "▶3 Split <amatch> into command and arguments
     let tail=substitute(expand('<amatch>'), '\V\^aurum://', '', '')
     let command=tolower(matchstr(tail, '\v^\w+'))
                     \     'has_key(opts, v:val)')
             let opts[key]=+opts[key]
         endfor
-        let bvar={'repo': repo, 'opts': opts, 'read': a:0}
+        let bvar={'repo': repo, 'opts': opts, 'read': a:read}
         call s:_r.glog.setup(bvar)
-        if !a:0
+        if !a:read
             let s:bufvars[buf]=bvar
             setlocal filetype=aurumgraphlog bufhidden=wipe
             runtime ftplugin/aurumgraphlog.vim
     "▶3 file command (repo:rev:file)
     elseif command is# 'file'
         let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
-        let fcontents=repo.functions.readfile(repo, rev, file)
-        if len(fcontents)>1 && empty(fcontents[-1])
-            call remove(fcontents, -1)
-        else
-            setlocal binary noendofline
+        call s:F.comm.setlines(repo.functions.readfile(repo, rev, file), a:read)
+        if !a:read
+            let s:bufvars[buf]={'repo': repo, 'rev': rev, 'file': file}
         endif
-        if a:0
-            call append('.', fcontents)
-        else
-            call setline('.', fcontents)
-        endif
-        let s:bufvars[buf]={'repo': repo, 'rev': rev, 'file': file}
     "▶3 annotate command (repo:rev:file)
     elseif command is# 'annotate'
         let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
-        let bvar={'repo': repo, 'rev': rev, 'file': file, 'read': a:0}
+        let bvar={'repo': repo, 'rev': rev, 'file': file, 'read': a:read}
         call s:_r.annotate.setup(bvar)
-        if !a:0
+        if !a:read
             let s:bufvars[buf]=bvar
             setlocal filetype=aurumannotate bufhidden=wipe
             runtime ftplugin/aurumannotate.vim
                     \    'substitute(v:val, ''\v\\([\\;:])'', "\\1", "g")')
         " XXX All options should be from s:diffoptslst list
         call map(opts, '+v:val')
-        let s:bufvars[buf]={'repo': repo, 'rev1': rev1, 'rev2': rev2,
-                    \       'files': filelist, 'opts': opts}
-        if a:0
-            call append('.', repo.functions.diff(repo, rev1, rev2, filelist, opts))
+        if a:read
+            call s:F.comm.setlines(repo.functions.diff(repo, rev1, rev2,
+                        \                              filelist, opts), 1)
         else
-            call repo.functions.difftobuffer(repo, buf, rev1, rev2, filelist, opts)
+            let s:bufvars[buf]={'repo': repo, 'rev1': rev1, 'rev2': rev2,
+                        \       'files': filelist, 'opts': opts}
+            call repo.functions.difftobuffer(repo, buf, rev1, rev2,
+                        \                    filelist, opts)
             setlocal filetype=diff
         endif
     "▶3 status command (repo:opts)
         for key in filter(['rev1', 'rev2'], 'has_key(opts, v:val)')
             let opts[key]=repo.functions.getrevhex(repo, opts[key])
         endfor
-        let bvar={'repo': repo, 'opts': opts, 'read': a:0}
+        let bvar={'repo': repo, 'opts': opts, 'read': a:read}
         call s:_r.status.setup(bvar)
-        if !a:0
+        if !a:read
             let s:bufvars[buf]=bvar
             setlocal filetype=aurumstatus bufhidden=wipe
             runtime ftplugin/aurumstatus.vim
         endif
     "▶3 commit command  (repo:user:date:files)
     elseif command is# 'commit'
-        if a:0
+        if a:read
             call s:_f.throw('nocread')
         endif
         let [repo, user, date, cb, files]=s:F.comm.repotuplesplit(tail, 4)
         setlocal buftype=acwrite
     "▶3 copy command (file)
     elseif command is# 'copy'
-        let fcontents=readfile(tail)
-        if len(fcontents)>1 && empty(fcontents[-1])
-            call remove(fcontents, -1)
-        else
-            setlocal binary noendofline
+        call s:F.comm.setlines(readfile(tail, 'b'), a:read)
+        if !a:read
+            let s:bufvars[buf]={'file': tail}
         endif
-        if a:0
-            call append('.', fcontents)
-        else
-            call setline('.', fcontents)
-        endif
-        let s:bufvars[buf]={'file': tail}
     "▶3 Unknown command
     else
         return
     endif
     "▲3
-    let s:bufvars[buf].command=command
+    if !a:read
+        let s:bufvars[buf].command=command
+    endif
     file
 endfunction
 let s:_augroups+=['AuCommitMessage']
     endif
 endfunction
 let s:annfunc['@FWC']=['-onlystrings'.
-            \          '{  repo  '.s:nogetrepocarg.
+            \          '{  repo  '.s:nogetrepoarg.
             \          '  ?file  type ""'.
             \          '  ?rev   type ""'.
             \          '}', 'filter']
     endif
 endfunction
 let s:vimdfunc['@FWC']=['-onlystrings '.
-            \           '{  repo  '.s:nogetrepocarg.
+            \           '{  repo  '.s:nogetrepoarg.
             \           '  ?file  type ""'.
             \           ' !?curfile'.
             \           '}'.
                 \                         ':'.efiles.':'.opts)
 endfunction
 let s:difffunc['@FWC']=['-onlystrings '.
-            \           '{  repo  '.substitute(s:repoarg, '\V"."', '":"', '').
+            \           '{  repo  '.s:repoarg.
             \           '  ?rev1  type ""'.
             \           '  ?rev2  type ""'.
             \           s:diffoptsstr.
         return
     endif
     let rev=repo.functions.getrevhex(repo, a:rev)
+    if get(a:opts, 'read', 0)
+        call s:F.comm.setlines(repo.functions.readfile(repo, rev, file), 0)
+        return
+    endif
     let epath=escape(repo.path, ':\')
     execute get(a:opts, 'cmd', 'silent edit')
                 \ fnameescape('aurum://file:'.epath.':'.rev.':'.file)
 let s:filefunc['@FWC']=['-onlystrings '.
             \           '[:"."    type "" '.
             \           '[:=(0)   either (match /\L/, path fr)]]'.
-            \           '{ repo '.s:nogetrepocarg.
-            \           ' ?cmd    type ""}', 'filter']
+            \           '{  repo '.s:nogetrepoarg.
+            \           ' !?read'.
+            \           '  ?cmd    type ""}', 'filter']
 call add(s:filecomp,
             \substitute(substitute(s:filefunc['@FWC'][0],
             \'\V:=(0)\v\s+type\s*\V""', 'path', ''),

File test/file.in

 :AuFile 5 testrepo/dlines.lst repo testrepo
 :call WriteFile(bufname('%'), 'w$: '.winnr('$'))
 :AuFile 6 cmd silent\ vsplit
-:call WriteFile(bufname('%'), 'w$: '.winnr('$'))
+:call WriteFile(bufname('%'), 'w$: '.winnr('$').'; l$: '.line('$'))
+:set noreadonly
+:AuFile 5 testrepo/chgrepo.zsh read
+:call WriteFile(bufname('%'), 'l$: '.line('$'))
 :source addmessages.vim

File test/file.ok

 aurum://file:%TMPDIR%/test/testrepo:c5d978071bc74635267df368a498d81f4ca03e27:dlines.lst
 w$: 1
 aurum://file:%TMPDIR%/test/testrepo:ad9ef3ae5da7f0af0f413dc9b0bbbccc73195c73:dlines.lst
-w$: 2
+w$: 2; l$: 52
+aurum://file:%TMPDIR%/test/testrepo:ad9ef3ae5da7f0af0f413dc9b0bbbccc73195c73:dlines.lst
+l$: 94