Commits

ZyX_I committed 8ae821f

Switched model of using `@aurum/edit': aurum://{command} handlers are now registered by plugin depending on @aurum/edit, not by @aurum/edit that depends on plugins with aurum://{command} handlers

  • Participants
  • Parent commits b6a96de

Comments (0)

Files changed (8)

File doc/aurum.txt

 ------------------------------------------------------------------------------
 2.3. aurum:// pseudo-protocol                                       *aurum://*
 
-Aurum provides a number of things that can be opened or read using filenames 
+Aurum provides a number of commands that can be opened or read using filenames 
 starting with aurum://. Some things you should know:
 - If pseudo-protocol supports more then one argument, in all but last 
   arguments colons and backslashes should be escaped. In a last argument you 

File plugin/aurum/annotate.vim

     execute frawor#Setup('0.0', {'@/table': '0.1',
                 \        '@aurum/cmdutils': '0.0',
                 \         '@aurum/bufvars': '0.0',
+                \            '@aurum/edit': '0.0',
                 \                  '@/fwc': '0.3',
                 \             '@/commands': '0.0',
                 \            '@/functions': '0.0',
             \substitute(substitute(s:annfunc['@FWC'][0],
             \'\vfile\s+type\s*\V""', 'file path',          ''),
             \'\vrev\s+type\s*\V""',  'rev '.s:_r.comp.rev, ''))
-"▶1 post resource
-let s:annotate={'function': s:F.setup,
-            \  'arguments': 2,
-            \   'filetype': 'aurumannotate',}
-" XXX
-let s:annotate.setannbuf=s:F.setannbuf
-call s:_f.postresource('annotate', s:annotate)
+"▶1 aurum://annotate
+call s:_f.newcommand({
+            \'function': s:F.setup,
+            \ 'arguments': 2,
+            \  'filetype': 'aurumannotate',})
+"▶1 Post resource
+call s:_f.postresource('annotate', {'setannbuf': s:F.setannbuf})
 "▶1
 call frawor#Lockvar(s:, '_r,_pluginloaded')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/commit.vim

                 \              '@aurum/status': '0.0',
                 \            '@aurum/cmdutils': '0.0',
                 \             '@aurum/bufvars': '0.0',
+                \                '@aurum/repo': '0.0',
+                \                '@aurum/edit': '0.0',
                 \                      '@/fwc': '0.3',
-                \                '@aurum/repo': '0.0',
                 \                 '@/commands': '0.0',
                 \                '@/functions': '0.0',}, 0)
     call FraworLoad('@/commands')
             \substitute(substitute(s:commfunc['@FWC'][0],
             \'\V|*_r.repo.get',  '',         ''),
             \'\V+ type ""',      '+ (path)', ''))
-"▶1 Post resource
+"▶1 aurum://commit
 let s:commit={'arguments': 3,
             \  'listargs': 1,
             \'modifiable': 1,
             \  'filetype': 'aurumcommit',
             \}
-" XXX
-let s:commit.commit=s:F.commit
-let s:commit.finish=s:F.finish
 function s:commit.function(read, repo, user, date, cb, files)
     if a:read
         call s:_f.throw('nocread')
     return {'user': a:user, 'date': a:date, 'files': a:files,
                 \'closebranch': !!a:cb}
 endfunction
-call s:_f.postresource('commit', s:commit)
+call s:_f.newcommand(s:commit)
+"▶1 Post resource
+call s:_f.postresource('commit', {'commit': s:F.commit,
+            \                     'finish': s:F.finish,})
 "▶1
 call frawor#Lockvar(s:, '_r,_pluginloaded')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/diff.vim

     execute frawor#Setup('0.0', {'@aurum/cmdutils': '0.0',
                 \                 '@aurum/bufvars': '0.0',
                 \                    '@aurum/repo': '0.0',
+                \                    '@aurum/edit': '0.0',
                 \                           '@/os': '0.0',
                 \                          '@/fwc': '0.0',
-                \                    '@/resources': '0.0',
                 \                     '@/mappings': '0.0',
                 \                     '@/commands': '0.0',
                 \                    '@/functions': '0.0',}, 0)
         return {'rev1': rev1, 'rev2': rev2, 'files': a:files}
     endif
 endfunction
-call s:_f.postresource('diff', s:diff)
+call s:_f.newcommand(s:diff)
+unlet s:diff
 "▶1
 call frawor#Lockvar(s:, '_r,_pluginloaded')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/edit.vim

     execute frawor#Setup('0.0', {'@/autocommands': '0.0',
                 \                   '@/functions': '0.0',
                 \                   '@aurum/repo': '0.0',
-                \                    '@aurum/log': '0.0',
-                \                   '@aurum/file': '0.0',
-                \                   '@aurum/diff': '0.0',
-                \                 '@aurum/status': '0.0',
-                \                 '@aurum/commit': '0.0',
-                \               '@aurum/annotate': '0.0',
                 \               '@aurum/cmdutils': '0.0',
                 \                '@aurum/bufvars': '0.0',}, 0)
     call FraworLoad('@/autocommands')
 let s:_messages={
             \'ucmd': 'Unknown command: %s',
         \}
-"▶1 commands
-for s:cmd in ['log', 'file', 'annotate', 'status', 'diff', 'commit']
-    let s:commands[s:cmd]=s:_r[s:cmd]
-endfor
-unlet s:cmd
+call extend(s:_messages, map({
+            \'creg': 'command was already registered by plugin %s',
+            \'ndct': 'command description is not a dictionary',
+            \'mfun': '`function'' key is missing',
+            \'nfun': 'value of key `%s'' must be a callable function reference',
+            \'odct': 'key `options'' is not a dictionary',
+            \'nnum': 'key `%s'' is not a natural number',
+            \ 'nbl': 'key `%s'' is not 1 or 0',
+            \'nlst': 'key `%s'' is not a list of strings',
+            \'nstr': 'key `%s'' is not a string',
+            \ 'ift': 'invalid filetype: `%s'' '.
+            \        '(only lowercase latin letters allowed)',
+            \ 'dup': 'string `%s'' from key `%s'' was already listed',
+        \}, '"Error while registering command %s for plugin %s: ".v:val'))
 "▶1 copy
 function s:F.copy(read, file)
     call s:_r.cmdutils.setlines(readfile(a:file, 'b'), a:read)
         return s:F.copy(a:read, tail)
     endif
     if !has_key(s:commands, command)
