Commits

ZyX_I  committed f3aff78

@aurum/edit, @aurum/repo: Made aurum:// events support various ++opts

  • Participants
  • Parent commits a1b577f

Comments (0)

Files changed (4)

File doc/aurum.txt

     2.2: Added |aurum-repo.initprops|.
     2.3: Added |aurum-rf-getroot| support.
     2.4: Added {requiresclean} argument to |aurum-rf-status|.
+    2.5: Added parsecmdarg and crnl resources
 @aurum:
     0.1: Added :AuBranch and :AuName.
 @aurum/edit:

File plugin/aurum/drivers/git.vim

 " Convert between lines (NL separated strings with NULLs represented as NLs) and 
 " NULL separated strings with NLs represented by NLs.
 function s:F.nullnl(text)
-    let r=[]
-    for line in a:text
-        let nlsplit=split(line, "\n", 1)
-        if empty(r)
-            call extend(r, nlsplit)
-        else
-            let r[-1].="\n".nlsplit[0]
-            call extend(r, nlsplit[1:])
-        endif
+    let r=['']
+    for nlsplit in map(copy(a:text), 'split(v:val, "\n", 1)')
+        let r[-1].="\n".nlsplit[0]
+        call extend(r, nlsplit[1:])
     endfor
+    if empty(r[0])
+        call remove(r, 0)
+    else
+        let r[0]=r[0][1:]
+    endif
     return r
 endfunction
 "▶1 git.status :: repo[, rev1[, rev2[, files[, clean]]]]

File plugin/aurum/edit.vim

     execute frawor#Setup('1.1', {'@/autocommands': '0.0',
                 \                   '@/functions': '0.0',
                 \                   '@/resources': '0.0',
-                \                   '@aurum/repo': '2.0',
+                \                   '@aurum/repo': '2.5',
                 \                '@aurum/bufvars': '0.0',}, 0)
     call FraworLoad('@/autocommands')
     call FraworLoad('@/functions')
         endif
     endif
 endfunction
+"▶1 getopts :: Bool → Dictionary
+function s:F.getopts()
+    let r=s:_r.parsecmdarg()
+    if !has_key(r, 'b')
+        let r.b=&binary
+    endif
+    if !has_key(r, 'e') && !empty(&fileencoding)
+        let r.e=&fileencoding
+    endif
+    if has_key(r, 'e') && r.e is# &encoding
+        unlet r.e
+    endif
+    if !has_key(r, 'f')
+        let r.f=&fileformat
+    endif
+    return r
+endfunction
+"▶1 wtransform :: [String] → [String] +? [String]
+function s:F.wtransform(lines)
+    let r=a:lines
+    let a=s:F.getopts()
+    if a.b
+        if &endofline
+            call add(r, '')
+        endif
+    else
+        call add(r, '')
+        if a.f is# 'dos'
+            call map(r, 'v:val."\n"')
+        elseif a.f is# 'mac'
+            let r=s:_r.crnl(r)
+        endif
+    endif
+    if has_key(a, 'e')
+        call map(r, 'iconv(v:val, "'.&encoding.'","'.(a.e).'")')
+    endif
+    return r
+endfunction
 "▶1 edit
 function s:F.edit(rw, file)
     if a:rw>=0
             let s:_r.bufvars[bufnr('%')]={'file': a:file, 'command': 'edit'}
         endif
     elseif a:rw==-1
-        let lines=getline(1, '$')
-        if &binary
-            if &endofline
-                let lines+=['']
-            endif
-        else
-            let lines+=['']
-            if &fileformat is# 'dos'
-                call map(lines, 'v:val."\n"')
-            elseif &fileformat is# 'mac'
-                let lines=[join(lines, "\r")]
-            endif
-        endif
-        if !empty(&fileencoding) && &encoding isnot# &fileencoding
-            call map(lines, 'iconv(v:val, "'.&encoding.'","'.&fileencoding.'")')
-        endif
-        call writefile(lines, a:file, 'b')
+        call writefile(s:F.wtransform(getline(1, '$')), a:file, 'b')
         setlocal nomodified
     endif
 endfunction
         setlocal modifiable noreadonly
     endif
     if a:rw<0
