]>
Commit | Line | Data |
---|---|---|
717fd8f6 AF |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.2.072 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.2.072 | |
11 | Problem: When using expression folding, foldexpr() mostly returns -1 for | |
12 | the previous line, which makes it difficult to write a fold | |
13 | expression. | |
14 | Solution: Make the level of the previous line available while still looking | |
15 | for the end of a fold. | |
16 | Files: src/fold.c | |
17 | ||
18 | ||
19 | *** ../vim-6.2.071/src/fold.c Fri Apr 18 14:49:33 2003 | |
20 | --- src/fold.c Wed Aug 13 21:28:57 2003 | |
21 | *************** | |
22 | *** 72,77 **** | |
23 | --- 72,87 ---- | |
24 | static linenr_T invalid_top = (linenr_T)0; | |
25 | static linenr_T invalid_bot = (linenr_T)0; | |
26 | ||
27 | + /* | |
28 | + * When using 'foldexpr' we sometimes get the level of the next line, which | |
29 | + * calls foldlevel() to get the level of the current line, which hasn't been | |
30 | + * stored yet. To get around this chicken-egg problem the level of the | |
31 | + * previous line is stored here when available. prev_lnum is zero when the | |
32 | + * level is not available. | |
33 | + */ | |
34 | + static linenr_T prev_lnum = 0; | |
35 | + static int prev_lnum_lvl = -1; | |
36 | + | |
37 | /* Flags used for "done" argument of setManualFold. */ | |
38 | #define DONE_NOTHING 0 | |
39 | #define DONE_ACTION 1 /* did close or open a fold */ | |
40 | *************** | |
41 | *** 247,252 **** | |
42 | --- 257,264 ---- | |
43 | * an undefined fold level. Otherwise update the folds first. */ | |
44 | if (invalid_top == (linenr_T)0) | |
45 | checkupdate(curwin); | |
46 | + else if (lnum == prev_lnum && prev_lnum_lvl >= 0) | |
47 | + return prev_lnum_lvl; | |
48 | else if (lnum >= invalid_top && lnum <= invalid_bot) | |
49 | return -1; | |
50 | ||
51 | *************** | |
52 | *** 2450,2455 **** | |
53 | --- 2462,2471 ---- | |
54 | ll = flp->lnum + 1; | |
55 | while (!got_int) | |
56 | { | |
57 | + /* Make the previous level available to foldlevel(). */ | |
58 | + prev_lnum = flp->lnum; | |
59 | + prev_lnum_lvl = flp->lvl; | |
60 | + | |
61 | if (++flp->lnum > linecount) | |
62 | break; | |
63 | flp->lvl = flp->lvl_next; | |
64 | *************** | |
65 | *** 2457,2462 **** | |
66 | --- 2473,2479 ---- | |
67 | if (flp->lvl >= 0 || flp->had_end <= MAX_LEVEL) | |
68 | break; | |
69 | } | |
70 | + prev_lnum = 0; | |
71 | if (flp->lnum > linecount) | |
72 | break; | |
73 | ||
74 | *** ../vim-6.2.071/src/version.c Tue Aug 12 20:01:59 2003 | |
75 | --- src/version.c Tue Sep 2 22:21:15 2003 | |
76 | *************** | |
77 | *** 632,633 **** | |
78 | --- 632,635 ---- | |
79 | { /* Add new patch number below this line */ | |
80 | + /**/ | |
81 | + 72, | |
82 | /**/ | |
83 | ||
84 | -- | |
85 | I'd like to meet the man who invented sex and see what he's working on now. | |
86 | ||
87 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
88 | /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ | |
89 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
90 | \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html /// |