-        call s:_f.throw('ucmd', command)
+        call FraworLoad('@aurum/'.command)
+        if !has_key(s:commands, command)
+            call s:_f.throw('ucmd', command)
+        endif
     endif
     let cdescr=s:commands[command]
     let arguments=get(cdescr, 'arguments', 0)
         file
     endif
 endfunction
+"▶1 newcommand :: {f}, cdescr → + s:commands
+function s:F.newcommand(plugdict, fdict, cdescr)
+    let cname=a:plugdict.id[strridx(a:plugdict.id, '/')+1:]
+    if has_key(s:commands, cname)
+        call s:_f.throw('creg', cname, a:plugdict.id, s:commands[cname].plid)
+    elseif type(a:cdescr)!=type({})
+        call s:_f.throw('ndct', cname, a:plugdict.id)
+    elseif !has_key(a:cdescr, 'function')
+        call s:_f.throw('mfun', cname, a:plugdict.id)
+    elseif !exists('*a:cdescr.function')
+        call s:_f.throw('nfun', cname, a:plugdict.id, 'function')
+    endif
+    let cdescr={'function': a:cdescr.function}
+    for key in filter(['arguments', 'listargs'],
+                \     'has_key(a:cdescr, v:val)')
+        if type(a:cdescr[key])!=type(0) || a:cdescr[key]<=0
+            call s:_f.throw('nnum', cname, a:plugdict.id, key)
+        endif
+        let cdescr[key]=a:cdescr[key]
+    endfor
+    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
+    if has_key(a:cdescr, 'options')
+        if type(a:cdescr.options)!=type({})
+            call s:_f.throw('odct', cname, a:plugdict.id)
+        endif
+        let cdescr.options={}
+        let cdescr.okeys=[]
+        for key in filter(['list', 'bool', 'num', 'str'],
+                    \     'has_key(a:cdescr.options, v:val)')
+            if type(a:cdescr.options[key])!=type([]) ||
+                        \!empty(filter(copy(a:cdescr.options[key]),
+                        \       'type(v:val)!='.type('')))
+                call s:_f.throw('nlst', cname, a:plugdict.id, key)
+            endif
+            let cdescr.options[key]=[]
+            for v in a:cdescr.options[key]
+                if index(cdescr.okeys, key)!=-1
+                    call s:_f.throw('dup', cname, a:plugdict.id, v, key)
+                endif
+                let cdescr.options[key]+=[v]
+                let cdescr.okeys+=[v]
+            endfor
+        endfor
+        if has_key(a:cdescr.options, 'pats')
+            let cdescr.options.pats=filter(copy(a:cdescr.options.pats),
+                        \                  'index(cdescr.okeys, v:val)!=-1')
+        endif
+    endif
+    if has_key(a:cdescr, 'filetype')
+        if type(a:cdescr.filetype)!=type('')
+            call s:_f.throw('nstr', cname, a:plugdict.id, 'filetype')
+        elseif a:cdescr.filetype!~#'\v^\l+$'
+            call s:_f.throw('ift', cname, a:plugdict.id, a:cdescr.filetype)
+        endif
+        let cdescr.filetype=a:cdescr.filetype
+    endif
+    let cdescr.id=cname
+    let cdescr.plid=a:plugdict.id
+    let s:commands[cname]=cdescr
+endfunction
+"▶1 delcommand :: {f} → + s:commands
+function s:F.delcommand(plugdict, fdict)
+    let cname=a:plugdict.id[strridx(a:plugdict.id, '/')+1:]
+    if has_key(s:commands, cname)
+        unlet s:commands[cname]
+    endif
+endfunction
+"▶1 Register feature
+call s:_f.newfeature('newcommand', {'cons': s:F.newcommand,
+            \                     'unload': s:F.delcommand,})
 "▶1
