Commits

ZyX_I  committed 8462955

Added support for $time#non-default format#
Fixed one-line templates

  • Participants
  • Parent commits f641efa

Comments (0)

Files changed (1)

File plugin/aurum/log.vim

     endif
 endfunction
 "▶2 temp.syntax :: template, opts → [VimCommand] + :syn
+"▶3 Some globals
 let s:syncache={}
 let s:schs='%([|+\-/\\]\ *)'
+let s:noargtimereg='\v\d\d \S+ \d{4,} \d\d:\d\d'
+let s:ukntkws=['c', 'x', 'X', '+']
+let s:timekwregs={
+            \'a': '\S\{1,3}',
+            \'A': '\S\+',
+            \'b': '\S\{1,3}',
+            \'B': '\S\+',
+            \'C': '\d\d',
+            \'d': '\d\d',
+            \'D': '\d\d\/\d\d\/\d\d',
+            \'e': '\[1-3 ]\d',
+            \'F': '\d\{4,}-\d\d-\d\d',
+            \'G': '\d\{4,}',
+            \'g': '\d\d',
+            \'h': '\S\{1,3}',
+            \'H': '\d\d',
+            \'I': '\d\d',
+            \'j': '\d\{3}',
+            \'k': '\[12 ]\d',
+            \'l': '\[1 ]\d',
+            \'m': '\d\d',
+            \'M': '\d\d',
+            \'n': '\n',
+            \'p': '\[AP]M',
+            \'P': '\[ap]m',
+            \'r': '\d\d:\d\d:\d\d \[AP]M',
+            \'R': '\d\d:\d\d',
+            \'s': '\d\+',
+            \'S': '\d\d',
+            \'t': '\t',
+            \'T': '\d\d:\d\d:\d\d',
+            \'u': '\[1-7]',
+            \'U': '\d\d',
+            \'V': '\d\d',
+            \'w': '\[0-6]',
+            \'W': '\d\d',
+            \'y': '\d\d',
+            \'Y': '\d\{4,}',
+            \'z': '\[+\-]\d\{4}',
+            \'Z': '\S\{3}',
+            \'%': '%',
+        \}
+"▲3
+" TODO Test this
 function s:F.temp.syntax(template, opts)
     "▶3 Cache
     let cid=string(a:opts.templatefunc)[10:-3]
                     let r+=['syn match auLog_'.kw.' /\v.*/ '.
                                 \'contained nextgroup=']
                 elseif kw is# 'time'
-                    " TODO Add argument parsing
                     call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
+                    if has_key(arg, 0)
+                        if j<=llit && !empty(lit[j+1])
+                            let creg='\%(\%('.escape(lit[j+1], '\/').'\)\@!'.
+                                        \'\.\)\*'
+                        else
+                            let creg='\.\*'
+                        endif
+                        let reg='\V'.substitute(escape(arg.0, '\/'), '\v\%(.)',
+                                    \'\=index(s:ukntkws, submatch(1))==-1 ?'.
+                                    \   'get(s:timekwregs, submatch(1), '.
+                                    \       'submatch(0)) :'.
+                                    \   'creg', 'g')
+                    else
+                        let reg=s:noargtimereg
+                    endif
                     let r+=['syn match auLog_time '.
-                                \'/\v\d\d \S+ \d{4,} \d\d:\d\d/ '.
+                                \'/'.reg.'/ '.
                                 \'contained nextgroup=']
                 elseif has_key(s:kwreg, kw)
                     call s:F.temp.addgroup(r, nlgroups, 'auLog_'.kw)
         let r[-1].=' skipnl'
         let i+=1
     endfor
-    let r+=['syn match auLogNextLineStart @\v'.s:schs.'+@ skipwhite '.
-                \'contained nextgroup='.join(nlgroups, ',')]
+    if !empty(nlgroups)
+        let r+=['syn match auLogNextLineStart @\v'.s:schs.'+@ skipwhite '.
+                    \'contained nextgroup='.join(nlgroups, ',')]
+    endif
     let s:syncache[cid]=r
     return r
 endfunction