On Wed, 23 Mar 2011, Tim Chase wrote:
On 03/21/2011 11:58 PM, c b wrote:
Hi Tom,
s/Tom/Tim/
:)
On Mon, Mar 21, 2011 at 5:31 PM, Tim Chase<v...@tim.thechases.com> wrote:
On 03/21/2011 01:43 PM, sanjay ravat wrote:
[2011-03-21T18:45:46.004-07:00] [Other info]... log message
[2011-03-21T18:45:46.008-07:00] [Other info]... log message
[2011-03-21T18:45:46.607-07:00] [Other info]... log message
Thanks for the example data and better description. After
experimenting with it, I came up with the following:
:set foldmethod=expr
foldexpr=(getline(v:lnum)[:19]==getline(v:lnum+1)[:19])?1:'<1'
Change the 19 according to which depth you want:
Seconds: 19 (above example)
Minutes: 16
Hours: 13
Days: 10
Months: 7
Years: 4
1. How can we expand this so that multiple nesting (based on
timestamp) will be supported? i.e. if we have logs for two days
2011-03-20 and 2011-03-21, the first level would have only two lines
shown (when folded) viz. 2011-03-20 and 2011-03-21. Then upon opening
one of the folds, each would have upto 24 folds (one for each hour),
then each hour would have upto 60 folds (one for each minute) and so
on.
You can tweak the expression to chain them...something ugly like
set
foldexpr=(getline(v:lnum)[:19]==getline(v:lnum+1)[:19])?6:((getline(v:lnum)[:16]==getline(v:lnum+1)[:16])?'<6':((getline(v:lnum)[:13]==getline(v:lnum+1)[:13])?'<5':((getline(v:lnum)[:10]==getline(v:lnum+1)[:10])?'<4':((getline(v:lnum)[:7]==getline(v:lnum+1)[:7])?'<3':((getline(v:lnum)[:4]==getline(v:lnum+1)[:4])?'<2':'<1')))))
looks like it works for me.
Get thee to a function!
Tested... but there are some off-by-one issues. (The indices of the
array start at 0, and '<1' is taken for 'no fold here', so the levels
start at 2.) (Don't have time to fix it right now... just
procrastinating at work...)
Use it by setting up the functions:
:set foldmethod=expr foldexpr=TimeStampFoldExpr() foldtext=TimeStampFoldText()
[===] :se fdm=expr fde=TimeStampFoldExpr() fdt=TimeStampFoldText()
==> ~/.vim/plugin/timestampfold.vim <==
let s:levels = [ 4, 7, 10, 13, 16, 19 ]
fun! s:TimeStamp(lnum,i)
let off = s:levels[a:i < 0 ? 0 : a:i]
return getline(a:lnum)[:off]
endfun
fun! TimeStampFoldExpr()
let prefix = ''
for i in reverse(range(len(s:levels)))
let lev = i + 2
let offset = levels[i]
if s:TimeStamp(v:lnum,i) == s:TimeStamp(v:lnum+1,i)
return prefix . lev
endif
let prefix = '<'
endfor
return prefix . '1'
endfun
fun! TimeStampFoldText()
return v:folddashes . s:TimeStamp(v:foldstart, v:foldlevel-2)
endfun
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php