-        call call(cdescr.write, [call('getline', ((a:rw==-1)?([ 1,   '$' ]):
-                    \                                        (["'[", "']"])))]+
-                    \                            args, {})
+        call call(cdescr.write,
+                    \[s:F.wtransform(call('getline', ((a:rw==-1)?
+                    \                                   ([ 1,   '$' ]):
+                    \                                   (["'[", "']"]))))]+
+                    \args, {})
     else
         let args=[a:rw]+args
         if a:rw==0

File plugin/aurum/repo.vim

 "▶1
 scriptencoding utf-8
 if !exists('s:_pluginloaded')
-    execute frawor#Setup('2.4', {'@/resources': '0.0',
+    execute frawor#Setup('2.5', {'@/resources': '0.0',
                 \                       '@/os': '0.0',
                 \                  '@/options': '0.0',
                 \             '@aurum/bufvars': '0.0',}, 0)
 endfunction
 "▶2 changesets
 let s:iterfuncs.changesets=s:iterfuncs.revrange
+"▶1 crnl :: [String] → [String]
+function s:F.crnl(text)
+    let r=['']
+    for crsplit in map(copy(a:text), 'split(v:val, "\r", 1)')
+        let r[-1].="\r".crsplit[0]
+        call extend(r, crsplit[1:])
+    endfor
+    if empty(r[0])
+        call remove(r, 0)
+    else
+        let r[0]=r[0][1:]
+    endif
+    return r
+endfunction
+"▶1 parsecmdarg :: + v:cmdarg + opts → Dictionary
+function s:F.parsecmdarg()
+    let r={}
+    for arg in filter(split(v:cmdarg),
+                \     'v:val =~# ''\V\^++\v%(%(enc|ff)\=|%(no)bin)''')
+        let idx=stridx(arg, '=')
+        let r[arg[2]]=arg[(idx+1):]
+    endfor
+    if has_key(r, 'b')
+        let r.b=1
+    elseif has_key(r, 'n')
+        let r.b=0
+        unlet r.n
+    endif
+    return r
+endfunction
 "▶1 setlines :: [String], read::Bool → + buffer
 function s:F.setlines(lines, read)
+    let lines=a:lines
+    if !empty(v:cmdarg)
+        let a=s:F.parsecmdarg()
+        if has_key(a, 'f') && !(has_key(a, 'b') && a.b) && !&binary
+            if a.f is# 'dos'
+                let lines=map(copy(lines), 'v:val[-1:] is# "\r" ? '.
+                            \                   'v:val[:-2] : '.
+                            \                   'v:val')
+            elseif a.f is# 'mac'
+                let lines=s:F.crnl(lines)
+            endif
+            if !a:read
+                let &l:fileformat=a.f
+            endif
+        endif
+        if has_key(a, 'e')
+            let lines=map(copy(lines), 'iconv(v:val, "'.(a.e).'", "'.&enc.'")')
+            if !a:read
+                let &l:fileencoding=a.e
+            endif
+        endif
+        if !a:read && has_key(a, 'b')
+            let &l:binary=a.b
+        endif
+    endif
     let d={'set': function((a:read)?('append'):('setline'))}
-    if len(a:lines)>1 && empty(a:lines[-1])
-        call d.set('.', a:lines[:-2])
+    if len(lines)>1 && empty(lines[-1])
+        call d.set('.', lines[:-2])
     else
         if !a:read
             setlocal binary noendofline
         endif
-        call d.set('.', a:lines)
+        call d.set('.', lines)
     endif
 endfunction
 "▶1 dirty :: repo, file → Bool
             \                'update': s:F.update,
             \           'diffoptslst': s:diffoptslst,
             \           'diffoptsstr': s:diffoptsstr,})
-call s:_f.postresource('setlines', s:F.setlines)
+call s:_f.postresource('crnl',        s:F.crnl)
+call s:_f.postresource('parsecmdarg', s:F.parsecmdarg)
+call s:_f.postresource('setlines',    s:F.setlines)
 "▶1 regdriver feature
 let s:requiredfuncs=['repo', 'getcs', 'checkdir']
 let s:optfuncs=['readfile', 'annotate', 'diff', 'status', 'commit', 'update',