ZyX_I avatar ZyX_I committed 6e8b3c2

@/fwc: Made `isfunc' be also a filter that transforms its argument into a function reference

Comments (0)

Files changed (6)

     You can't check for floating-point values if vim is compiled without 
     |+float| feature.
 
-isfunc {one}   (|FWC-{one}|)                                    *FWC-c-isfunc*
+isfunc {one}   (|FWC-{one}|)                     *FWC-f-isfunc* *FWC-c-isfunc*
     Checker: checks whether argument is a name of a callable function or 
              a callable function reference. If optional argument is 1, then 
              only function references are allowed.
              Names of dictionary items are also allowed, but only if they 
              start with scope prefix and do use only dotted subscripts 
              (dict.key).
+    Filter: checks argument with above rules and if check succeeds, transforms 
+            it into a function reference (unless it is a reference already).
 
 isreg                                                            *FWC-c-isreg*
     Checker: checks whether argument is a valid regular expression.
     0.1: (intfuncs-0.1) Added |FWC-c-idof|
     0.2: (intfuncs-0.2) Made |FWC-f-path| filter expand argument
     0.3: (intfuncs-0.3) Added -onlystrings support for |FWC-c-range|
+    0.4: (intfuncs-0.4) Made |FWC-f-isfunc| transform argument to a function 
+                        reference
 @/os:
     0.1: Added |frawor-r-os.path.relpath|
          Made |frawor-r-os.path.normpath| also simplify its argument

plugin/frawor/fwc.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('0.3', {'@/fwc/compiler': '0.0',
+execute frawor#Setup('0.4', {'@/fwc/compiler': '0.0',
             \                '@/decorators'  : '0.0'}, 1)
 "▶1 Define messages
 if v:lang=~?'ru'

plugin/frawor/fwc/intfuncs.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('0.3', {'@/resources': '0.0',
+execute frawor#Setup('0.4', {'@/resources': '0.0',
             \                '@/os':        '0.0',
             \                '@/signs':     '0.0',}, 1)
 let s:r={}
     endif
     return self
 endfunction
+function s:r.isfunc.pipe(desc, idx, type)
+    call call(s:r.isfunc.check, [a:desc, a:idx, a:type], self)
+    if !a:desc[1]
+        let curargstr=self.argstr()
+        call self.let(curargstr,
+                    \ '((type('.curargstr.')==2)?'.
+                    \   '('.curargstr.'):'.
+                    \ '((exists('.curargstr.'))?'.
+                    \    '(eval('.curargstr.'))'.
+                    \  ':'.
+                    \    '(function('.curargstr.'))))')
+    endif
+    return self
+endfunction
 "▶1 `isreg'
 " Checks whether {argument} is a valid regular expression
 let s:r.isreg={'args': []}
 plugin/frawor/fwc/compiler:nsfunc
 plugin/frawor/fwc/compiler:runfail
 plugin/frawor/fwc/compiler:evalfail
-plugin/frawor/fwc/compiler:nsfunc
 plugin/frawor/fwc/compiler:nmatch
 plugin/frawor/fwc/compiler:typefail
 1
 ::: Section <Pipes/Built-in pipes/tuple>
 plugin/frawor/fwc/compiler:invlstlen
 plugin/frawor/fwc/compiler:typefail
+::: Section <Pipes/Built-in pipes/isfunc>
+plugin/frawor/fwc/compiler:nsfunc
 ::: Section <Pipes/Built-in pipes/list>
 plugin/frawor/fwc/compiler:typefail
 plugin/frawor/fwc/compiler:typefail

test/fwctests.dat

 ['run [$[abc def]]',       'filter'], [s:.revstring],       0
 ['earg',                   'filter'], ['string("abc")'],    ["'abc'"]
 ['earg',                   'filter'], ['('],                0
-['isfunc',                 'filter'], [0],                  0
-['isfunc',                 'filter'], [function('tr')],     [function("tr")]
 ['take ={"abc": 1} start', 'filter'], ['a'],                [1]
 ['take ={"abc": 1} start', 'filter'], ['b'],                0
 ['take ={"abc": 1} start', 'filter'], [0],                  0
 ['tuple bool, bool',       'filter'], ['abc'],              0
 ['tuple (?bool |=(!@.@))', 'filter'], [[1]],                [[0]]
 ['tuple (tuple bool tuple bool, bool)', 'filter'], [[[''],[4,0]]], [[[0],[1,0]]]
+#▶3 isfunc
+:let g:Tr=function('tr')
+:let g:d={'tr': function('tr')}
+['isfunc',                 'filter'], [0],                  0
+['isfunc',                 'filter'], [function('tr')],     [function('tr')]
+['isfunc',                 'filter'], ['tr'],               [function('tr')]
+['isfunc',                 'filter'], ['g:Tr'],             [function('tr')]
+['isfunc',                 'filter'], ['g:d.tr'],           [function('tr')]
 #▶3 list
 ['list bool',              'filter'], ["['abc', 'def']"],   0
 ['list bool',              'filter'], [['abc', 'def']],     [[1, 1]]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.