Commits

ZyX_I committed 239c019

Made it possible to write to aurum://commit (untested)

Comments (0)

Files changed (4)

ftplugin/aurumcommit.vim

             \                    '@/mappings': '0.0',
             \                 '@aurum/commit': '0.0',})
 "▶1 com.runcommap
-function s:F.runcommap(action, ...)
-    let buf=get(a:000, 0, bufnr('%'))
+function s:F.runcommap(action)
+    let buf=bufnr('%')
     let bvar=s:_r.bufvars[buf]
     if a:action is# 'commit'
         call s:_r.commit.finish(bvar)
-        if !a:0
-            bwipeout!
-            stopinsert
-        endif
     elseif a:action is# 'discard'
-        if !a:0
-            bwipeout!
-            stopinsert
-        endif
+        bwipeout!
+        stopinsert
     endif
     if has_key(bvar, 'sbvar')
         call bvar.sbvar.recunload(bvar.sbvar)

plugin/aurum/commit.vim

     call a:bvar.repo.functions.commit(a:bvar.repo, message, a:bvar.files,
                 \                     a:bvar.user, a:bvar.date,
                 \                     a:bvar.closebranch)
+    call feedkeys("\<C-\>\<C-n>:bwipeout!\n")
 endfunction
 "▶1 commfunc
 function s:commfunc.function(opts, ...)
     if a:read
         call s:_f.throw('nocread')
     endif
-    augroup AuCommitMessage
-        autocmd BufWriteCmd <buffer>
-                    \  call s:F.finish(s:_r.bufvars[expand('<abuf>')])
-                    \| call feedkeys("\<C-\>\<C-n>:bwipeout!\n")
-    augroup END
-    setlocal buftype=acwrite
     return {'user': a:user, 'date': a:date, 'files': a:files,
-                \'closebranch': !!a:cb}
+                \'closebranch': !!a:cb, 'write': s:F.finish,}
+endfunction
+function s:commit.write(lines, repo, user, date, cb, files)
+    let message=join(filter(copy(a:lines), 'v:val[0] isnot# "#"'), "\n")
+    call a:repo.functions.commit(a:repo, message, a:files, a:user, a:date, a:cb)
 endfunction
 call s:_f.newcommand(s:commit)
 "▶1 Post resource

plugin/aurum/edit.vim

     call FraworLoad('@/autocommands')
     call FraworLoad('@/functions')
     let s:auefunc={}
