Tuesday, June 9, 2020

Re: Wrapg text at col. 80 on large-ish files - performance aspects.

On 20/06/08 01:23PM, Chris Jones wrote:
> I imagine someone familiar with foldexpr's would see at a glance what's
> wrong with the fold expression when the number of lines in the file runs
> in the thousands...

Fold expressions are powerful, but they are evaluated for every line,
and can be slow because of that. It's slow because of the expensive
regex, equivalent to: https://regex101.com/r/fx4iPC/2.

You can simplify it to just match several equal signs at the beginning
of the line:

setlocal foldexpr=getline(v:lnum)=~'^=\\+'?\">\".(len(matchstr(getline(v:lnum),'^=\\+'))-1):\"=\"

It should be much faster.

What it does:

getline(v:lnum) - get text of the current line
=~ - check if string matches a regex
'^=\\+' - one or more = at the beginning of line; this is my
simplification, might give you false positives, but
if you have correct mediawiki file it should be ok
? - part of ternary operator, like in C, check :h expr1
\">\" - literal string ">", part fold level indication,
check :h fold-expr
. - string concatenation :h expr-.
len(...)-1 - counts how many = are at the beginning of the line
and subtracts 1, so top level headings are
not folded. With previous ">" it will evaluate
to e.g. ">1" and set fold level.
: - separation in ternary operator
\"=\" - literal "=" string; If there is no match it
will use fold level from previous line,
extending the fold to what's under the header.

Regards,
Matt

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200609120408.efyyoibepfe6lirq%40arch.

No comments: