Commits

ZyX_I committed 2887390

@/fwc/constructor: Added minimization possibilities

Comments (0)

Files changed (3)

     |FWC-ck-_l| pointing to a tree.
 _toblock :: blocktype -> + self._l, self._stack              *FWC-cf-_toblock*
     Removes items from |FWC-ck-_stack| until it finds block with given type.
-_tolist :: () -> [ String ]                                   *FWC-cf-_tolist*
-    Constructs and returns a list of VimL commands.
+_tolist :: [ min] -> [ String ]                               *FWC-cf-_tolist*
+    Constructs and returns a list of VimL commands. If {min} optional argument 
+    is present and true, then it removes indent and minimizes vim commands.
 break :: () -> self                                          *FWC-cf-break*
 continue :: () -> self                                       *FWC-cf-continue*
     Adds |FWC-cb-do| with argument equal to function name and goes up one 
     3.1: Made self.continue and self.break go up one level.
     4.0: Splitted self.addif(expr?) into self.addif(expr) and self.addelse()
     4.1: Added self.endfor() and self.endwhile().
+    4.2: Made it possible to minimize code (currently only indent is removed 
+         and command names are truncated).
 @/os:
     0.1: Added |frawor-r-os.path.relpath|
          Made |frawor-r-os.path.normpath| also simplify its argument

plugin/frawor/fwc/constructor.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('4.1', {'@/resources': '0.0'}, 1)
+execute frawor#Setup('4.2', {'@/resources': '0.0'}, 1)
 let s:constructor={}
 let s:comp={}
 let s:constructor._comp=s:comp
+"▶1 indent
+function s:F.indent(indent)
+    return repeat(' ', &sw*a:indent)
+endfunction
+"▶1 indentmin
+function s:F.indentmin(indent)
+    return ''
+endfunction
+"▶1 cmdmin
+let s:cmdmin={
+            \'while':    'wh',
+            \'endwhile': 'endw',
+            \'endfor':   'endfo',
+            \'continue': 'con',
+            \'break':    'brea',
+            \'call':     'cal',
+            \'elseif':   'elsei',
+            \'else':     'el',
+            \'endif':    'en',
+            \'throw':    'th',
+            \'catch':    'cat',
+            \'finally':  'fina',
+            \'endtry':   'endt',
+            \'execute':  'exe',
+            \'echo':     'ec',
+            \'echomsg':  'echom',
+            \'unlet':    'unl',
+            \'return':   'retu',
+        \}
+"▶1 c
+function s:comp.c(cmd, arg)
+    return get(self._cmds, a:cmd, a:cmd).(empty(a:arg)?(''):(' ')).a:arg
+endfunction
 "▶1 string     :: a → String
 function s:constructor.string(val)
     if type(a:val)==type('') && a:val=~#"[\r\n@]"
 "▶1 do: do, continue, break
 "▶2 comp.do
 function s:comp.do(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).remove(a:item, 0))
+    call add(a:r, self.indent(a:indent).remove(a:item, 0))
 endfunction
 "▶2 continue   :: &self
 function s:constructor.continue()
 "▶1 if block
 "▶2 comp.if
 function s:comp.if(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'if '.remove(a:item, 0))
+    call add(a:r, self.indent(a:indent).'if '.remove(a:item, 0))
     if !empty(a:item)
         call extend(a:toextend,map(remove(a:item,0),'['.(a:indent+1).',v:val]'))
     endif
     while !empty(a:item)
         let type=remove(a:item, 0)
         if type is# 'elseif'
-            call add(a:toextend, [a:indent, 'elseif '.remove(a:item, 0)])
+            call add(a:toextend, [a:indent, self.c('elseif',remove(a:item,0))])
         elseif type is# 'else'
-            call add(a:toextend, [a:indent, 'else'])
+            call add(a:toextend, [a:indent, self.c('else','')])
         elseif type is# 'endif'
             break
         endif
         call extend(a:toextend,map(remove(a:item,0),'['.(a:indent+1).',v:val]'))
     endwhile
-    call add(a:toextend, [a:indent, 'endif'])
+    call add(a:toextend, [a:indent, self.c('endif','')])
 endfunction
 "▶2 if         :: &self(expr)
 function s:constructor.if(expr)
 "▶1 try block
 "▶2 comp.try
 function s:comp.try(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'try')
