Commits

ZyX_I  committed e2d95d7

Ported plugin to frawor

  • Participants
  • Parent commits 0f983cb

Comments (0)

Files changed (3)

 syntax: regexp
 ^info/\.sids/sid-
 ^info/_
+^info/parinfo

File parinfo-addon-info.txt

         "url": "https://bitbucket.org/ZyX_I/parinfo",
     },
     "dependencies": {
-        "vimpluginloader": {
+        "frawor": {
             "type": "hg",
-            "url": "http://vimpluginloader.hg.sourceforge.net:8000/hgroot/vimpluginloader/vimpluginloader",
-        }
+            "url": "https://bitbucket.org/ZyX_I/frawor",
+        },
     },
     "files": [
         "doc/parinfo.txt",

File plugin/parinfo.vim

 "▶1 Начало
 scriptencoding utf-8
-if exists("s:g._pluginloaded") || exists("g:parinfoOptions.DoNotLoad")
-    finish
-endif
+execute frawor#Setup('0.0', {'@/os': '0.0',
+            \      '@/autocommands': '0.0',
+            \           '@/options': '0.0',})
 "▶1 Основная часть — глобальные переменные
-execute load#Setup('0.0', "parinfo", 0, 0, 1)
 "▶2 Настройки
-let s:g.defaultOptions={
-            \"SaveDirectory": os#JoinPath(expand('<sfile>:h:h'), 'info'),
-            \"SaveOptions": {
-            \     "_history": split(':/=@', '\zs'),
-            \   "_variables": 1,
-            \},
-            \"MaxLines": &history ? &history : 127,
+let s:_options={
+            \'SaveDirectory': {'default':
+            \                       s:_r.os.path.join(expand('<sfile>:h:h'),
+            \                                         'info'),
+            \                  'checker': 'path dw'},
+            \  'SaveOptions': {'default': {'history': [':', '/', '=', '@'],
+            \                            'variables': 1,},},
+            \     'MaxLines': {'default': (&history ? &history : 127),
+            \                  'checker': 'range 0 inf'},
         \}
-let s:g.c={}
-let s:g.c.options={
-            \"SaveDirectory": ["file", "d"],
-            \"SaveOptions": ["dict", [
-            \   [["equal", "_history"], ["alllst", ["in",split(':/=@','\zs')]]],
-            \   [["equal", "_variables"], ["or", [["equal", 1],
-            \                                     ["alllst", ["var", ""]],
-            \                                     ["isreg", ""]]]],
-            \   [["regex", '^_\@!\w\+$'], ["isfunc", 1]],
-            \]],
-            \"MaxLines": ["num", [0]],
-        \}
-" "▶2 Выводимые сообщения
-" let s:g.p={
-"             \"emsg": {
-"             \   %-ERROR_ID-%: %-ERROR_MSG-%,
-"             \},
-"             \"etype": {
-"             \   %-ERROR_TYPE-%: %-ERRO_TYPE_MSG-%,
-"             \}
-"         \}
+" TODO checker for SaveOptions
 "▶1 Основная часть — функции
 "▶2 Разделы
-call map(["load", "acc", "unload", "comm", "reg"], 'extend(s:F, {v:val : {}})')
+call map(['load', 'acc', 'unload', 'comm'], 'extend(s:F, {v:val : {}})')
 lockvar 1 s:F
-"▶2 main: eerror, destruct, option, session
-"▶3 main.destruct
-function s:F.main.destruct()
-    call s:F.unload.main(1)
-    unlet s:g s:F
-    return 1
-endfunction
-"▶3 main.session
-function s:F.main.session(...)
-    if a:0
-        return s:F.comm.restore(a:1)
-    else
-        return s:F.comm.save()
-    endif
-endfunction
 "▶2 comm: merge
 "▶3 comm.readfile
 function s:F.comm.readfile(file)
 endfunction
 "▶3 comm.restore
 function s:F.comm.restore(info)
-    let d={'addoptions': s:g.load.addoptions}
+    let d={'addoptions': s:addoptions}
     for [key, value] in items(a:info)
-        if has_key(s:g.load.saveoptions, key)
-            call call(s:g.load.saveoptions[key], [value], deepcopy(d))
+        if has_key(s:saveoptions, key)
+            call call(s:saveoptions[key], [value], deepcopy(d))
         endif
         unlet value
     endfor
 endfunction
 "▶3 comm.save
 function s:F.comm.save()
-    let d={'addoptions': s:g.load.addoptions}
+    let d={'addoptions': s:addoptions}
     let r={}
-    for [key, d.F] in items(s:g.load.saveoptions)
+    for [key, d.F] in items(s:saveoptions)
         let r[key]=call(d.F, [], deepcopy(d))
     endfor
     return r
 endfunction
-"▶2 reg
-let s:g.reg={}
-let s:g.reg.registered={}
-"▶3 reg.register
-function s:F.reg.register(name, F, ...)
-    let s:g.reg.registered[a:name]=a:F
-    unlockvar 1 s:g.defaultOptions.SaveOptions
-    let s:g.defaultOptions.SaveOptions['@'.a:name]=deepcopy(get(a:000, 0, 0))
-    lockvar 1 s:g.defaultOptions.SaveOptions
-    lockvar s:g.defaultOptions.SaveOptions['@'.a:name]
-endfunction
 "▶2 acc
 "▶3 acc.history
 function s:F.acc.history(...)
     if empty(a:000)
         let r={}
-        for histtype in self.addoptions._history
+        for histtype in self.addoptions.history
             let r[histtype]=[]
             while 1
                 let histentry=histget(histtype, -1)
     endif
 endfunction
 "▶3 acc.var
-let s:g.acc={}
 let s:F.acc.var={}
 "▶4 acc.var.setvars
 function s:F.acc.var.setvars(vars)
     return r
 endfunction
 "▶4 acc.var.getvarlst
-let s:g.acc.varreg=string("\\v^\\w+ +\\[('(''|[^'])*', )*('(''|[^'])*')\\]$")
 function s:F.acc.var.getvarlst()
     let r=[]
     let d={}
     for [key, d.Value] in items(g:)
         if type(d.Value)==type([]) &&
-                    \len(filter(copy(d.Value), 'type(v:val)=='.type("")))==
+                    \len(filter(copy(d.Value), 'type(v:val)=='.type('')))==
                     \                                               len(d.Value)
             call add(r, key)
         endif
 function s:F.acc.var.lst(...)
     if empty(a:000)
         return s:F.acc.var.getvars(filter(s:F.acc.var.getvarlst(),
-                    \'index(self.addoptions._variables, v:val)!=-1'))
+                    \'index(self.addoptions.variables, v:val)!=-1'))
     else
         return s:F.acc.var.setvars(a:1)
     endif
 function s:F.acc.var.reg(...)
     if empty(a:000)
         return s:F.acc.var.getvars(filter(s:F.acc.var.getvarlst(),
-                    \'v:val=~#self.addoptions._variables'))
+                    \'v:val=~#self.addoptions.variables'))
     else
         return s:F.acc.var.setvars(a:1)
     endif
 endfunction
 "▶2 load
