Commits

ZyX_I  committed 8d5d3cf

Ported plugin to frawor

  • Participants
  • Parent commits f117676

Comments (0)

Files changed (1)

File plugin/z.vim

-"{{{1 Начало
 scriptencoding utf-8
-if (exists("s:g._pluginloaded") && s:g._pluginloaded) ||
-            \exists("g:zOptions.DoNotLoad")
+"{{{1 Первая загрузка
+if !exists('s:_pluginloaded')
+    "{{{2 Объявление переменных
+    execute frawor#Setup('0.0', {'@/fwc': '0.0',
+                \           '@/commands': '0.0',
+                \          '@/functions': '0.0',}, 0)
+    call map(['cmd', 'comp'], 'extend(s:F, {v:val : {}})')
+    lockvar 1 s:F
+    "{{{2 Команды
+    call FraworLoad('@/commands')
+    call FraworLoad('@/functions')
+    let s:zefunc={}
+    let s:zecomp=['+ first (in *F.comp._completeEopt(@), path w)']
+    call s:_f.command.add('ZEdit', s:zefunc, {'nargs': '+', 'bang': 1,
+                \                             'complete': s:zecomp})
+    let s:zvfunc={}
+    let s:zvcomp=['+ first (in *F.comp._completeEopt(@), path)']
+    call s:_f.command.add('ZView', s:zvfunc, {'nargs': '+', 'bang': 1,
+                \                             'complete': s:zvcomp})
+    "}}}2
     finish
-"{{{1 Первая загрузка
-elseif !exists("s:g._pluginloaded")
-    "{{{2 Объявление переменных
-    execute load#Setup('0.0', 1, 1, 1)
-    call map(["cmd", "comp"], 'extend(s:F, {v:val : {}})')
-    lockvar 1 s:F
-    "{{{2 Функции
-    let s:g._load.functions=[
-                \['InsertComplete', 'comp._ins_complete', {}],
-                \['InputComplete',  'comp._input_complete', {}],
-            \]
-    "{{{2 Команды
-    let s:g._load.commands={
-                \"Edit": {
-                \      "nargs": '+',
-                \       "bang": '',
-                \       "func": "cmd.edit",
-                \   "complete": "customlist,s:_edit_complete",
-                \},
-                \"View": {
-                \      "nargs": '+',
-                \       "bang": '',
-                \       "func": "cmd.view",
-                \   "complete": "customlist,s:_view_complete",
-                \},
-            \}
-    "{{{2 Регистрация дополнения
-    let s:g._load.requires=[["load", '0.0'],
-                \           ["comp", '0.4'],
-                \           ["stuf", '0.0']]
-    let s:g._load.mappings={
-                \   "FNameComplete": {
-                \       'function': 'comp.InsCompleteMapping',
-                \        'default': "\<C-x>\<C-f>",
-                \           'type': 'i',
-                \   },
-                \}
-    let s:g._load.reginfo=s:F.plug.load.registerplugin(s:g._load)
-    let s:F.main.eerror=s:g._load.reginfo.functions.eerror
-    let s:F.main.option=s:g._load.reginfo.functions.option
+elseif s:_pluginloaded
     finish
 endif
-"{{{1 Вторая загрузка
-let s:g._pluginloaded=1
-unlet s:g._load
 "{{{1 Вторая загрузка — функции
-"{{{2 Внешние дополнения
-let s:F.plug.comp=s:F.plug.load.getfunctions("comp")
-let s:F.plug.stuf=s:F.plug.load.getfunctions("stuf")
-"{{{2 main: eerror, destruct, option
-"{{{3 main.destruct: выгрузить плагин
-function s:F.main.destruct()
-    for name in ['E', 'Ins', 'Inp']
-        call s:F.plug.comp.delcomp(s:g.comp["_cname".name])
-    endfor
-    unlet s:g
-    unlet s:F
-    return 1
-endfunction
-"{{{2 cmd: edit, view
+"{{{2 cmd, z?func
 "{{{3 cmd.main
 function s:F.cmd.main(action, bang, ...)
     let options=filter(copy(a:000), 'v:val[0:1]==#"++"')
     let files=filter(copy(a:000), 'v:val[0:1]!=#"++"')
     let nfiles=[]
     for file in files
-        execute a:action.a:bang." ".
-                    \join(options)." ".
+        execute a:action.a:bang.' '.
+                    \join(options).' '.
                     \fnameescape(file)
     endfor
 endfunction
-"{{{3 cmd.edit
-function s:F.cmd.edit(...)
-    return call(s:F.cmd.main, ["edit"]+a:000, {})
+"{{{3 zefunc
+function s:zefunc.function(...)
+    return call(s:F.cmd.main, ['edit']+a:000, {})
 endfunction
-"{{{3 cmd.view
-function s:F.cmd.view(...)
-    return call(s:F.cmd.main, ["view"]+a:000, {})
+"{{{3 zvfunc
+function s:zvfunc.function(...)
+    return call(s:F.cmd.main, ['view']+a:000, {})
 endfunction
 "{{{2 comp: _edit_complete
 "{{{3 comp._completeEopt
-"{{{4 s:g.comp
-let s:g.comp={}
-let s:g.comp.ppopt=["ff", "fileformat", "enc", "encoding", "bin", "binary",
-            \       "nobin", "nobinary", "bad"] " 'edit'
-let s:g.comp.bads=['keep', 'drop', '?']
-let s:g.comp.fileformats=['dos', 'unix', 'mac']
-let s:g.comp.encodings=['latin1', 'koi8-r', 'koi8-u', 'macroman',
+"{{{4 Globals
+let s:ppopt=['ff', 'fileformat', 'enc', 'encoding', 'bin', 'binary',
+            \'nobin', 'nobinary', 'bad'] " 'edit'
+let s:bads=['keep', 'drop', '?']
+let s:fileformats=['dos', 'unix', 'mac']
+let s:encodings=['latin1', 'koi8-r', 'koi8-u', 'macroman',
             \'cp437', 'cp737', 'cp775', 'cp850', 'cp852', 'cp855', 'cp857',
             \'cp860', 'cp861', 'cp862', 'cp863', 'cp865', 'cp866', 'cp869',
             \'cp874', 'cp1250', 'cp1251', 'cp1253', 'cp1254', 'cp1255',
             \'cp1256', 'cp1257', 'cp1258']
-call extend(s:g.comp.encodings, map(range(2, 15), "'iso-8859-'.v:val"))
-call extend(s:g.comp.encodings, map(copy(s:g.comp.encodings), "'8bit-'.v:val"))
-let s:g.comp.dbencodings=['cp932', 'euc-jp', 'sjis', 'cp949',
+call extend(s:encodings, map(range(2, 15), '"iso-8859-".v:val'))
+call extend(s:encodings, map(copy(s:encodings), '"8bit-".v:val'))
+let s:dbencodings=['cp932', 'euc-jp', 'sjis', 'cp949',
             \'euc-kr', 'cp936', 'euc-cn', 'cp950', 'big5', 'euc-tw',
             \'japan', 'korea', 'prc', 'chinese', 'taiwan']
-call extend(s:g.comp.encodings, s:g.comp.dbencodings)
-call extend(s:g.comp.encodings, map(copy(s:g.comp.dbencodings),
+call extend(s:encodings, s:dbencodings)
+call extend(s:encodings, map(copy(s:dbencodings),
             \'"2byte-".v:val'))
-call extend(s:g.comp.encodings, ['utf-8', 'ucs-2', 'ucs-2le', 'utf-16',
+unlet s:dbencodings
+call extend(s:encodings, ['utf-8', 'ucs-2', 'ucs-2le', 'utf-16',
             \'utf-16le', 'ucs-4', 'ucs-4le', 'utf8', 'unicode', 'uncs2be',
             \'ucs-2be', 'ucs-4be', 'utf-32', 'utf-32le', 'default'])
-let s:g.comp.alts={
+let s:ppabbr={
             \   'ff': 'fileformat',
             \  'enc': 'encoding',
             \  'bin':   'binary',
             \'nobin': 'nobinary',
         \}
-call map(copy(s:g.comp.alts), 'extend(s:g.comp.alts, {v:val : v:key})')
-let s:g.comp.withoption={
+let s:alts=copy(s:ppabbr)
+call map(copy(s:ppabbr), 'extend(s:alts, {v:val : v:key})')
+let s:withoption={
             \'ff':  'fileformats', 'fileformat': 'fileformats',
             \'enc': 'encodings',     'encoding':   'encodings',
             \'bad': 'bads',
         \}
-let s:g.comp._cnameE="zvim/edit"
-let s:g.comp._cnameV="zvim/view"
-let s:g.comp._cnameIns="zvim/insert"
-let s:g.comp._cnameInp="zvim/input"
-let s:g.comp.toarglead=[
-            \'v:val=~#"^".es',
-            \'v:val=~?"^".es',
-            \'v:val=~#es',
-            \'v:val=~?es',
+"{{{4 comp.toarglead
+let s:filterexprs=[
+            \'v:val[:(larglead)] is# a:arglead',
+            \'v:val[:(larglead)] ==? a:arglead',
+            \'stridx(v:val, a:arglead)!=-1',
+            \'v:val=~?"\\V".escape(a:arglead, "\\")',
         \]
-"{{{4 comp.toarglead
 function s:F.comp.toarglead(arglead, list)
-    let es=s:F.plug.stuf.regescape(a:arglead)
-    for expr in s:g.comp.toarglead
+    let larglead=len(a:arglead)-1
+    for expr in s:filterexprs
         let r=filter(copy(a:list), expr)
         if !empty(r)
             return r
     if start[0:1]==#'++'
         let start=start[2:]
         if start!~#'='
-            let starts=s:F.comp.toarglead(start, s:g.comp.ppopt)
+            let starts=s:F.comp.toarglead(start, s:ppopt)
             return map(starts, '"++".v:val')
         else
             let end=matchstr(start, '=\@<=.*$')
             let s=matchstr(start, '^.\{-}=\@=')
-            if has_key(s:g.comp.withoption, s)
-                let opts=s:F.comp.toarglead(end,
-                            \s:g.comp[s:g.comp.withoption[s]])
+            if has_key(s:withoption, s)
+                let opts=s:F.comp.toarglead(end, s:{s:withoption[s]})
                 return map(opts, '"++".s."=".v:val')
             else
-                let starts=s:F.comp.toarglead(s, s:g.comp.ppopt)
+                let starts=s:F.comp.toarglead(s, s:ppopt)
                 let alts={}
                 let r=[]
                 let r2=[]
                 for start in starts
-                    if has_key(alts, start)
+                    if has_key(ppabbrs, start)
                         continue
                     endif
-                    if has_key(s:g.comp.alts, start)
-                        let alts[s:g.comp.alts[start]]=1
+                    if has_key(s:alts, start)
+                        let alts[s:alts[start]]=1
                     endif
-                    if !has_key(s:g.comp.withoption, start)
+                    if !has_key(s:withoption, start)
                         let r2+=['++'.start]
                         continue
                     endif
-                    let r+=s:F.comp._completeEopt("++".start."=".end)
+                    let r+=s:F.comp._completeEopt('++'.start.'='.end)
                 endfor
                 if empty(r)
                     let r=r2
     endif
     return []
 endfunction
-"{{{3 comp._edit_complete, comp._view_complete
-let s:g.comp.Emodel=
-            \{"model": "words",
-            \ "words": ["first", [["func!", s:F.comp._completeEopt],
-            \                     ["file", "w"]]]}
-let s:g.comp.Vmodel=
-            \{"model": "words",
-            \ "words": ["first", [["func!", s:F.comp._completeEopt],
-            \                     ["file", "r"]]]}
-let s:F.comp._edit_complete=s:F.plug.comp.ccomp(s:g.comp._cnameE,
-            \                                   s:g.comp.Emodel)
-let s:F.comp._view_complete=s:F.plug.comp.ccomp(s:g.comp._cnameV,
-            \                                   s:g.comp.Vmodel)
-let s:g.comp.InsModel={
-            \"model": "insertwords",
-            \"words": ["file", ""],
-            \"start": "_cfile",
-        \}
-let s:F.comp._ins_complete=s:F.plug.comp.ccomp(s:g.comp._cnameIns,
-            \                                  s:g.comp.InsModel)
-function s:F.comp.InsCompleteMapping(...)
-    return "\<C-r>=ZInsertComplete()\n"
-endfunction
-let s:g.comp.InpModel={
-            \"model": "inputwords",
-            \"words": ["file", ""],
-            \"argsplitregex": '',
-        \}
-let s:F.comp._input_complete=s:F.plug.comp.ccomp(s:g.comp._cnameInp,
-            \                                    s:g.comp.InpModel)
 "{{{1
-lockvar! s:F
-lockvar! s:g
+execute frawor#Lockvar(s:, '_pluginloaded')
 " vim: ft=vim:ts=8:fdm=marker:fenc=utf-8