-    call s:_f.augroup.add('Aurum',[['BufReadCmd',  'aurum://*',0,[s:auefunc,0]],
-                \                  ['FileReadCmd', 'aurum://*',0,[s:auefunc,1]],
-                \                 ])
+    call s:_f.augroup.add('Aurum',
+                \[['BufReadCmd',   'aurum://*', 0, [s:auefunc,  0]],
+                \ ['FileReadCmd',  'aurum://*', 0, [s:auefunc,  1]],
+                \ ['BufWriteCmd',  'aurum://*', 0, [s:auefunc, -1]],
+                \ ['FileWriteCmd', 'aurum://*', 0, [s:auefunc, -2]],
+                \])
     finish
 elseif s:_pluginloaded
     finish
 let s:commands={}
 let s:_messages={
             \'ucmd': 'Unknown command: %s',
+            \ 'nwr': 'Write feature is not implemented for command %s',
         \}
 call extend(s:_messages, map({
             \'creg': 'command was already registered by plugin %s',
     let tail=a:str
     let repopath=matchstr(tail, '\v^[^:]+')
     let tail=tail[len(repopath)+1:]
-    let repo=s:_r.repo.get(s:_r.cmdutils.unescape(repopath))
-    if repo is 0
-        call s:_f.throw('nrepo', repopath)
-    endif
-    let r=[repo]
+    let r=[repopath]
     let i=0
     while i<a:num-1
         let chunk=matchstr(tail, '\v^[^:]+')
             \ 'str': 's:_r.cmdutils.unescape(opts[o])',
         \}
 " FIXME This code is creating repository object for the second time
-function s:auefunc.function(read)
+function s:auefunc.function(rw)
     " XXX On windows all forward slashes are transformed to backward in @%,
     "     all backward are transformed to forward in <amatch>
-    let tail=expand('<amatch>')[len('aurum://'):]
+    let buf=expand('<abuf>')
+    let amatch=expand('<amatch>')
+    let tail=amatch[len('aurum://'):]
     let command=tolower(matchstr(tail, '\v^\w+'))
     let tail=tail[len(command)+1:]
-    if command is# 'copy'
-        return s:F.copy(a:read, tail)
+    if command is# 'copy' && a:rw>=0
+        return s:F.copy(a:rw, tail)
     endif
     if !has_key(s:commands, command)
         call FraworLoad('@aurum/'.command)
             call s:_f.throw('ucmd', command)
         endif
     endif
+    "▶2 Launch bvar.write if applicable
+    if a:rw==-1 && has_key(s:_r.bufvars,buf)            &&
+                \  has_key(s:_r.bufvars[buf], 'amatch') &&
+                \  has_key(s:_r.bufvars[buf], 'write')  &&
+                \          s:_r.bufvars[buf].amatch is# amatch
+        return s:_r.bufvars[buf].write(s:_r.bufvars[buf])
+    endif
+    "▲2
     let cdescr=s:commands[command]
     let arguments=get(cdescr, 'arguments', 0)
     let argnum=arguments+get(cdescr, 'listargs', 0)
     let hasopts=has_key(cdescr, 'options')
     let fname='repotuple'.((hasopts)?('opts'):('')).'split'
     let args=s:F[fname](tail, argnum)
+    "▶2 Get string arguments
     for i in range(1, arguments)
         let args[i]=s:_r.cmdutils.unescape(args[i])
     endfor
+    "▶2 Get list arguments
     if argnum>arguments
         for i in range(arguments+1, argnum)
             let args[i]=map(split(args[i],';'), 's:_r.cmdutils.unescape(v:val)')
         endfor
     endif
+    "▶2 Get options
     if hasopts
         let opts=remove(args, -1)
         let newopts={}
         endfor
         call add(args, newopts)
     endif
-    if !a:read
+    "▶2 Get repository
+    let repo=s:_r.repo.get(s:_r.cmdutils.unescape(args[0]))
+    if repo is 0
+        call s:_f.throw('nrepo', args[0])
+    endif
+    let args[0]=repo
+    "▲2
+    if a:rw==0
         setlocal modifiable noreadonly
     endif
-    let bvar=call(cdescr.function, [a:read]+args, {})
-    if !a:read
-        let buf=bufnr('%')
-        if has_key(s:_r.bufvars, buf) &&
-                    \has_key(s:_r.bufvars[buf], 'prevbuf')
-            let bvar.prevbuf=s:_r.bufvars[buf].prevbuf
+    if a:rw<0
+        if a:rw==-1
+            let lines=getline(1, '$')
+        else
+            let lines=getline("'[", "']")
         endif
-        if !get(cdescr, 'modifiable', 0)
-            setlocal buftype=nofile nomodifiable readonly
+        call call(cdescr.write, [call('getline', ((a:rw==-1)?([ 1,   '$' ]):
+                    \                                        (["'[", "']"])))]+
+                    \                            args)
+    else
+        let bvar=call(cdescr.function, [a:rw]+args, {})
+        if a:rw==0
+            if has_key(s:_r.bufvars, buf) &&
+                        \has_key(s:_r.bufvars[buf], 'prevbuf')
+                let bvar.prevbuf=s:_r.bufvars[buf].prevbuf
+            endif
+            if !get(cdescr, 'modifiable', 0)
+                setlocal buftype=nofile nomodifiable readonly
+            endif
+            let bvar.amatch=amatch
+            let bvar.command=command
+            let bvar.repo=args[0]
+            if hasopts
+                let bvar.opts=args[-1]
+            endif
+            let s:_r.bufvars[buf]=bvar
+            if has_key(cdescr, 'filetype')
+                let &l:filetype=cdescr.filetype
+                execute 'runtime! ftplugin/'.cdescr.filetype.'.vim'
+            endif
+            file
         endif
-        let bvar.command=command
-        let bvar.repo=args[0]
-        if hasopts
-            let bvar.opts=args[-1]
-        endif
-        let s:_r.bufvars[buf]=bvar
-        if has_key(cdescr, 'filetype')
-            let &l:filetype=cdescr.filetype
-            execute 'runtime! ftplugin/'.cdescr.filetype.'.vim'
-        endif
-        file
     endif
 endfunction
 "▶1 newcommand :: {f}, cdescr → + s:commands
         call s:_f.throw('nfun', cname, a:plugdict.id, 'function')
     endif
     let cdescr={'function': a:cdescr.function}
+    "▶2 Numeric (natural numbers) keys: arguments, listargs
     for key in filter(['arguments', 'listargs'],
                 \     'has_key(a:cdescr, v:val)')
         if type(a:cdescr[key])!=type(0) || a:cdescr[key]<=0
         endif
         let cdescr[key]=a:cdescr[key]
     endfor
+    "▶2 Boolean keys: modifiable
     if has_key(a:cdescr, 'modifiable')
         if type(a:cdescr.modifiable)!=type(0)
             call s:_f.throw('nbl')
         endif
         let cdescr.modifiable=(!!a:cdescr.modifiable)
     endif
+    "▶2 `options' dictionary
     if has_key(a:cdescr, 'options')
         if type(a:cdescr.options)!=type({})
             call s:_f.throw('odct', cname, a:plugdict.id)
                         \                  'index(cdescr.okeys, v:val)!=-1')
         endif
     endif
+    "▶2 `filetype' key
     if has_key(a:cdescr, 'filetype')
         if type(a:cdescr.filetype)!=type('')
             call s:_f.throw('nstr', cname, a:plugdict.id, 'filetype')
         endif
         let cdescr.filetype=a:cdescr.filetype
     endif
+    "▶2 Function keys: `write'
+    if has_key(a:cdescr, 'write')
+        if !exists('*a:cdescr.write')
+            call s:_f.throw('nfun', cname, a:plugdict.id, 'write')
+        endif
+        let cdescr.write=a:cdescr.write
+    endif
+    "▲2
     let cdescr.id=cname
     let cdescr.plid=a:plugdict.id
     let s:commands[cname]=cdescr

plugin/aurum/record.vim

             \           'function available',
             \ 'recnof': 'No files were selected for commiting',
         \}