-call frawor#Lockvar(s:, '_pluginloaded,_r')
+call frawor#Lockvar(s:, '_pluginloaded,_r,commands')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/file.vim

                 \                 '@aurum/bufvars': '0.0',
                 \                 '@aurum/vimdiff': '0.0',
                 \                    '@aurum/repo': '0.0',
+                \                    '@aurum/edit': '0.0',
                 \                           '@/os': '0.0',
                 \                          '@/fwc': '0.0',
-                \                    '@/resources': '0.0',
                 \                     '@/mappings': '0.0',
                 \                     '@/commands': '0.0',
                 \                    '@/functions': '0.0',}, 0)
             \'\Vcmd\s\+type ""',            'cmd '.s:_r.comp.cmd,           ''),
             \'\V:"."\s\+type ""', 'either ((type ""), '.s:_r.comp.rev.')',  ''))
 "▶1 file resource
-let s:file= {'arguments': 2,}
+let s:file={'arguments': 2,}
 function s:file.function(read, repo, rev, file)
     let rev=a:repo.functions.getrevhex(a:repo, a:rev)
     call s:_r.cmdutils.setlines(a:repo.functions.readfile(a:repo, rev, a:file),
     endif
     return {'rev': rev, 'file': a:file}
 endfunction
-call s:_f.postresource('file', s:file)
+call s:_f.newcommand(s:file)
+unlet s:file
 "▶1 aurum://file mappings
 let s:mmgroup=':call <SNR>'.s:_sid.'_Eval("s:_f.mapgroup.map(''AuFile'', '.
             \                                               "bufnr('%'))\")\n"

File plugin/aurum/log.vim

     execute frawor#Setup('0.0', {'@/table': '0.1',
                 \        '@aurum/cmdutils': '0.0',
                 \         '@aurum/bufvars': '0.0',
+                \            '@aurum/edit': '0.0',
                 \                  '@/fwc': '0.3',
                 \            '@aurum/repo': '0.0',
                 \             '@/commands': '0.0',
                 \            '@/functions': '0.0',
-                \            '@/resources': '0.0',
                 \              '@/options': '0.0',}, 0)
     call FraworLoad('@/commands')
     call FraworLoad('@/functions')
             \                         'revrange '.s:_r.comp.rev.' '.
             \                                     s:_r.comp.rev,            ''))
 "▶1 Post resource