+    call add(a:r, self.indent(a:indent).'try')
     if !empty(a:item)
         call extend(a:toextend,map(remove(a:item,0),'['.(a:indent+1).',v:val]'))
     endif
     while !empty(a:item)
         let type=remove(a:item, 0)
         if type is# 'catch'
-            call add(a:toextend, [a:indent, 'catch '.remove(a:item, 0)])
+            call add(a:toextend, [a:indent, self.c('catch',remove(a:item, 0))])
         elseif type is# 'finally'
-            call add(a:toextend, [a:indent, 'finally'])
+            call add(a:toextend, [a:indent, self.c('finally', '')])
         elseif type is# 'endtry'
             break
         endif
         call extend(a:toextend,map(remove(a:item,0),'['.(a:indent+1).',v:val]'))
     endwhile
-    call add(a:toextend, [a:indent, 'endtry'])
+    call add(a:toextend, [a:indent, self.c('endtry', '')])
 endfunction
 "▶2 try        :: &self()
 function s:constructor.try()
 "▶1 cycles: while, for; continue, break
 "▶2 comp.while
 function s:comp.while(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'while '.remove(a:item, 0))
+    call add(a:r, self.indent(a:indent).self.c('while', remove(a:item, 0)))
     call extend(a:toextend, map(remove(a:item, 0), '['.(a:indent+1).', v:val]'))
-    call add(a:toextend, [a:indent, 'endwhile'])
+    call add(a:toextend, [a:indent, self.c('endwhile', '')])
 endfunction
 "▶2 while      :: &self(expr)
 function s:constructor.while(expr)
 endfunction
 "▶2 comp.for
 function s:comp.for(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'for '.remove(a:item, 0).' in '.
+    call add(a:r, self.indent(a:indent).'for '.remove(a:item, 0).' in '.
                 \                                             remove(a:item, 0))
     call extend(a:toextend, map(remove(a:item, 0), '['.(a:indent+1).', v:val]'))
-    call add(a:toextend, [a:indent, 'endfor'])
+    call add(a:toextend, [a:indent, self.c('endfor', '')])
 endfunction
 "▶2 for        :: &self(var, expr)
 function s:constructor.for(var, expr)
 "▶1 execute: call, throw, return
 "▶2 comp.execute
 function s:comp.execute(r, toextend, indent, item)
-    call add(a:r,repeat(' ',&sw*a:indent).remove(a:item,0).' '.remove(a:item,0))
+    call add(a:r,self.indent(a:indent).self.c(remove(a:item,0),
+                \                             remove(a:item,0)))
 endfunction
 "▶2 return, call, execute, echo, echomsg, echon
 for s:type in ['return', 'call', 'execute', 'echo', 'echomsg', 'echon']
 "▶1 let: let, strappend, increment, decrement
 "▶2 comp.let
 function s:comp.let(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'let '.remove(a:item, 0).
-                \                               remove(a:item, 0).'='.
-                \                                  remove(a:item, 0))
+    call add(a:r, self.indent(a:indent).self.c('let', remove(a:item, 0).
+                \                                remove(a:item, 0).'='.
+                \                                     remove(a:item, 0)))
 endfunction
 "▶2 let, strappend
 for [s:type, s:s] in [['let', ''], ['strappend', '.']]
 endfunction
 "▶1 unlet      :: &self(var|[var])
 function s:comp.unlet(r, toextend, indent, item)
-    call add(a:r, repeat(' ', &sw*a:indent).'unlet '.join(remove(a:item, 0)))
+    call add(a:r, self.indent(a:indent).self.c('unlet', join(remove(a:item,0))))
 endfunction
 function s:constructor.unlet(var)
     return self._out()._deeper('unlet', type(a:var)==type('')?[a:var]:a:var)
                 \._up()
 endfunction
 "▶1 _tolist    :: () + self → [String]
-function s:constructor._tolist()
+function s:constructor._tolist(...)
     let r=[]
     let items=map(deepcopy(self._tree), '[0, v:val]')
     let toextend=[]
+    let self._comp.indent=((a:0 && a:1)?(s:F.indentmin):(s:F.indent))
+    let self._comp._cmds=((a:0 && a:1)?(s:cmdmin):({}))
     while !empty(items)
         let [indent, item]=remove(items, 0)
         if type(item)==type('')
-            call add(r, repeat(' ', &sw*indent).item)
+            call add(r, self._comp.indent(indent).item)
         else
             let type=remove(item, 0)
             if has_key(self._comp, type)
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.