fold: fold_T.fd_small is TriState

This commit is contained in:
Jan Edmund Lazo 2018-07-16 02:36:28 -04:00
parent 9e20398908
commit f193b5241f

View File

@ -44,14 +44,14 @@
* The info stored in both growarrays is the same: An array of fold_T.
*/
typedef struct {
linenr_T fd_top; /* first line of fold; for nested fold
* relative to parent */
linenr_T fd_len; /* number of lines in the fold */
garray_T fd_nested; /* array of nested folds */
char fd_flags; /* see below */
char fd_small; /* TRUE, FALSE or MAYBE: fold smaller than
'foldminlines'; MAYBE applies to nested
folds too */
linenr_T fd_top; // first line of fold; for nested fold
// relative to parent
linenr_T fd_len; // number of lines in the fold
garray_T fd_nested; // array of nested folds
char fd_flags; // see below
TriState fd_small; // kTrue, kFalse, or kNone: fold smaller than
// 'foldminlines'; kNone applies to nested
// folds too
} fold_T;
#define FD_OPEN 0 /* fold is open (nested ones can be closed) */
@ -649,7 +649,7 @@ void foldCreate(linenr_T start, linenr_T end)
if (!use_level)
curwin->w_fold_manual = true;
fp->fd_flags = FD_CLOSED;
fp->fd_small = MAYBE;
fp->fd_small = kNone;
/* redraw */
changed_window_setting();
@ -787,8 +787,8 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
(void)foldFind(&wp->w_folds, top, &fp);
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot) {
fp->fd_small = MAYBE;
++fp;
fp->fd_small = kNone;
fp++;
}
if (foldmethodIsIndent(wp)
@ -1340,8 +1340,9 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
nfp[i].fd_top += fp->fd_top;
if (fp->fd_flags == FD_LEVEL)
nfp[i].fd_flags = FD_LEVEL;
if (fp->fd_small == MAYBE)
nfp[i].fd_small = MAYBE;
if (fp->fd_small == kNone) {
nfp[i].fd_small = kNone;
}
}
/* move the existing folds down to make room */
@ -1526,15 +1527,18 @@ check_closed(
} else if (fp->fd_flags == FD_CLOSED)
closed = TRUE;
/* Small fold isn't closed anyway. */
if (fp->fd_small == MAYBE)
// Small fold isn't closed anyway.
if (fp->fd_small == kNone) {
*maybe_smallp = TRUE;
}
if (closed) {
if (*maybe_smallp)
fp->fd_small = MAYBE;
if (*maybe_smallp) {
fp->fd_small = kNone;
}
checkSmall(win, fp, lnum_off);
if (fp->fd_small == TRUE)
if (fp->fd_small == kTrue) {
closed = FALSE;
}
}
return closed;
}
@ -1553,35 +1557,33 @@ checkSmall(
int count;
int n;
if (fp->fd_small == MAYBE) {
/* Mark any nested folds to maybe-small */
if (fp->fd_small == kNone) {
// Mark any nested folds to maybe-small
setSmallMaybe(&fp->fd_nested);
if (fp->fd_len > curwin->w_p_fml)
fp->fd_small = FALSE;
else {
if (fp->fd_len > curwin->w_p_fml) {
fp->fd_small = kFalse;
} else {
count = 0;
for (n = 0; n < fp->fd_len; ++n) {
for (n = 0; n < fp->fd_len; n++) {
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
if (count > curwin->w_p_fml) {
fp->fd_small = FALSE;
fp->fd_small = kFalse;
return;
}
}
fp->fd_small = TRUE;
fp->fd_small = kTrue;
}
}
}
/* setSmallMaybe() {{{2 */
/*
* Set small flags in "gap" to MAYBE.
*/
// setSmallMaybe() {{{2
// Set small flags in "gap" to kNone.
static void setSmallMaybe(garray_T *gap)
{
fold_T *fp = (fold_T *)gap->ga_data;
for (int i = 0; i < gap->ga_len; ++i) {
fp[i].fd_small = MAYBE;
for (int i = 0; i < gap->ga_len; i++) {
fp[i].fd_small = kNone;
}
}
@ -2361,13 +2363,14 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
flp->wp->w_fold_manual = true;
} else
fp->fd_flags = (fp - 1)->fd_flags;
fp->fd_small = MAYBE;
/* If using the "marker", "expr" or "syntax" method, we
* need to continue until the end of the fold is found. */
fp->fd_small = kNone;
// If using the "marker", "expr" or "syntax" method, we
// need to continue until the end of the fold is found.
if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax)
|| getlevel == foldlevelSyntax) {
finish = TRUE;
}
fold_changed = TRUE;
break;
}
@ -2454,7 +2457,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
/* Current fold at least extends until lnum. */
if (fp->fd_len < flp->lnum - fp->fd_top) {
fp->fd_len = flp->lnum - fp->fd_top;
fp->fd_small = MAYBE;
fp->fd_small = kNone;
fold_changed = TRUE;
}
@ -2566,8 +2569,8 @@ static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot)
assert(fp[1].fd_top > bot);
fp[1].fd_len = fp->fd_len - (fp[1].fd_top - fp->fd_top);
fp[1].fd_flags = fp->fd_flags;
fp[1].fd_small = MAYBE;
fp->fd_small = MAYBE;
fp[1].fd_small = kNone;
fp->fd_small = kNone;
/* Move nested folds below bot to new fold. There can't be
* any between top and bot, they have been removed by the caller. */