Skip to content

Commit db022f3

Browse files
committed
patch 8.1.1960: fold code is spread out
Problem: Fold code is spread out. Solution: Move fold functions to fold.c.
1 parent a112f2d commit db022f3

4 files changed

Lines changed: 185 additions & 177 deletions

File tree

src/evalfunc.c

Lines changed: 0 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ static void f_fmod(typval_T *argvars, typval_T *rettv);
117117
#endif
118118
static void f_fnameescape(typval_T *argvars, typval_T *rettv);
119119
static void f_fnamemodify(typval_T *argvars, typval_T *rettv);
120-
static void f_foldclosed(typval_T *argvars, typval_T *rettv);
121-
static void f_foldclosedend(typval_T *argvars, typval_T *rettv);
122-
static void f_foldlevel(typval_T *argvars, typval_T *rettv);
123-
static void f_foldtext(typval_T *argvars, typval_T *rettv);
124-
static void f_foldtextresult(typval_T *argvars, typval_T *rettv);
125120
static void f_foreground(typval_T *argvars, typval_T *rettv);
126121
static void f_funcref(typval_T *argvars, typval_T *rettv);
127122
static void f_function(typval_T *argvars, typval_T *rettv);
@@ -3641,173 +3636,6 @@ f_fnamemodify(typval_T *argvars, typval_T *rettv)
36413636
vim_free(fbuf);
36423637
}
36433638

3644-
/*
3645-
* "foldclosed()" function
3646-
*/
3647-
static void
3648-
foldclosed_both(
3649-
typval_T *argvars UNUSED,
3650-
typval_T *rettv,
3651-
int end UNUSED)
3652-
{
3653-
#ifdef FEAT_FOLDING
3654-
linenr_T lnum;
3655-
linenr_T first, last;
3656-
3657-
lnum = tv_get_lnum(argvars);
3658-
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
3659-
{
3660-
if (hasFoldingWin(curwin, lnum, &first, &last, FALSE, NULL))
3661-
{
3662-
if (end)
3663-
rettv->vval.v_number = (varnumber_T)last;
3664-
else
3665-
rettv->vval.v_number = (varnumber_T)first;
3666-
return;
3667-
}
3668-
}
3669-
#endif
3670-
rettv->vval.v_number = -1;
3671-
}
3672-
3673-
/*
3674-
* "foldclosed()" function
3675-
*/
3676-
static void
3677-
f_foldclosed(typval_T *argvars, typval_T *rettv)
3678-
{
3679-
foldclosed_both(argvars, rettv, FALSE);
3680-
}
3681-
3682-
/*
3683-
* "foldclosedend()" function
3684-
*/
3685-
static void
3686-
f_foldclosedend(typval_T *argvars, typval_T *rettv)
3687-
{
3688-
foldclosed_both(argvars, rettv, TRUE);
3689-
}
3690-
3691-
/*
3692-
* "foldlevel()" function
3693-
*/
3694-
static void
3695-
f_foldlevel(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
3696-
{
3697-
#ifdef FEAT_FOLDING
3698-
linenr_T lnum;
3699-
3700-
lnum = tv_get_lnum(argvars);
3701-
if (lnum >= 1 && lnum <= curbuf->b_ml.ml_line_count)
3702-
rettv->vval.v_number = foldLevel(lnum);
3703-
#endif
3704-
}
3705-
3706-
/*
3707-
* "foldtext()" function
3708-
*/
3709-
static void
3710-
f_foldtext(typval_T *argvars UNUSED, typval_T *rettv)
3711-
{
3712-
#ifdef FEAT_FOLDING
3713-
linenr_T foldstart;
3714-
linenr_T foldend;
3715-
char_u *dashes;
3716-
linenr_T lnum;
3717-
char_u *s;
3718-
char_u *r;
3719-
int len;
3720-
char *txt;
3721-
long count;
3722-
#endif
3723-
3724-
rettv->v_type = VAR_STRING;
3725-
rettv->vval.v_string = NULL;
3726-
#ifdef FEAT_FOLDING
3727-
foldstart = (linenr_T)get_vim_var_nr(VV_FOLDSTART);
3728-
foldend = (linenr_T)get_vim_var_nr(VV_FOLDEND);
3729-
dashes = get_vim_var_str(VV_FOLDDASHES);
3730-
if (foldstart > 0 && foldend <= curbuf->b_ml.ml_line_count
3731-
&& dashes != NULL)
3732-
{
3733-
/* Find first non-empty line in the fold. */
3734-
for (lnum = foldstart; lnum < foldend; ++lnum)
3735-
if (!linewhite(lnum))
3736-
break;
3737-
3738-
/* Find interesting text in this line. */
3739-
s = skipwhite(ml_get(lnum));
3740-
/* skip C comment-start */
3741-
if (s[0] == '/' && (s[1] == '*' || s[1] == '/'))
3742-
{
3743-
s = skipwhite(s + 2);
3744-
if (*skipwhite(s) == NUL
3745-
&& lnum + 1 < (linenr_T)get_vim_var_nr(VV_FOLDEND))
3746-
{
3747-
s = skipwhite(ml_get(lnum + 1));
3748-
if (*s == '*')
3749-
s = skipwhite(s + 1);
3750-
}
3751-
}
3752-
count = (long)(foldend - foldstart + 1);
3753-
txt = NGETTEXT("+-%s%3ld line: ", "+-%s%3ld lines: ", count);
3754-
r = alloc(STRLEN(txt)
3755-
+ STRLEN(dashes) // for %s
3756-
+ 20 // for %3ld
3757-
+ STRLEN(s)); // concatenated
3758-
if (r != NULL)
3759-
{
3760-
sprintf((char *)r, txt, dashes, count);
3761-
len = (int)STRLEN(r);
3762-
STRCAT(r, s);
3763-
/* remove 'foldmarker' and 'commentstring' */
3764-
foldtext_cleanup(r + len);
3765-
rettv->vval.v_string = r;
3766-
}
3767-
}
3768-
#endif
3769-
}
3770-
3771-
/*
3772-
* "foldtextresult(lnum)" function
3773-
*/
3774-
static void
3775-
f_foldtextresult(typval_T *argvars UNUSED, typval_T *rettv)
3776-
{
3777-
#ifdef FEAT_FOLDING
3778-
linenr_T lnum;
3779-
char_u *text;
3780-
char_u buf[FOLD_TEXT_LEN];
3781-
foldinfo_T foldinfo;
3782-
int fold_count;
3783-
static int entered = FALSE;
3784-
#endif
3785-
3786-
rettv->v_type = VAR_STRING;
3787-
rettv->vval.v_string = NULL;
3788-
#ifdef FEAT_FOLDING
3789-
if (entered)
3790-
return; /* reject recursive use */
3791-
entered = TRUE;
3792-
3793-
lnum = tv_get_lnum(argvars);
3794-
/* treat illegal types and illegal string values for {lnum} the same */
3795-
if (lnum < 0)
3796-
lnum = 0;
3797-
fold_count = foldedCount(curwin, lnum, &foldinfo);
3798-
if (fold_count > 0)
3799-
{
3800-
text = get_foldtext(curwin, lnum, lnum + fold_count - 1,
3801-
&foldinfo, buf);
3802-
if (text == buf)
3803-
text = vim_strsave(text);
3804-
rettv->vval.v_string = text;
3805-
}
3806-
3807-
entered = FALSE;
3808-
#endif
3809-
}
3810-
38113639
/*
38123640
* "foreground()" function
38133641
*/

0 commit comments

Comments
 (0)