-"▶3 s:g.load
-let s:g.load={}
-let s:g.load.vars=map({
+"▶3 s:vars
+let s:vars=map({
             \type(0) : 'all',
             \type([]): 'lst',
-            \type(""): 'reg',
+            \type(''): 'reg',
         \}, 's:F.acc.var[v:val]')
 "▶3 load.adler32
 function s:F.load.adler32(str)
         let s2 = (s2+s1)               %65521
         let i+=1
     endwhile
-    return printf("%04x%04x", s1, s2)
+    return printf('%04x%04x', s1, s2)
 endfunction
 "▶3 load.gensid
 function s:F.load.gensid()
-    let prevsidbase=max(map(filter(fileutils#GetDirContents(s:g.load.siddir),
-                \                'v:val=~?''^sid-\x\{8}-\d\+$'''),
-                \         '+v:val[13:]'))
+    let prevsidbase=max(map(filter(s:_r.os.listdir(s:siddir),
+                \                  'v:val=~?''^sid-\x\{8}-\d\+$'''),
+                \           '+v:val[13:]'))
     let checksumsrc=v:progname.join(map(range(0, argc()-1), 'argv(v:val)'))
-    if has("reltime")
+    if has('reltime')
         let checksumsrc.=reltimestr(reltime())
     else
         let checksumsrc.=localtime()
     endif
-    let s:g.load.sid=s:F.load.adler32(checksumsrc).'-'.(prevsidbase+1)
-    let s:g.load.sidfile=os#JoinPath(s:g.load.siddir, 'sid-'.(s:g.load.sid))
+    let s:sessid=s:F.load.adler32(checksumsrc).'-'.(prevsidbase+1)
+    let s:sessidfile=s:_r.os.path.join(s:siddir, 'sid-'.(s:sessid))
 endfunction
 "▶3 load.setoptions
 function s:F.load.setoptions()
-    let s:g.load.saveoptions=copy(s:F.main.option("SaveOptions"))
-    let s:g.load.addoptions={}
+    let s:saveoptions=copy(s:_f.getoption('SaveOptions'))
+    let s:addoptions={}
     let d={}
-    for [key, d.Value] in items(s:g.load.saveoptions)
-        let s:g.load.addoptions[key]=d.Value
-        if key==#'_history'
-            let s:g.load.saveoptions[key]=s:F.acc.history
-        elseif key==#'_variables'
-            let s:g.load.saveoptions[key]=s:g.load.vars[type(d.Value)]
-        elseif key[0]==#'@' && has_key(key[1:], s:g.reg.registered)
-            let s:g.load.saveoptions[key]=s:g.load.registered[key[1:]]
+    for [key, d.Value] in items(s:saveoptions)
+        let s:addoptions[key]=d.Value
+        if key is# 'history'
+            let s:saveoptions[key]=s:F.acc.history
+        elseif key is# 'variables'
+            let s:saveoptions[key]=s:vars[type(d.Value)]
         else
-            let s:g.load.saveoptions[key]=d.Value
+            let s:saveoptions[key]=d.Value
         endif
     endfor
-    lockvar! s:g.load.saveoptions
+    lockvar! s:saveoptions
 endfunction
 "▶3 load.main
 function s:F.load.main()
-    let s:g.load.savedir=s:F.main.option("SaveDirectory")
-    let s:g.load.siddir=os#JoinPath(s:g.load.savedir, '.sids')
-    if !isdirectory(s:g.load.siddir)
-        call mkdir(s:g.load.siddir)
+    let s:savedir=s:_f.getoption('SaveDirectory')
+    let s:siddir=s:_r.os.path.join(s:savedir, '.sids')
+    if !isdirectory(s:siddir)
+        call mkdir(s:siddir)
     endif
     call s:F.load.setoptions()
-    let tosave=keys(s:g.load.saveoptions)
+    let tosave=keys(s:saveoptions)
     call s:F.load.gensid()
-    call writefile(tosave, s:g.load.sidfile, 'b')
-    let s:g.load.infofile=os#JoinPath(s:g.load.savedir, 'parinfo')
-    if filereadable(s:g.load.infofile)
-        call s:F.comm.restore(s:F.comm.readfile(s:g.load.infofile))
+    call writefile(tosave, s:sessidfile, 'b')
+    let s:infofile=s:_r.os.path.join(s:savedir, 'parinfo')
+    if filereadable(s:infofile)
+        call s:F.comm.restore(s:F.comm.readfile(s:infofile))
     endif
 endfunction
 "▶2 unload
     return r
 endfunction
 "▶3 unload.main
-function s:F.unload.main(...)
-    let maxlines=s:F.main.option("MaxLines")
+function s:F.unload.main()
+    let maxlines=s:_f.getoption('MaxLines')
     let r=s:F.comm.save()
-    if filereadable(s:g.load.infofile)
-        let oldr=s:F.comm.readfile(s:g.load.infofile)
+    if filereadable(s:infofile)
+        let oldr=s:F.comm.readfile(s:infofile)
         let r=s:F.comm.merge(maxlines, r, oldr)
     else
         let r=s:F.comm.merge(maxlines, r)
     endif
-    call writefile(s:F.unload.dump('', r), s:g.load.infofile, 'b')
-    call delete(s:g.load.sidfile)
+    call writefile(s:F.unload.dump('', r), s:infofile, 'b')
+    call delete(s:sessidfile)
 endfunction
-"▶1 Регистрация дополнения
-let s:g._load.requires=[["load", '0.11']]
-let s:g._load.preload=[["fileutils", "autoload"],
-            \          ["os",        "autoload"]]
-let s:g._load.reginfo=s:F.plug.load.registerplugin(s:g._load)
-call extend(s:F.main, s:g._load.reginfo.functions)
-unlet s:g._load
+"▶1 Создание автокомманд
 call s:F.load.main()
 unlet s:F.load
-call s:F.main.autocmd('', 'VimLeavePre', '*', s:F.unload.main)
+call s:_f.augroup.add('ParInfo', [['VimLeavePre', '*', 0, s:F.unload.main]])
 "▶1
-lockvar! s:F s:g
+call frawor#Lockvar(s:, '')
 " vim: ft=vim ts=4 sts=4 et fmr=▶,▲