Commits

ZyX_I committed f55e41f

@%aurum/log/templates: Fixed template compiler
(it was removing some specials and joining lines under
certain conditions)

Comments (0)

Files changed (1)

autoload/aurum/log/templates.vim

 let s:addexpr='((eval(submatch(1))!=0)?'.
             \           '(printf("%+i", eval(submatch(1)))):'.
             \           '(""))'
-function s:F.strappend(func, s)
+function s:F.strappend(func, s, nl)
     let func=a:func
-    if func[-1][:13] is# 'let text[-1].='
+    if a:nl
+        let i=len(func)
+        while i
+            let i-=1
+            if func[i] is# 'let text+=[""]'
+                call remove(func, i)
+                break
+            endif
+        endwhile
+        let func+=['let text+=['.a:s.']']
+    elseif func[-1][:13] is# 'let text[-1].='
         let func[-1].='.'.a:s
     elseif func[-1][:10] is# 'let text+=['
         let func[-1]=func[-1][:-2].'.'.a:s.']'
 "▶1 compile :: template, opts → Fref
 let s:add={}
 "▶2 add.ke2 : Add complex multiline statement
-function s:add.ke2(addedif, expr, kw, arg, func)
+function s:add.ke2(addedif, expr, kw, arg, func, nl)
     let addedif2=0
     let func=a:func
     let func+=[s:setlstrstr]
     endif
 endfunction
 "▶2 add.ke1 : Add simple multiline statements
-function s:add.ke1(addedif, expr, kw, arg, func)
+function s:add.ke1(addedif, expr, kw, arg, func, nl)
     let addedif2=0
     let func=a:func
     let func+=[s:setlstrstr]
     endif
 endfunction
 "▶2 add.ke0 : Add single-line statement
-function s:add.ke0(addedif, expr, kw, arg, func)
+function s:add.ke0(addedif, expr, kw, arg, func, nl)
     let func=a:func
     let add2if=0
     if a:kw is# 'branch' && a:arg.0 isnot# 'keep' && !a:addedif
         endif
     endif
     "▲3
+    if a:nl
+        let  lexpr='len(text)'
+        let llexpr='0'
+    else
+        let  lexpr='len(text)-1'
+        let llexpr='len(text[-1])'
+    endif
     let func+=['let special.'.a:kw.'_r='.
-                \  '[[len(text)-1, len(text[-1])], '.
-                \   '[len(text)-1, len(text[-1])-1+len(estr)]]',]
-    call s:F.strappend(func, 'estr')
+                \  '[['.lexpr.', '.llexpr.'], '.
+                \   '['.lexpr.', '.llexpr.'-1+len(estr)]]',]
+    call s:F.strappend(func, 'estr', a:nl)
     if add2if
         let func+=['endif']
     endif
         "▲2
         let func+=['let text+=[""]']
         let i=-1
+        let nl=1
         for str in lit
             let i+=1
             if !empty(str)
-                if i==0
-                    let func[-1]='let text+=['.string(str).']'
-                else
-                    call s:F.strappend(func, string(str))
-                endif
+                call s:F.strappend(func, string(str), nl)
+                let nl=0
             endif
             if lmeta>i
                 "▶2 Define variables
                     call extend(reqs, s:kwreqs[kw])
                 endif
                 "▲2
-                call s:add['ke'.ke[0]](addedif, expr, kw, arg, func)
+                call s:add['ke'.ke[0]](addedif, expr, kw, arg, func, nl)
+                let nl=0
             endif
         endfor
         if addedif
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.