ZyX_I  committed 13b128e

@/decorators/altervars: Added `window special setter\n@/fwc/constructor: Added some new functions that can be used by other plugins (not by FWC)

  • Participants
  • Parent commits 1f14fab

Comments (0)

Files changed (3)

File doc/frawor.txt

                    one of `b', `t' or `w' as an optional argument for buffer, 
                    tabpage or window-local variables).
         buffer     Saves and restores current buffer number.
+        window     Saves and restores current tab page and window.
         winview    Saves and restores window view (using |winsaveview()| and 
         matches    Saves and restores matches (using |getmatches()| and 

File plugin/frawor/decorators/altervars.vim

 let s:F.saver={}
 let s:F.setter={}
 let s:F.sschk={}
+"▶2 window
+function s:F.saver.window()
+    return [tabpagenr(), winnr()]
+function s:F.setter.window(twnr)
+    if type(a:twnr)==type([]) && len(a:twnr)==2
+                \&& type(a:twnr[0])==type(0) && a:twnr[0]<=tabpagenr('$')
+                \&& type(a:twnr[1])==type(0) && a:twnr[1]<=winnr('$')
+        try
+            if tabpagenr()!=a:twnr[0]
+                execute 'tabnext' a:twnr[0]
+            endif
+            if winnr()!=a:twnr[1]
+                execute a:twnr[1].'wincmd w'
+            endif
+        catch
+            echohl ErrorMsg
+            echomsg v:exception
+            echohl None
+        endtry
+    endif
+call s:_f.addaltspecial('window', s:F.saver.window, s:F.setter.window)
 "▶2 winview
 call s:_f.addaltspecial('winview', function('winsaveview'),
             \                      function('winrestview'))
 function s:F.setter.buffer(bufnr)
     if type(a:bufnr)==type(0) && a:bufnr!=bufnr('%') && bufexists(a:bufnr)
-            execute "buffer ".a:bufnr
+            execute 'buffer' a:bufnr
             " Setter must not throw anything: it may break things
             echohl ErrorMsg

File plugin/frawor/fwc/constructor.vim

 function s:constructor.let(var, val)
     return self.out().deeper('let', a:var, a:val).up()
+"▶1 strappend  :: &self(var, val)
+function s:constructor.strappend(var, val)
+    return self.out().deeper('append', a:var, a:val).up()
 "▶1 unlet      :: &self(var)
 function s:constructor.unlet(var)
     return self.out().deeper('unlet', type(a:var)==type('')?[a:var]:a:var).up()
 function s:constructor.increment(var, ...)
     return self.out().deeper('inc', a:var, get(a:000, 0, 1)).up()
+"▶1 decrement  :: &self(var, val)
+function s:constructor.decrement(var, val)
+    return self.out().deeper('dec', a:var, get(a:000, 0, 1)).up()
 "▶1 call       :: &self(expr)
     return self.out().deeper('call', a:expr).up()
 function s:constructor.throw(expr)
     return self.out().deeper('throw', a:expr).up().up()
+"▶1 do         :: &self(vimLstr)
+    return self.out().deeper('do', a:str).up()
 "▶1 tolist     :: () + self → [String]
 function s:constructor.tolist()
     let r=[]
                 call add(toextend, [indent, 'endfor'])
             elseif type is# 'let'
                 call add(r, istr.'let '.remove(item, 0).'='.remove(item, 0))
+            elseif type is# 'append'
+                call add(r, istr.'let '.remove(item, 0).'.='.remove(item, 0))
             elseif type is# 'inc'
                 let lhs=remove(item, 0)
                 let assign='+='
                     let shift=-shift
                 call add(r, istr.'let '.lhs.assign.shift)
+            elseif type is# 'dec'
+                call add(r, istr.'let '.remove(item, 0).'-='.remove(item, 0))
             elseif       type is# 'call'   ||
                         \type is# 'throw'  ||
                         \type is# 'return'
                 call add(r, istr.type.' '.join(remove(item, 0)))
             elseif type is# 'continue' || type is# 'break'
                 call add(r, istr.type)
+            elseif type is# 'do'
+                call add(r, remove(item, 0))
             if !empty(toextend)
                 call extend(items, remove(toextend, 0, -1), 0)