Commits

ZyX_I committed b99a842 Merge

Merge

Comments (0)

Files changed (2)

macros/fstree.vim

     let b=+a:b
     return ((a==b)?(0):((a>b)?(1):(-1)))
 endfunction
+let s:mappings={}
+let s:mappings.show={'lhs': 'p', 'selection': 'save'}
+function s:mappings.show.function(bvar, node)
+    echom join(a:node.path, s:_r.os.sep)
+    return ''
+endfunction
+let s:mappings.showpath={'lhs': 'P'}
+function s:mappings.showpath.function(bvar, node)
+    echom string(a:node.path)
+    return ''
+endfunction
 call s:_f.tree.add('fs', s:F.get, {'columns': s:columns,
             \                   'coldefault': ['name', 'size'],
+            \                     'mappings': s:mappings,
             \                      'options': {'colopts':
             \                                   {'size':
             \                                       {'align': 'right',

plugin/gtregen.vim

 let s:trees={}
 "▶1 Default mappings
 let s:defmappings={}
+"▶2 (un)selection
 let s:defmappings._select={'lhs': 's', 'selection': 'ignore', 'passnodes': 0}
 function s:defmappings._select.function(bvar, lnr)
-    let a:bvar.selected[a:lnr]=1
-    " TODO syntax
+    let synname='TreeSelected_'.a:lnr
+    let a:bvar.selected[a:lnr]=synname
+    let blnr=a:lnr+a:bvar.cstart
+    execute 'syntax region '.synname.' start=/\v^%'.blnr.'l/'.
+                \                    ' end=/\v%'.blnr.'l$/'.
+                \                    ' contains=TreeSelected'.
+                \                    ' contained containedin=TreeData'
     return ''
 endfunction
 let s:defmappings._unselect={'lhs': 'S', 'selection': 'ignore', 'passnodes': 0}
-function s:defmappings._unselect.function(bvar, lnr)
+function s:F.unselect(bvar, lnr)
     if has_key(a:bvar.selected, a:lnr)
-        unlet a:bvar.selected[a:lnr]
-        " TODO syntax
+        let synname=remove(a:bvar.selected, a:lnr)
+        execute 'syntax clear '.synname
     endif
     return ''
 endfunction
+let s:defmappings._unselect.function=s:F.unselect
 "▶1 runmap :: tree, mdescr
 function s:F.runmap(tree, mdescr, mode)
     let bvar=s:_r.bufvars[bufnr('%')]
+    let postcmd=''
     if a:mode is# 'x'
         let lstart=line("'<")
         let lend=line("'>")
             let lend=bvar.cend
         endif
         let selection=range(lstart-bvar.cstart, lend-bvar.cstart)
+        " TODO Use vselection here?
+        if a:mdescr.selection isnot# 'save'
+            let postcmd="\<C-\>\<C-n>"
+        endif
     elseif a:mode is# 'n'
         if a:mdescr.selection isnot# 'ignore' && !empty(bvar.selected)
             let selection=map(keys(bvar.selected), '+v:val')
-            " TODO empty selection after mapping
+            if a:mdescr.selection isnot# 'save'
+                call map(copy(selection), 's:F.unselect(bvar, v:val)')
+            endif
         else
             let line=line('.')
             if line<bvar.cstart
     endif
     if a:mdescr.multrun is# 'map' || (a:mdescr.multrun is# 'no' &&
                 \                     len(selection)==1)
-        return join(map(selection, 'a:mdescr.function(bvar, v:val)'), '')
+        return join(map(selection, 'a:mdescr.function(bvar,v:val)'), '').postcmd
     elseif a:mdescr.multrun is# 'list'
-        return a:mdescr.function(bvar, selection)
+        return a:mdescr.function(bvar, selection).postcmd
     else
         call s:_f.throw('invrun')
     endif
-    return ''
+    return postcmd
 endfunction
 "▶1 tree.add :: {f}, tid, Func, options → + s:trees, :au
 let s:tree.cons={'add': {}, 'del': {}}
     for [mapname, mdescr] in items(extend(copy(s:defmappings),
                 \                         get(a:options, 'mappings', {})))
         let tree.mappings[mapname]={'function': mdescr.function,
-                    \                'multrun': get(mdescr, 'multrun',   'map'),
-                    \                'treerun': get(mdescr, 'treerun',   'no' ),
-                    \              'passnodes': get(mdescr, 'passnodes',   1  ),
-                    \              'selection': get(mdescr, 'selection', 'use')}
+                    \                'multrun': get(mdescr,'multrun',  'map'  ),
+                    \                'treerun': get(mdescr,'treerun',  'no'   ),
+                    \              'passnodes': get(mdescr,'passnodes',1      ),
+                    \              'selection': get(mdescr,'selection','clear'),
+                    \}
         " TODO operator mappings
         " TODO non-expr mappings
         let mappings[mapname]={'lhs': get(mdescr, 'lhs', 0),
             \                         '?match /\v^\a\w*$/ '.
             \                               '(haskey function '.
             \                                'dict {'.
-            \                                   'function (|isfunc)'.
-            \                                   'multrun  in [map list no]'.
-            \                                   'treerun  in [leafs trees all '.
-            \                                                'no]'.
-            \                                   'lhs      type ""'.
+            \                                  ' function  (|isfunc)'.
+            \                                  ' multrun   in [map list no]'.
+            \                                  ' treerun   in [leafs trees all'.
+            \                                                ' no]'.
+            \                                  ' lhs       type ""'.
+            \                                  ' selection in [ignore clear'.
+            \                                                ' save]'.
             \                                '})'.
             \                       '} '.
             \          '}',
                     \      a:bvar.colwidths[i], islast)
         let i+=1
     endfor
+    " TODO Make this syntax highlighting merge with existing
+    syntax match TreeSelected /.*/ contained
     "▲2
     setlocal modifiable noreadonly
     call setline('.', lines)