+"▶1 write
+function s:F.write(bvar)
+    call feedkeys("\<C-\>\<C-n>:call ".
+            \      "call(<SNR>".s:_sid."_Eval('s:F.runstatmap'), ".
+            \           "['commit', ".expand('<abuf>')."], {})\n", 'n')
+endfunction
 "▶1 recfunc
 " TODO investigate why closing record tab is causing next character consumption
 "      under wine
     let bvar.bwfunc=s:F.unload
     let bvar.getwnrs=s:F.getwnrs
     let bvar.recrunmap=s:F.runstatmap
+    let bvar.write=s:F.write
     if !bvar.startundo
         setlocal undolevels=-1
     endif
-    augroup AuRecordStatus
-        " XXX Workaround for the fact that current window is restored after
-        "     autocommand exits
-        autocmd BufWriteCmd <buffer>
-                    \ :call feedkeys("\<C-\>\<C-n>:call ".
-                    \      "call(<SNR>".s:_sid."_Eval('s:F.runstatmap'), ".
-                    \           "['commit', ".expand('<abuf>')."], {})\n", 'n')
-    augroup END
-    setlocal buftype=acwrite noreadonly
+    setlocal noreadonly buftype=acwrite
     if empty(bvar.chars)
         bwipeout!
     endif
 endfunction
-let s:_augroups+=['AuRecordStatus']
 " XXX options message, user, date and closebranch are used by com.commit
 " XXX documentation says that options are the same as for `:AuCommit' except for 
 " `type' option
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.