comparison runtime/doc/fold.txt @ 30594:586b5b3aacf9 v9.0.0632

patch 9.0.0632: calling a function from an "expr" option has overhead Commit: https://github.com/vim/vim/commit/87b4e5c5db9d1cfd6f2e79656e1a6cff3c69d15f Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 1 15:32:46 2022 +0100 patch 9.0.0632: calling a function from an "expr" option has overhead Problem: Calling a function from an "expr" option has too much overhead. Solution: Add call_simple_func() and use it for 'foldexpr'
author Bram Moolenaar <Bram@vim.org>
date Sat, 01 Oct 2022 16:45:04 +0200
parents f8116058ca76
children f68f43043842
comparison
equal deleted inserted replaced
30593:56ab58fcefa6 30594:586b5b3aacf9
72 The folds are automatically defined by their foldlevel, like with the "indent" 72 The folds are automatically defined by their foldlevel, like with the "indent"
73 method. The value of the 'foldexpr' option is evaluated to get the foldlevel 73 method. The value of the 'foldexpr' option is evaluated to get the foldlevel
74 of a line. Examples: 74 of a line. Examples:
75 This will create a fold for all consecutive lines that start with a tab: > 75 This will create a fold for all consecutive lines that start with a tab: >
76 :set foldexpr=getline(v:lnum)[0]==\"\\t\" 76 :set foldexpr=getline(v:lnum)[0]==\"\\t\"
77 This will call a function to compute the fold level: >
78 :set foldexpr=MyFoldLevel(v:lnum)
79 This will make a fold out of paragraphs separated by blank lines: > 77 This will make a fold out of paragraphs separated by blank lines: >
80 :set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1 78 :set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
81 This does the same: > 79 This does the same: >
82 :set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1 80 :set foldexpr=getline(v:lnum-1)=~'^\\s*$'&&getline(v:lnum)=~'\\S'?'>1':1
83 81
84 Note that backslashes must be used to escape characters that ":set" handles 82 Note that backslashes must be used to escape characters that ":set" handles
85 differently (space, backslash, double quote, etc., see |option-backslash|). 83 differently (space, backslash, double quote, etc., see |option-backslash|).
84
85 The most efficient is to call a compiled function without arguments: >
86 :set foldexpr=MyFoldLevel()
87 The function must use v:lnum. See |expr-option-function|.
86 88
87 These are the conditions with which the expression is evaluated: 89 These are the conditions with which the expression is evaluated:
88 - The current buffer and window are set for the line. 90 - The current buffer and window are set for the line.
89 - The variable "v:lnum" is set to the line number. 91 - The variable "v:lnum" is set to the line number.
90 - The result is used for the fold level in this way: 92 - The result is used for the fold level in this way: