Commits

ZyX_I committed 81d5f9a

@/autocommands: Removed @FWC decorator, restored old checks (they are more efficient + dont touch if it works)

  • Participants
  • Parent commits 1ac2845
  • Tags FWC-revert-autocommands

Comments (0)

Files changed (3)

plugin/frawor/autocommands.vim

             \exists('g:frawor__donotload')
     finish
 endif
-execute frawor#Setup('0.0', {'@/functions': '0.0',
-            \             '@/fwc/compiler': '0.0'}, 1)
+execute frawor#Setup('0.0', {}, 1)
 "▶1 Define messages
 if v:lang=~?'ru'
     let s:_messages={
+                \   'agidnstr': 'Ошибка создания группы событий '.
+                \               'для дополнения %s: название группы '.
+                \               'не является строкой',
                 \    'invagid': 'Ошибка создания группы событий '.
                 \               'для дополнения %s: строка «%s» не может '.
                 \               'являться названием группы',
             \}
     call extend(s:_messages, map({
                 \    'agiddef': 'группа уже определена дополнением %s',
+                \    'agenlst': 'список событий не является списком',
+                \   'noevents': 'отсутствуют события в списке',
+                \      'enlst': 'одно из событий не является списком',
+                \     'en3lst': 'одно из событий содержит не три элемента',
             \},'"Ошибка создания группы событий %s для дополнения %s: ".v:val'))
     call extend(s:_messages, map({
-                \   'invetype': 'тип событий не верен: %s',
+                \ 'etypenslst': 'тип события не является строкой или списком',
+                \  'invetypes': 'часть типов событий не верна',
+                \    'ptrnstr': 'шаблон не является строкой',
+                \  'nestnbool': 'третий элемент не является единицей или нулём',
                 \   'emptycmd': 'список аргументов пуст',
                 \ 'nowrapfunc': 'отсутствует функция _f.wrapfunc '.
                 \               '(дополнение должно зависеть от '.
                 \                'plugin/frawor/functions)',
+                \     'ukncmd': 'не удалось обработать команду',
             \},'"Ошибка создания события №%u группы событий %s '.
             \   'для дополнения %s: ".v:val'))
 else
     let s:_messages={
+                \   'agidnstr': 'Error while creating augroup for plugin %s: '.
+                \               'group ID is not a String',
                 \    'invagid': 'Error while creating augroup for plugin %s: '.
                 \               'string `%s'' is not a valid group ID',
                 \   'loadfail': 'Failed to load plugin %s',
             \}
     call extend(s:_messages, map({
                 \    'agiddef': 'group was already defined by plugin %s',
+                \    'agenlst': 'event list is not a List',
+                \   'noevents': 'no events in list',
+                \      'enlst': 'one of events is not a List',
+                \     'en3lst': 'one of events contains not 3 elements',
             \}, '"Error while creating augroup %s for plugin %s: ".v:val'))
     call extend(s:_messages, map({
-                \   'invetype': 'event type is not valid: %s',
+                \ 'etypenslst': 'event type is neither String nor List',
+                \  'invetypes': 'some event types are not valid',
+                \    'ptrnstr': 'event pattern is not a String',
+                \  'nestnbool': 'third list element is neither 0 nor 1',
                 \   'emptycmd': 'arguments list is empty',
                 \ 'nowrapfunc': 'function _f.wrapfunc is absent '.
                 \               '(plugin must depend on '.
                 \                'plugin/frawor/functions)',
+                \     'ukncmd': 'failed to process command',
             \}, '"Error while processing event #%u for augroup %s '.
             \    'defined by plugin %s: ".v:val'))
 endif
     let d={}
     while !empty(a:plugdict.g._augroups)
         let d.agname=remove(a:plugdict.g._augroups, 0)
-        if type(d.agname)==type("") && stridx(d.agname, '#')==-1 &&
+        if type(d.agname)==type('') && stridx(d.agname, '#')==-1 &&
                     \exists('#'.d.agname)
             call s:F.wipeau(d.agname)
         endif
 endfunction
 "▶2 augroup.add  :: {f}, agid, [event] → + :autocmd, s:augroups
 function s:F.augroup.add(plugdict, fdict, agid, events)
+    "▶3 Check arguments
+    if type(a:agid)!=type('')
+        call s:_f.throw('agidnstr', a:plugdict.id)
+    elseif a:agid!~#'^\w\+$'
+        call s:_f.throw('invagid', a:plugdict.id, a:agid)
+    elseif has_key(s:augroups,a:agid) && s:augroups[a:agid].plid!=#a:plugdict.id
+        call s:_f.throw('agiddef', a:agid,a:plugdict.id,s:augroups[a:agid].plid)
+    elseif type(a:events)!=type([])
+        call s:_f.throw('agenlst', a:agid, a:plugdict.id)
+    elseif empty(a:events)
+        call s:_f.throw('noevents', a:agid, a:plugdict.id)
+    elseif !empty(filter(copy(a:events), 'type(v:val)!='.type([])))
+        call s:_f.throw('enlst', a:agid, a:plugdict.id)
+    elseif !empty(filter(copy(a:events), 'len(v:val)!=4'))
+        call s:_f.throw('en3lst', a:agid, a:plugdict.id)
+    endif
+    "▲3
     if has_key(s:augroups, a:agid)
         let augroup=s:augroups[a:agid]
     else
     let d={}
     for [d.event, d.pattern, d.nested, d.command] in a:events
         let epc=[]
-        call add(epc, join(d.event, ","))
+        if type(d.event)==type('')
+            call add(epc, split(d.event, ','))
+        elseif type(d.event)==type([])
+            call add(epc, d.event)
+        "▶3 Invalid event types
+        else
+            call s:_f.throw('etypenslst', i, a:agid, a:plugdict.id)
+        endif
+        if !empty(filter(copy(epc[0]), 'type(v:val)!='.type('').' || '.
+                    \                  'v:val=~#"\\_[^a-zA-Z]" || '.
+                    \                  '!exists("##".v:val)'))
+            call s:_f.throw('invetypes', i, a:agid, a:plugdict.id)
+        endif
+        "▲3
+        let epc[0]=join(epc[0], ',')
+        "▶3 Check pattern
+        if type(d.pattern)!=type('')
+            call s:_f.throw('ptrnstr', i, a:agid, a:plugdict.id)
+        endif
+        "▲3
         call add(epc, escape(d.pattern, ' '))
+        "▶3 Check nested
+        if d.nested isnot 0 && d.nested isnot 1
+            call s:_f.throw('nestnbool', i, a:agid, a:plugidct.id)
+        endif
+        "▲3
         if d.nested
             call add(epc, 'nested')
         endif
         if type(d.command)==type([])
+            "▶3 Check d.command
+            if empty(d.command)
+                call s:_f.throw('emptycmd', i, a:agid, a:plugdict.id)
+            endif
+            "▲3
             let augroup.args[i]=d.command[1:]
             let d.command=d.command[0]
         endif
             let augroup.wrapfunc=a:plugdict.g._f.wrapfunc
             let augroup.funcs[i]=d.command
             let epc+=['call s:F.aurun('.string(a:agid).', '.i.')']
-        elseif !has_key(augroup.args, i) && type(d.command)==type("")
+        elseif !has_key(augroup.args, i) && type(d.command)==type('')
             call add(epc, substitute(d.command, '<SID>',
                         \            '<SNR>'.a:plugdict.sid.'_', 'g'))
+        "▶3 Unknown d.command
+        else
+            call s:_f.throw('ukncmd', i, a:agid, a:plugdict.id)
         endif
+        "▲3
         call add(augroup.events, join(epc))
         let i+=1
         unlet d.event d.pattern d.command
     let a:fdict[augroup.id]=augroup
     call s:F.createau(augroup)
 endfunction
-let s:F.augroup.add=s:_f.wrapfunc({'function': s:F.augroup.add,
-            \                          '@FWC': ['_ _'.
-            \'(#invagid(@^.0.id, .) match/\v^\w+$/ #^'.
-            \ 'either not key augroups, '.
-            \        '#agiddef(., @<<.id, augroups.(@).plid) '.
-            \           'value @<<.id is augroups.(@^^.2).plid)'.
-            \'list tuple ((if type "" |*$"split"(. ",") () '.
-            \             'list (type "" match /\v^\w+$/ '.
-            \                   '#invetype(%, @<, @<<<.id, @) '.
-            \                                   '?=exists("##".@.@))), '.
-            \            '(type ""), '.
-            \            'bool, '.
-            \            '(either ((type string, function, dictionary), '.
-            \                     '(type [] #emptycmd(%, @<, @<<<.id) '.
-            \                              '?=!empty(@.@)))))',
-            \'filter']})
 "▶2 Define feature
 call s:_f.newfeature('augroup', {'cons': s:F.augroup,
             \                  'unload': s:F.augroup.del,})

test/invalid-augroup.add.ok

-.1: plugin/frawor/fwc/compiler:FWCfail
->>> .1: messages
-plugin/frawor/fwc/compiler:typefail
-plugin/frawor/autocommands:invagid
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.2: plugin/frawor/fwc/compiler:FWCfail
->>> .2: messages
-plugin/frawor/fwc/compiler:nregmatch
-plugin/frawor/autocommands:invagid
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.4: plugin/frawor/fwc/compiler:FWCfail
->>> .4: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.5: plugin/frawor/fwc/compiler:FWCfail
->>> .5: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.6: plugin/frawor/fwc/compiler:FWCfail
->>> .6: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.7: plugin/frawor/fwc/compiler:FWCfail
->>> .7: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.8: plugin/frawor/fwc/compiler:FWCfail
->>> .8: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.9: plugin/frawor/fwc/compiler:FWCfail
->>> .9: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.10: plugin/frawor/fwc/compiler:FWCfail
->>> .10: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.11: plugin/frawor/fwc/compiler:FWCfail
->>> .11: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.12: plugin/frawor/fwc/compiler:FWCfail
->>> .12: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.13: plugin/frawor/fwc/compiler:FWCfail
->>> .13: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.14: plugin/frawor/fwc/compiler:FWCfail
->>> .14: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.15: plugin/frawor/fwc/compiler:FWCfail
->>> .15: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.16: plugin/frawor/fwc/compiler:FWCfail
->>> .16: messages
-plugin/frawor/fwc/compiler:nregmatch
-plugin/frawor/autocommands:invagid
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.17: plugin/frawor/fwc/compiler:FWCfail
->>> .17: messages
-plugin/frawor/fwc/compiler:typefail
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.19: plugin/frawor/fwc/compiler:FWCfail
->>> .19: messages
-plugin/frawor/fwc/compiler:notfail
-plugin/frawor/fwc/compiler:isnot
-plugin/frawor/fwc/compiler:eitherfail
-plugin/frawor/autocommands:agiddef
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
-.20: plugin/frawor/fwc/compiler:FWCfail
->>> .20: messages
-plugin/frawor/fwc/compiler:typefail
-plugin/frawor/fwc/compiler:FWCfail
-<<< messages
+.1: plugin/frawor/autocommands:agidnstr
+.2: plugin/frawor/autocommands:invagid
+.3: plugin/frawor/autocommands:noevents
+.4: plugin/frawor/autocommands:en3lst
+.5: plugin/frawor/autocommands:etypenslst
+.6: plugin/frawor/autocommands:en3lst
+.7: plugin/frawor/autocommands:etypenslst
+.8: plugin/frawor/autocommands:invetypes
+.9: plugin/frawor/autocommands:invetypes
+.10: plugin/frawor/autocommands:ukncmd
+.11: plugin/frawor/autocommands:ptrnstr
+.12: plugin/frawor/autocommands:ukncmd
+.13: plugin/frawor/autocommands:emptycmd
+.14: plugin/frawor/autocommands:ukncmd
+.15: plugin/frawor/autocommands:nowrapfunc
+.16: plugin/frawor/autocommands:invagid
+.17: plugin/frawor/autocommands:agenlst
+.19: plugin/frawor/autocommands:agiddef
+.20: plugin/frawor/autocommands:enlst