-let s:log = { 'function': s:F.setup,
-            \  'options': {'list': ['files', 'revrange', 'ignfiles'],
-            \              'bool': ['merges', 'patch', 'stat', 'showfiles',
-            \                       'showrenames', 'showcopies'],
-            \               'num': ['limit']+s:_r.repo.diffoptslst,
-            \               'str': ['date', 'search', 'user', 'branch',
-            \                       'revision', 'style', 'template',
-            \                       'crrestrict'],
-            \              'pats': ['files'],
-            \             },
-            \ 'filetype': 'aurumlog',
-            \}
-call s:_f.postresource('log', s:log)
+call s:_f.newcommand({
+            \'function': s:F.setup,
+            \ 'options': {'list': ['files', 'revrange', 'ignfiles'],
+            \             'bool': ['merges', 'patch', 'stat', 'showfiles',
+            \                      'showrenames', 'showcopies'],
+            \              'num': ['limit']+s:_r.repo.diffoptslst,
+            \              'str': ['date', 'search', 'user', 'branch',
+            \                      'revision', 'style', 'template',
+            \                      'crrestrict'],
+            \             'pats': ['files'],
+            \            },
+            \'filetype': 'aurumlog',
+            \})
 "▶1
 call frawor#Lockvar(s:, '_r,_pluginloaded,compilecache,parsecache,syncache')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲

File plugin/aurum/status.vim

                 \            '@aurum/cmdutils': '0.0',
                 \                      '@/fwc': '0.2',
                 \                '@aurum/repo': '0.0',
+                \                '@aurum/edit': '0.0',
                 \                 '@/commands': '0.0',
                 \                  '@/options': '0.0',
                 \                '@/functions': '0.0',}, 0)
             \'\vfiles\s+\([^)]*\)',       'files path',            ''),
             \'\Vcmd\s\+(type "")',        'cmd '.  s:_r.comp.cmd,  ''),
             \'\vrev([12])\s+\V(type "")', 'rev\1 '.s:_r.comp.rev,  'g'))
+"▶1 aurum://status
+call s:_f.newcommand({
+            \'function': s:F.setup,
+            \ 'options': {'list': ['files', 'show'],
+            \             'bool': ['record'],
+            \              'str': ['rev1', 'rev2'],
+            \             'pats': ['files'],},
+            \'filetype': 'aurumstatus',
+            \})
 "▶1 status resource
-let s:status={'function': s:F.setup,
-            \  'options': {'list': ['files', 'show'],
-            \              'bool': ['record'],
-            \               'str': ['rev1', 'rev2'],
-            \              'pats': ['files'],},
-            \     'repo': 1,
-            \ 'filetype': 'aurumstatus',
-            \}
-" XXX
-let s:status.parseshow=s:F.parseshow
-call s:_f.postresource('status', s:status)
+call s:_f.postresource('status', {'parseshow': s:F.parseshow})
 "▶1
 call frawor#Lockvar(s:, '_r,_pluginloaded')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