Commits

ZyX_I  committed 376db63

Moved plugdict expansion to plugin/frawor, removed "@" expansion, added @%, @. and @^ expansions

  • Participants
  • Parent commits 5313663

Comments (0)

Files changed (10)

File autoload/frawor.vim

     return eval(a:expr)
 endfunction
 let s:_functions['s:Eval']=function('s:Eval')
-"▶1 frawor#expandplid :: String → String
-function frawor#expandplid(str)
-    return substitute(substitute(substitute(substitute(substitute(a:str,
-                \'\m^@@', '@',              ''),
-                \'\m^@/', 'plugin/frawor/', ''),
-                \'\m^@:', 'ftplugin/',      ''),
-                \'\m^@%', 'autoload/',      ''),
-                \'\m^@',  'plugin/',        '')
-endfunction
 "▶1 frawor#Setup      :: version, dependencies, oneload → vimlstr
 function frawor#Setup(version, dependencies, oneload)
     if type(a:version)==type("")
                 \'((type(v:val)==type(""))?'.
                 \   '(map(split(v:val, "\\."), "+v:val")):'.
                 \   '(v:val))')
-    for key in keys(deps)
-        let deps[frawor#expandplid(key)]=remove(deps, key)
-    endfor
     let dstr=substitute(string(deps), "\n", '''."\\n".''', 'g')
     let oneload=(!!a:oneload)
     return       'execute "function s:Eval(expr)\n'.
 let s:_functions['frawor#Setup']=function('frawor#Setup')
 "▶1 frawor#Reload     :: Either plugdict plid → + :source
 function! frawor#Reload(plid)
-    for file in FraworUnload(frawor#expandplid(a:plid))
+    for file in FraworUnload(a:plid)
         if file isnot 0
             execute 'source' fnameescape(file)
         endif

File doc/frawor.txt

                      runtimepath (or `/unknown' if frawor failed to detect 
                      it).
         It also sets s:_pluginloaded to either 1 for oneload plugins or 0.
+                                                       *frawor-plid-expansion*
+        If some key in {dependencies} dictionary starts with `@', then it is 
+        transformed:
+                            Origin      Transformed ~
+                            @/          plugin/frawor/
+                            @:          ftplugin/
+                            @%          autoload/
+                            @@          @
+                            @           plugin/
+        There two special cases: `^' gets expanded to plugin id without one 
+        component (but with trailing slash) and `@.' gets expanded to plugin 
+        id (both only for {dependencies} dictionary).
                                                      *frawor-anonymous-plugin*
         You may specify 0 instead of {version}. In this case plugin type will 
         be `/anonymous', plugin id will be equal to `file' argument (possibly 
         1. If {version} or some value in {dependencies} is a dot-separated 
            list of numbers, then it is transformed into |List| of |Number|s. 
            Example: "1.0.4" → [1, 0, 4].
-                                                       *frawor-plid-expansion*
-        2. If some key in {dependencies} starts with `@', then it is 
-           transformed, see |frawor#expandplid()|.
-        3. It creates s:Eval function which is just a wrapper to |eval()|. 
+        2. It creates s:Eval function which is just a wrapper to |eval()|. 
            Useful inside mappings because they have no direct access to script 
            variables and for obtaining |<SID>| value.
-        4. It creates s:F variable containing a dictionary, s:_functions 
+        3. It creates s:F variable containing a dictionary, s:_functions 
            (also a dictionary) and s:_functions['s:Eval'] (contains 
            reference to s:Eval function).
-        5. Creates s:_sid variable containing your plugin script id.
-        6. If s:_sfile variable does not exist, sets it to plugin filename.
-        7. Calls |FraworRegister()|, passing it transformed {version}, s:_sid, 
+        4. Creates s:_sid variable containing your plugin script id.
+        5. If s:_sfile variable does not exist, sets it to plugin filename.
+        6. Calls |FraworRegister()|, passing it transformed {version}, s:_sid, 
            s:_sfile, transformed {dependencies}, {oneload} and s:.
         Example: >
             execute frawor#Setup([0, 0], {"plugin/frawor": [0, 0]}, 0)
         frawor#Setup extension, it won't work with FraworRegister.
         Note: you must |:execute| frawor#Setup, not |:call| it.
 
-frawor#expandplid({plid})                                *frawor#expandplid()*
-        Perform some expansions on plugin id: if plugin id starts with `@' it 
-        is transformed:
-        Origin      Transformed ~
-        @@          @
-        @/          plugin/frawor/
-        @:          ftplugin/
-        @%          autoload/
-        @           plugin/
-
 FraworLoad({plugin})                                            *FraworLoad()*
-        Load {plugin}. {plugin} argument may be either a plugin ID or plugin 
-        dictionary. Returns 0 if it failed to load plugin, 1 if plugin was 
-        successfully loaded and 2 if plugin is being loaded now.
+        Load {plugin}. {plugin} argument may be either a plugin ID 
+        (transformed using |frawor-plid-expansion|) or plugin dictionary. 
+        Returns 0 if it failed to load plugin, 1 if plugin was successfully 
+        loaded and 2 if plugin is being loaded now.
 
 FraworUnload({plugin})                                        *FraworUnload()*
         Unload {plugin}. {plugin} argument may be either a plugin ID 

File plugin/frawor.vim

                 \  'invloadarg': 'Неверный тип аргумента FraworLoad',
                 \   'notloaded': 'Дополнение %s не загружено',
                 \'invunloadarg': 'Неверный тип аргумента FraworUnload',
+                \       'npref': 'Использование приставки «%s» здесь '.
+                \                'не разрешено',
             \}
 else
     let s:_messages={
                 \  'invloadarg': 'Wrong type of FraworLoad argument',
                 \   'notloaded': 'Plugin %s is not loaded',
                 \'invunloadarg': 'Wrong type of FraworUnload argument',
+                \       'npref': 'Prefix `%s'' is not allowed here',
             \}
 endif
 "▶1 s:Eval
     return eval(a:expr)
 endfunction
 let s:_functions['s:Eval']=function('s:Eval')
+"▶1 expandplid      :: String → plid
+let s:prefixes={
+            \'@/': 'plugin/frawor/',
+            \'@:': 'ftplugin/',
+            \'@%': 'autoload/',
+            \'@' : 'plugin/',
+            \'@@': '@',
+        \}
+function s:F.expandplid(str, ...)
+    let prefix=matchstr(a:str, '\v^\@[/:%@\^.]?')
+    if empty(prefix)
+        return a:str
+    elseif has_key(s:prefixes, prefix)
+        return s:prefixes[prefix].a:str[len(prefix):]
+    elseif !a:0
+        call s:_f.throw('npref', prefix)
+    elseif prefix is '@^'
+        return matchstr(a:1, '\m.*/').a:str[2:]
+    elseif prefix is '@.'
+        return a:1.a:str[2:]
+    else
+        return s:prefixes[prefix].a:str[len(prefix):]
+    endif
+endfunction
 "▶1 compareversions :: version, version → -1|0|1
 function s:F.compareversions(a, b)
     let len=max([len(a:a), len(a:b)])
     endif
     "▲4
     for [dplid, d.Version] in items(deps)
+        let dplid=s:F.expandplid(dplid, plid)
         "▶4 Verifying dependency version
         if type(d.Version)!=type([])
             call s:_f.throw('d_vernotlist', dplid, plid)
 "▶1 loadplugin      :: Either plugdict plid → 0|1|2 + plugdict, …
 function s:F.loadplugin(plid)
     "▶2 Get plugdict
-    if type(a:plid)==type("")
+    if type(a:plid)==type('')
+        let plid=s:F.expandplid(a:plid)
         "▶3 Checking for empty plid
-        if empty(a:plid)
+        if empty(plid)
             call s:_f.throw('plidempty')
         endif
         "▶3 Checking whether plugin is already being loaded
-        if has_key(s:loading, a:plid)
+        if has_key(s:loading, plid)
             return 2
         endif
         "▲3
-        if !has_key(s:pls, a:plid)
-            execute 'runtime! '.fnameescape(a:plid.'.vim')
+        if !has_key(s:pls, plid)
+            execute 'runtime! '.fnameescape(plid.'.vim')
         endif
         "▶3 Checking whether plugin was successfully loaded
         if !has_key(s:pls, a:plid)
         let plugdict=s:pls[a:plid]
     "▶3 Processing dictionary supplied instead of plugin ID
     elseif type(a:plid)==type({})
-        if has_key(a:plid, 'id') && type(a:plid.id)==type("") &&
+        if has_key(a:plid, 'id') && type(a:plid.id)==type('') &&
                     \has_key(s:pls, a:plid.id) && s:pls[a:plid.id] is a:plid
+            let plid=a:plid.id
             let plugdict=a:plid
         else
             call s:_f.throw('invplugdict')
     "▲2
     if plugdict.status!=2
         let shadowdict=s:shadow[plugdict.id]
-        let s:loading[a:plid]=1
+        let s:loading[plid]=1
         let d={}
         try
             "▶2 Loading dependencies
             for [dplid, d.Version] in items(plugdict.dependencies)
                 if has_key(s:loading, dplid)
-                    if dplid!=#a:plid
-                        call s:_f.warn('recdep', dplid, a:plid)
+                    if dplid!=#plid
+                        call s:_f.warn('recdep', dplid, plid)
                     endif
                     continue
                 endif
                     let dversion=s:pls[dplid].version
                     "▶3 Checking dependency version
                     if d.Version[0]!=dversion[0]
-                        call s:_f.throw('majmismatch', dplid, a:plid,
+                        call s:_f.throw('majmismatch', dplid, plid,
                                     \                  d.Version[0],
                                     \                  dversion[0])
                     elseif s:F.compareversions(d.Version, dversion)>0
-                        call s:_f.throw('oldversion', dplid, a:plid,
+                        call s:_f.throw('oldversion', dplid, plid,
                                     \                 join(d.Version, '.'),
                                     \                 join(dversion,  '.'))
                     endif
                     "▲3
                 else
-                    call s:_f.throw('reqfailed', dplid, a:plid)
+                    call s:_f.throw('reqfailed', dplid, plid)
                 endif
             endfor
             "▲2
             endif
             "▲2
         finally
-            unlet s:loading[a:plid]
+            unlet s:loading[plid]
         endtry
     endif
     return 1
 function s:F.unloadplugin(plid)
     "▶2 Get plugdict
     if type(a:plid)==type("")
-        if has_key(s:pls, a:plid)
-            let plugdict=s:pls[a:plid]
+        let plid=s:F.expandplid(a:plid)
+        if has_key(s:pls, plid)
+            let plugdict=s:pls[plid]
         else
-            call s:_f.throw('notloaded', a:plid)
+            call s:_f.throw('notloaded', plid)
         endif
+        unlet plid
     elseif type(a:plid)==type({})
         if has_key(a:plid, 'id') && type(a:plid.id)==type("") &&
                     \has_key(s:pls, a:plid.id) && s:pls[a:plid.id] is a:plid

File test/plid-expansion.in

+:let &rtp.=",".escape($TESTDIR, ',\').'/rtp'
+:let g:testfile="plugin/".g:curtest.".vim"
+:source test.vim

File test/plid-expansion.ok

+plugin/exptest
+plugin/plid-expansion/exptest
+autoload/exptest
+ftplugin/exptest
+['newfeature', 'postresource', 'throw', 'warn']

File test/rtp/autoload/exptest.vim

+execute frawor#Setup('0.0', {}, 1)
+call WriteFile('autoload/exptest')

File test/rtp/ftplugin/exptest.vim

+execute frawor#Setup('0.0', {}, 1)
+call WriteFile('ftplugin/exptest')
+

File test/rtp/plugin/exptest.vim

+execute frawor#Setup('0.0', {}, 1)
+call WriteFile('plugin/exptest')
+

File test/rtp/plugin/plid-expansion.vim

+execute frawor#Setup('0.0', {'@exptest'   : '0.0',
+            \                '@%exptest'  : '0.0',
+            \                '@:exptest'  : '0.0',
+            \                '@/resources': '0.0',
+            \                '@./exptest' : '0.0',}, 1)
+call WriteFile(string(sort(keys(s:_f))))
+

File test/rtp/plugin/plid-expansion/exptest.vim

+execute frawor#Setup('0.0', {}, 1)
+call WriteFile('plugin/plid-expansion/exptest')
+