test/reload-frawor.ok

 load: plugin/writefile-feature
 unloadpre: autoload/frawor
 unloadpre: plugin/frawor/commands
+unloadpre: plugin/frawor/functions
 unloadpre: plugin/frawor/lua
 unloadpre: plugin/frawor/mappings
 unloadpre: plugin/frawor/perl
 unloadpre: plugin/frawor/tcl
 unloadpre: plugin/ignoredeps-feature
 unloadpre: plugin/frawor/autocommands
-unloadpre: plugin/frawor/functions
 unloadpre: plugin/frawor/options
 unloadpre: plugin/writefile-feature
 unloadpre: plugin/frawor/decorators/altervars
 unloadpre: plugin/frawor/checks
 unloadpre: plugin/frawor/fwc/compiler
+unloadpre: plugin/frawor/fwc/constructor
+unloadpre: plugin/frawor/fwc/parser
 unloadpre: plugin/frawor/decorators
 unloadpre: plugin/frawor/os
-unloadpre: plugin/frawor/fwc/constructor
-unloadpre: plugin/frawor/fwc/parser
 unloadpre: plugin/frawor/resources
 unloadpre: plugin/frawor
 unload: autoload/frawor
 unload: plugin/frawor/commands
+unload: plugin/frawor/functions
 unload: plugin/frawor/lua
 unload: plugin/frawor/mappings
 unload: plugin/frawor/perl
 unload: plugin/frawor/tcl
 unload: plugin/ignoredeps-feature
 _unload
+register: plugin/frawor/decorators
+load: plugin/frawor/decorators
 register: plugin/frawor/autocommands
 load: plugin/frawor/autocommands
-register: plugin/frawor/checks
-load: plugin/frawor/checks
+register: plugin/ignoredeps-feature
+load: plugin/ignoredeps-feature
+register: plugin/frawor/fwc/constructor
+load: plugin/frawor/fwc/constructor
+register: plugin/frawor/os
+load: plugin/frawor/os
+register: autoload/frawor
+load: autoload/frawor
+register: plugin/writefile-feature
+load: plugin/writefile-feature
+register: plugin/frawor/options
+load: plugin/frawor/options
 register: plugin/frawor/fwc/parser
 load: plugin/frawor/fwc/parser
 register: plugin/frawor
 load: plugin/frawor
-register: plugin/frawor/decorators
-load: plugin/frawor/decorators
-register: plugin/frawor/os
-load: plugin/frawor/os
+register: plugin/frawor/fwc/compiler
+load: plugin/frawor/fwc/compiler
 register: plugin/frawor/resources
 load: plugin/frawor/resources
-register: plugin/ignoredeps-feature
-load: plugin/ignoredeps-feature
-register: plugin/frawor/fwc/constructor
-load: plugin/frawor/fwc/constructor
-register: autoload/frawor
-load: autoload/frawor
+register: plugin/frawor/checks
+load: plugin/frawor/checks
 register: plugin/frawor/decorators/altervars
 load: plugin/frawor/decorators/altervars
-register: plugin/frawor/options
-load: plugin/frawor/options
-register: plugin/frawor/functions
-load: plugin/frawor/functions
-register: plugin/frawor/fwc/compiler
-load: plugin/frawor/fwc/compiler
-register: plugin/writefile-feature
-load: plugin/writefile-feature
 register: plugin/frawor/tcl
 load: plugin/frawor/tcl
 register: plugin/frawor/ruby
 load: plugin/frawor/mappings
 register: plugin/frawor/lua
 load: plugin/frawor/lua
+register: plugin/frawor/functions
+load: plugin/frawor/functions
 register: plugin/frawor/commands
 load: plugin/frawor/commands