Merge #8749 from janlazo/clint-tristate

This commit is contained in:
Justin M. Keyes 2018-08-04 19:37:58 +02:00 committed by GitHub
commit e861da247e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 546 additions and 565 deletions

View File

@ -3299,6 +3299,13 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
error(filename, linenum, 'readability/bool', 4, error(filename, linenum, 'readability/bool', 4,
'Use %s instead of %s.' % (token.lower(), token)) 'Use %s instead of %s.' % (token.lower(), token))
# Detect MAYBE
match = Search(r'\b(MAYBE)\b', line)
if match:
token = match.group(1)
error(filename, linenum, 'readability/bool', 4,
'Use kNONE from TriState instead of %s.' % token)
# Detect preincrement/predecrement # Detect preincrement/predecrement
match = Match(r'^\s*(?:\+\+|--)', line) match = Match(r'^\s*(?:\+\+|--)', line)
if match: if match:

View File

@ -48,9 +48,9 @@ static int diff_flags = DIFF_FILLER;
#define LBUFLEN 50 // length of line in diff file #define LBUFLEN 50 // length of line in diff file
// TRUE when "diff -a" works, FALSE when it doesn't work, MAYBE when not // kTrue when "diff -a" works, kFalse when it doesn't work,
// checked yet // kNone when not checked yet
static int diff_a_works = MAYBE; static TriState diff_a_works = kNone;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@ -686,9 +686,9 @@ void ex_diffupdate(exarg_T *eap)
// there are differences. // there are differences.
// May try twice, first with "-a" and then without. // May try twice, first with "-a" and then without.
int io_error = false; int io_error = false;
bool ok = false; TriState ok = kFalse;
for (;;) { for (;;) {
ok = false; ok = kFalse;
FILE *fd = mch_fopen(tmp_orig, "w"); FILE *fd = mch_fopen(tmp_orig, "w");
if (fd == NULL) { if (fd == NULL) {
@ -722,7 +722,7 @@ void ex_diffupdate(exarg_T *eap)
} }
if (STRNCMP(linebuf, "1c1", 3) == 0) { if (STRNCMP(linebuf, "1c1", 3) == 0) {
ok = TRUE; ok = kTrue;
} }
} }
fclose(fd); fclose(fd);
@ -739,7 +739,7 @@ void ex_diffupdate(exarg_T *eap)
} }
// If we checked if "-a" works already, break here. // If we checked if "-a" works already, break here.
if (diff_a_works != MAYBE) { if (diff_a_works != kNone) {
break; break;
} }
diff_a_works = ok; diff_a_works = ok;
@ -755,7 +755,7 @@ void ex_diffupdate(exarg_T *eap)
EMSG(_("E810: Cannot read or write temp files")); EMSG(_("E810: Cannot read or write temp files"));
} }
EMSG(_("E97: Cannot create diffs")); EMSG(_("E97: Cannot create diffs"));
diff_a_works = MAYBE; diff_a_works = kNone;
goto theend; goto theend;
} }
@ -830,7 +830,7 @@ static void diff_file(const char *const tmp_orig, const char *const tmp_new,
* differences are of no use. Ignore errors, diff returns * differences are of no use. Ignore errors, diff returns
* non-zero when differences have been found. */ * non-zero when differences have been found. */
vim_snprintf(cmd, len, "diff %s%s%s%s%s %s", vim_snprintf(cmd, len, "diff %s%s%s%s%s %s",
diff_a_works ? "-a " : "", diff_a_works == kFalse ? "" : "-a ",
"", "",
(diff_flags & DIFF_IWHITE) ? "-b " : "", (diff_flags & DIFF_IWHITE) ? "-b " : "",
(diff_flags & DIFF_ICASE) ? "-i " : "", (diff_flags & DIFF_ICASE) ? "-i " : "",
@ -1486,7 +1486,7 @@ int diff_check(win_T *wp, linenr_T lnum)
} }
// A closed fold never has filler lines. // A closed fold never has filler lines.
if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) { if (hasFoldingWin(wp, lnum, NULL, NULL, true, NULL)) {
return 0; return 0;
} }
@ -1793,7 +1793,7 @@ void diff_set_topline(win_T *fromwin, win_T *towin)
check_topfill(towin, false); check_topfill(towin, false);
(void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline, (void)hasFoldingWin(towin, towin->w_topline, &towin->w_topline,
NULL, TRUE, NULL); NULL, true, NULL);
} }
/// This is called when 'diffopt' is changed. /// This is called when 'diffopt' is changed.

View File

@ -242,7 +242,7 @@ static int ins_need_undo; /* call u_save() before inserting a
static int did_add_space = FALSE; /* auto_format() added an extra space static int did_add_space = FALSE; /* auto_format() added an extra space
under the cursor */ under the cursor */
static int dont_sync_undo = false; // CTRL-G U prevents syncing undo static TriState dont_sync_undo = kFalse; // CTRL-G U prevents syncing undo
// for the next left/right cursor // for the next left/right cursor
static linenr_T o_lnum = 0; static linenr_T o_lnum = 0;
@ -595,10 +595,10 @@ static int insert_check(VimState *state)
s->lastc = s->c; // remember previous char for CTRL-D s->lastc = s->c; // remember previous char for CTRL-D
// After using CTRL-G U the next cursor key will not break undo. // After using CTRL-G U the next cursor key will not break undo.
if (dont_sync_undo == MAYBE) { if (dont_sync_undo == kNone) {
dont_sync_undo = true; dont_sync_undo = kTrue;
} else { } else {
dont_sync_undo = false; dont_sync_undo = kFalse;
} }
return 1; return 1;
@ -997,7 +997,7 @@ static int insert_handle_key(InsertState *s)
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) { if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_left(); ins_s_left();
} else { } else {
ins_left(dont_sync_undo == false); ins_left(dont_sync_undo == kFalse);
} }
break; break;
@ -1010,7 +1010,7 @@ static int insert_handle_key(InsertState *s)
if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) { if (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)) {
ins_s_right(); ins_s_right();
} else { } else {
ins_right(dont_sync_undo == false); ins_right(dont_sync_undo == kFalse);
} }
break; break;
@ -7174,7 +7174,7 @@ static void ins_ctrl_g(void)
case 'U': case 'U':
// Allow one left/right cursor movement with the next char, // Allow one left/right cursor movement with the next char,
// without breaking undo. // without breaking undo.
dont_sync_undo = MAYBE; dont_sync_undo = kNone;
break; break;
/* Unknown CTRL-G command, reserved for future expansion. */ /* Unknown CTRL-G command, reserved for future expansion. */
@ -7954,7 +7954,7 @@ static void ins_left(bool end_change)
} else { } else {
vim_beep(BO_CRSR); vim_beep(BO_CRSR);
} }
dont_sync_undo = false; dont_sync_undo = kFalse;
} }
static void ins_home(int c) static void ins_home(int c)
@ -8039,7 +8039,7 @@ static void ins_right(bool end_change)
} else { } else {
vim_beep(BO_CRSR); vim_beep(BO_CRSR);
} }
dont_sync_undo = false; dont_sync_undo = kFalse;
} }
static void ins_s_right(void) static void ins_s_right(void)

View File

@ -4913,11 +4913,7 @@ void fix_help_buffer(void)
{ {
linenr_T lnum; linenr_T lnum;
char_u *line; char_u *line;
int in_example = FALSE; bool in_example = false;
int len;
char_u *fname;
char_u *p;
char_u *rt;
// Set filetype to "help". // Set filetype to "help".
if (STRCMP(curbuf->b_p_ft, "help") != 0) { if (STRCMP(curbuf->b_p_ft, "help") != 0) {
@ -4927,9 +4923,9 @@ void fix_help_buffer(void)
} }
if (!syntax_present(curwin)) { if (!syntax_present(curwin)) {
for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) { for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
line = ml_get_buf(curbuf, lnum, FALSE); line = ml_get_buf(curbuf, lnum, false);
len = (int)STRLEN(line); const size_t len = STRLEN(line);
if (in_example && len > 0 && !ascii_iswhite(line[0])) { if (in_example && len > 0 && !ascii_iswhite(line[0])) {
/* End of example: non-white or '<' in first column. */ /* End of example: non-white or '<' in first column. */
if (line[0] == '<') { if (line[0] == '<') {
@ -4937,14 +4933,14 @@ void fix_help_buffer(void)
line = ml_get_buf(curbuf, lnum, TRUE); line = ml_get_buf(curbuf, lnum, TRUE);
line[0] = ' '; line[0] = ' ';
} }
in_example = FALSE; in_example = false;
} }
if (!in_example && len > 0) { if (!in_example && len > 0) {
if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) { if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) {
/* blank-out a '>' in the last column (start of example) */ /* blank-out a '>' in the last column (start of example) */
line = ml_get_buf(curbuf, lnum, TRUE); line = ml_get_buf(curbuf, lnum, TRUE);
line[len - 1] = ' '; line[len - 1] = ' ';
in_example = TRUE; in_example = true;
} else if (line[len - 1] == '~') { } else if (line[len - 1] == '~') {
/* blank-out a '~' at the end of line (header marker) */ /* blank-out a '~' at the end of line (header marker) */
line = ml_get_buf(curbuf, lnum, TRUE); line = ml_get_buf(curbuf, lnum, TRUE);
@ -4958,7 +4954,7 @@ void fix_help_buffer(void)
* In the "help.txt" and "help.abx" file, add the locally added help * In the "help.txt" and "help.abx" file, add the locally added help
* files. This uses the very first line in the help file. * files. This uses the very first line in the help file.
*/ */
fname = path_tail(curbuf->b_fname); char_u *const fname = path_tail(curbuf->b_fname);
if (fnamecmp(fname, "help.txt") == 0 if (fnamecmp(fname, "help.txt") == 0
|| (fnamencmp(fname, "help.", 5) == 0 || (fnamencmp(fname, "help.", 5) == 0
&& ASCII_ISALPHA(fname[5]) && ASCII_ISALPHA(fname[5])
@ -4973,17 +4969,15 @@ void fix_help_buffer(void)
/* Go through all directories in 'runtimepath', skipping /* Go through all directories in 'runtimepath', skipping
* $VIMRUNTIME. */ * $VIMRUNTIME. */
p = p_rtp; char_u *p = p_rtp;
while (*p != NUL) { while (*p != NUL) {
copy_option_part(&p, NameBuff, MAXPATHL, ","); copy_option_part(&p, NameBuff, MAXPATHL, ",");
rt = (char_u *)vim_getenv("VIMRUNTIME"); char_u *const rt = (char_u *)vim_getenv("VIMRUNTIME");
if (rt != NULL if (rt != NULL
&& path_full_compare(rt, NameBuff, false) != kEqualFiles) { && path_full_compare(rt, NameBuff, false) != kEqualFiles) {
int fcount; int fcount;
char_u **fnames; char_u **fnames;
FILE *fd;
char_u *s; char_u *s;
int fi;
vimconv_T vc; vimconv_T vc;
char_u *cp; char_u *cp;
@ -5001,29 +4995,24 @@ void fix_help_buffer(void)
if (gen_expand_wildcards(1, buff_list, &fcount, if (gen_expand_wildcards(1, buff_list, &fcount,
&fnames, EW_FILE|EW_SILENT) == OK &fnames, EW_FILE|EW_SILENT) == OK
&& fcount > 0) { && fcount > 0) {
int i1; // If foo.abx is found use it instead of foo.txt in
int i2; // the same directory.
char_u *f1; for (int i1 = 0; i1 < fcount; i1++) {
char_u *f2; for (int i2 = 0; i2 < fcount; i2++) {
char_u *t1; if (i1 == i2) {
char_u *e1;
char_u *e2;
/* If foo.abx is found use it instead of foo.txt in
* the same directory. */
for (i1 = 0; i1 < fcount; ++i1) {
for (i2 = 0; i2 < fcount; ++i2) {
if (i1 == i2)
continue; continue;
if (fnames[i1] == NULL || fnames[i2] == NULL) }
if (fnames[i1] == NULL || fnames[i2] == NULL) {
continue; continue;
f1 = fnames[i1]; }
f2 = fnames[i2]; const char_u *const f1 = fnames[i1];
t1 = path_tail(f1); const char_u *const f2 = fnames[i2];
if (fnamencmp(f1, f2, t1 - f1) != 0) const char_u *const t1 = path_tail(f1);
if (fnamencmp(f1, f2, t1 - f1) != 0) {
continue; continue;
e1 = vim_strrchr(t1, '.'); }
e2 = vim_strrchr(path_tail(f2), '.'); const char_u *const e1 = vim_strrchr(t1, '.');
const char_u *const e2 = vim_strrchr(path_tail(f2), '.');
if (e1 == NULL || e2 == NULL) { if (e1 == NULL || e2 == NULL) {
continue; continue;
} }
@ -5044,10 +5033,12 @@ void fix_help_buffer(void)
} }
} }
} }
for (fi = 0; fi < fcount; ++fi) { for (int fi = 0; fi < fcount; fi++) {
if (fnames[fi] == NULL) if (fnames[fi] == NULL) {
continue; continue;
fd = mch_fopen((char *)fnames[fi], "r"); }
FILE *const fd = mch_fopen((char *)fnames[fi], "r");
if (fd == NULL) { if (fd == NULL) {
continue; continue;
} }
@ -5055,9 +5046,9 @@ void fix_help_buffer(void)
if (IObuff[0] == '*' if (IObuff[0] == '*'
&& (s = vim_strchr(IObuff + 1, '*')) && (s = vim_strchr(IObuff + 1, '*'))
!= NULL) { != NULL) {
int this_utf = MAYBE; TriState this_utf = kNone;
/* Change tag definition to a // Change tag definition to a
* reference and remove <CR>/<NL>. */ // reference and remove <CR>/<NL>.
IObuff[0] = '|'; IObuff[0] = '|';
*s = '|'; *s = '|';
while (*s != NUL) { while (*s != NUL) {
@ -5067,13 +5058,12 @@ void fix_help_buffer(void)
* above 127 is found and no * above 127 is found and no
* illegal byte sequence is found. * illegal byte sequence is found.
*/ */
if (*s >= 0x80 && this_utf != FALSE) { if (*s >= 0x80 && this_utf != kFalse) {
int l; this_utf = kTrue;
const int l = utf_ptr2len(s);
this_utf = TRUE; if (l == 1) {
l = utf_ptr2len(s); this_utf = kFalse;
if (l == 1) }
this_utf = FALSE;
s += l - 1; s += l - 1;
} }
++s; ++s;
@ -5082,19 +5072,21 @@ void fix_help_buffer(void)
* conversion to the current * conversion to the current
* 'encoding' may be required. */ * 'encoding' may be required. */
vc.vc_type = CONV_NONE; vc.vc_type = CONV_NONE;
convert_setup(&vc, (char_u *)( convert_setup(
this_utf == TRUE ? "utf-8" &vc,
: "latin1"), p_enc); (char_u *)(this_utf == kTrue ? "utf-8" : "latin1"),
if (vc.vc_type == CONV_NONE) p_enc);
/* No conversion needed. */ if (vc.vc_type == CONV_NONE) {
// No conversion needed.
cp = IObuff; cp = IObuff;
else { } else {
/* Do the conversion. If it fails // Do the conversion. If it fails
* use the unconverted text. */ // use the unconverted text.
cp = string_convert(&vc, IObuff, NULL); cp = string_convert(&vc, IObuff, NULL);
if (cp == NULL) if (cp == NULL) {
cp = IObuff; cp = IObuff;
} }
}
convert_setup(&vc, NULL, NULL); convert_setup(&vc, NULL, NULL);
ml_append(lnum, cp, (colnr_T)0, FALSE); ml_append(lnum, cp, (colnr_T)0, FALSE);
@ -5138,22 +5130,16 @@ void ex_viusage(exarg_T *eap)
/// @param tagname Name of the tags file ("tags" for English, "tags-fr" for /// @param tagname Name of the tags file ("tags" for English, "tags-fr" for
/// French) /// French)
/// @param add_help_tags Whether to add the "help-tags" tag /// @param add_help_tags Whether to add the "help-tags" tag
static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname, static void helptags_one(char_u *const dir, const char_u *const ext,
bool add_help_tags) const char_u *const tagfname, const bool add_help_tags)
{ {
FILE *fd_tags;
FILE *fd;
garray_T ga; garray_T ga;
int filecount; int filecount;
char_u **files; char_u **files;
char_u *p1, *p2; char_u *p1, *p2;
int fi;
char_u *s; char_u *s;
char_u *fname; TriState utf8 = kNone;
int utf8 = MAYBE; bool mix = false; // detected mixed encodings
int this_utf8;
int firstline;
int mix = FALSE; /* detected mixed encodings */
// Find all *.txt files. // Find all *.txt files.
size_t dirlen = STRLCPY(NameBuff, dir, sizeof(NameBuff)); size_t dirlen = STRLCPY(NameBuff, dir, sizeof(NameBuff));
@ -5186,7 +5172,8 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname,
EMSG(_(e_fnametoolong)); EMSG(_(e_fnametoolong));
return; return;
} }
fd_tags = mch_fopen((char *)NameBuff, "w");
FILE *const fd_tags = mch_fopen((char *)NameBuff, "w");
if (fd_tags == NULL) { if (fd_tags == NULL) {
EMSG2(_("E152: Cannot open %s for writing"), NameBuff); EMSG2(_("E152: Cannot open %s for writing"), NameBuff);
FreeWild(filecount, files); FreeWild(filecount, files);
@ -5209,44 +5196,44 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname,
/* /*
* Go over all the files and extract the tags. * Go over all the files and extract the tags.
*/ */
for (fi = 0; fi < filecount && !got_int; ++fi) { for (int fi = 0; fi < filecount && !got_int; fi++) {
fd = mch_fopen((char *)files[fi], "r"); FILE *const fd = mch_fopen((char *)files[fi], "r");
if (fd == NULL) { if (fd == NULL) {
EMSG2(_("E153: Unable to open %s for reading"), files[fi]); EMSG2(_("E153: Unable to open %s for reading"), files[fi]);
continue; continue;
} }
fname = files[fi] + dirlen + 1; const char_u *const fname = files[fi] + dirlen + 1;
firstline = TRUE; bool firstline = true;
while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) { while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) {
if (firstline) { if (firstline) {
/* Detect utf-8 file by a non-ASCII char in the first line. */ // Detect utf-8 file by a non-ASCII char in the first line.
this_utf8 = MAYBE; TriState this_utf8 = kNone;
for (s = IObuff; *s != NUL; ++s) for (s = IObuff; *s != NUL; s++) {
if (*s >= 0x80) { if (*s >= 0x80) {
int l; this_utf8 = kTrue;
const int l = utf_ptr2len(s);
this_utf8 = TRUE;
l = utf_ptr2len(s);
if (l == 1) { if (l == 1) {
/* Illegal UTF-8 byte sequence. */ // Illegal UTF-8 byte sequence.
this_utf8 = FALSE; this_utf8 = kFalse;
break; break;
} }
s += l - 1; s += l - 1;
} }
if (this_utf8 == MAYBE) /* only ASCII characters found */ }
this_utf8 = FALSE; if (this_utf8 == kNone) { // only ASCII characters found
if (utf8 == MAYBE) /* first file */ this_utf8 = kFalse;
}
if (utf8 == kNone) { // first file
utf8 = this_utf8; utf8 = this_utf8;
else if (utf8 != this_utf8) { } else if (utf8 != this_utf8) {
EMSG2(_( EMSG2(_(
"E670: Mix of help file encodings within a language: %s"), "E670: Mix of help file encodings within a language: %s"),
files[fi]); files[fi]);
mix = !got_int; mix = !got_int;
got_int = TRUE; got_int = TRUE;
} }
firstline = FALSE; firstline = false;
} }
p1 = vim_strchr(IObuff, '*'); /* find first '*' */ p1 = vim_strchr(IObuff, '*'); /* find first '*' */
while (p1 != NULL) { while (p1 != NULL) {
@ -5316,8 +5303,9 @@ static void helptags_one(char_u *dir, char_u *ext, char_u *tagfname,
} }
} }
if (utf8 == TRUE) if (utf8 == kTrue) {
fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n");
}
/* /*
* Write the tags into the file. * Write the tags into the file.

View File

@ -7395,7 +7395,7 @@ static void ex_operators(exarg_T *eap)
oa.end.lnum = eap->line2; oa.end.lnum = eap->line2;
oa.line_count = eap->line2 - eap->line1 + 1; oa.line_count = eap->line2 - eap->line1 + 1;
oa.motion_type = kMTLineWise; oa.motion_type = kMTLineWise;
virtual_op = false; virtual_op = kFalse;
if (eap->cmdidx != CMD_yank) { // position cursor for undo if (eap->cmdidx != CMD_yank) { // position cursor for undo
setpcmark(); setpcmark();
curwin->w_cursor.lnum = eap->line1; curwin->w_cursor.lnum = eap->line1;
@ -7426,7 +7426,7 @@ static void ex_operators(exarg_T *eap)
op_shift(&oa, FALSE, eap->amount); op_shift(&oa, FALSE, eap->amount);
break; break;
} }
virtual_op = MAYBE; virtual_op = kNone;
ex_may_print(eap); ex_may_print(eap);
} }

View File

@ -44,14 +44,14 @@
* The info stored in both growarrays is the same: An array of fold_T. * The info stored in both growarrays is the same: An array of fold_T.
*/ */
typedef struct { typedef struct {
linenr_T fd_top; /* first line of fold; for nested fold linenr_T fd_top; // first line of fold; for nested fold
* relative to parent */ // relative to parent
linenr_T fd_len; /* number of lines in the fold */ linenr_T fd_len; // number of lines in the fold
garray_T fd_nested; /* array of nested folds */ garray_T fd_nested; // array of nested folds
char fd_flags; /* see below */ char fd_flags; // see below
char fd_small; /* TRUE, FALSE or MAYBE: fold smaller than TriState fd_small; // kTrue, kFalse, or kNone: fold smaller than
'foldminlines'; MAYBE applies to nested // 'foldminlines'; kNone applies to nested
folds too */ // folds too
} fold_T; } fold_T;
#define FD_OPEN 0 /* fold is open (nested ones can be closed) */ #define FD_OPEN 0 /* fold is open (nested ones can be closed) */
@ -76,8 +76,8 @@ typedef struct {
this line (copy of "end" of prev. line) */ this line (copy of "end" of prev. line) */
} fline_T; } fline_T;
/* Flag is set when redrawing is needed. */ // Flag is set when redrawing is needed.
static int fold_changed; static bool fold_changed;
/* Function used by foldUpdateIEMSRecurse */ /* Function used by foldUpdateIEMSRecurse */
typedef void (*LevelGetter)(fline_T *); typedef void (*LevelGetter)(fline_T *);
@ -147,29 +147,27 @@ int hasAnyFolding(win_T *win)
*/ */
bool hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp) bool hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp)
{ {
return hasFoldingWin(curwin, lnum, firstp, lastp, TRUE, NULL); return hasFoldingWin(curwin, lnum, firstp, lastp, true, NULL);
} }
/* hasFoldingWin() {{{2 */ /* hasFoldingWin() {{{2 */
bool hasFoldingWin( bool hasFoldingWin(
win_T *win, win_T *const win,
linenr_T lnum, const linenr_T lnum,
linenr_T *firstp, linenr_T *const firstp,
linenr_T *lastp, linenr_T *const lastp,
int cache, /* when TRUE: use cached values of window */ const bool cache, // when true: use cached values of window
foldinfo_T *infop /* where to store fold info */ foldinfo_T *const infop // where to store fold info
) )
{ {
int had_folded = FALSE; bool had_folded = false;
linenr_T first = 0; linenr_T first = 0;
linenr_T last = 0; linenr_T last = 0;
linenr_T lnum_rel = lnum; linenr_T lnum_rel = lnum;
int x;
fold_T *fp; fold_T *fp;
int level = 0; int level = 0;
int use_level = FALSE; bool use_level = false;
int maybe_small = FALSE; bool maybe_small = false;
garray_T *gap;
int low_level = 0; int low_level = 0;
checkupdate(win); checkupdate(win);
@ -187,7 +185,7 @@ bool hasFoldingWin(
* First look in cached info for displayed lines. This is probably * First look in cached info for displayed lines. This is probably
* the fastest, but it can only be used if the entry is still valid. * the fastest, but it can only be used if the entry is still valid.
*/ */
x = find_wl_entry(win, lnum); const int x = find_wl_entry(win, lnum);
if (x >= 0) { if (x >= 0) {
first = win->w_lines[x].wl_lnum; first = win->w_lines[x].wl_lnum;
last = win->w_lines[x].wl_lastlnum; last = win->w_lines[x].wl_lastlnum;
@ -199,7 +197,7 @@ bool hasFoldingWin(
/* /*
* Recursively search for a fold that contains "lnum". * Recursively search for a fold that contains "lnum".
*/ */
gap = &win->w_folds; garray_T *gap = &win->w_folds;
for (;; ) { for (;; ) {
if (!foldFind(gap, lnum_rel, &fp)) if (!foldFind(gap, lnum_rel, &fp))
break; break;
@ -274,14 +272,11 @@ int foldLevel(linenr_T lnum)
return foldLevelWin(curwin, lnum); return foldLevelWin(curwin, lnum);
} }
/* lineFolded() {{{2 */ // lineFolded() {{{2
/* // Low level function to check if a line is folded. Doesn't use any caching.
* Low level function to check if a line is folded. Doesn't use any caching. // Return true if line is folded.
* Return TRUE if line is folded. // Return false if line is not folded.
* Return FALSE if line is not folded. bool lineFolded(win_T *const win, const linenr_T lnum)
* Return MAYBE if the line is folded when next to a folded line.
*/
int lineFolded(win_T *win, linenr_T lnum)
{ {
return foldedCount(win, lnum, NULL) != 0; return foldedCount(win, lnum, NULL) != 0;
} }
@ -299,8 +294,9 @@ long foldedCount(win_T *win, linenr_T lnum, foldinfo_T *infop)
{ {
linenr_T last; linenr_T last;
if (hasFoldingWin(win, lnum, NULL, &last, FALSE, infop)) if (hasFoldingWin(win, lnum, NULL, &last, false, infop)) {
return (long)(last - lnum + 1); return (long)(last - lnum + 1);
}
return 0; return 0;
} }
@ -649,7 +645,7 @@ void foldCreate(linenr_T start, linenr_T end)
if (!use_level) if (!use_level)
curwin->w_fold_manual = true; curwin->w_fold_manual = true;
fp->fd_flags = FD_CLOSED; fp->fd_flags = FD_CLOSED;
fp->fd_small = MAYBE; fp->fd_small = kNone;
/* redraw */ /* redraw */
changed_window_setting(); changed_window_setting();
@ -663,36 +659,31 @@ void foldCreate(linenr_T start, linenr_T end)
* When "end" is not 0, delete all folds from "start" to "end". * When "end" is not 0, delete all folds from "start" to "end".
* When "recursive" is TRUE delete recursively. * When "recursive" is TRUE delete recursively.
*/ */
void void deleteFold(
deleteFold( const linenr_T start,
linenr_T start, const linenr_T end,
linenr_T end, const int recursive,
int recursive, const bool had_visual // true when Visual selection used
int had_visual // TRUE when Visual selection used
) )
{ {
garray_T *gap;
fold_T *fp; fold_T *fp;
garray_T *found_ga;
fold_T *found_fp = NULL; fold_T *found_fp = NULL;
linenr_T found_off = 0; linenr_T found_off = 0;
int use_level; bool maybe_small = false;
int maybe_small = FALSE;
int level = 0; int level = 0;
linenr_T lnum = start; linenr_T lnum = start;
linenr_T lnum_off; bool did_one = false;
int did_one = FALSE;
linenr_T first_lnum = MAXLNUM; linenr_T first_lnum = MAXLNUM;
linenr_T last_lnum = 0; linenr_T last_lnum = 0;
checkupdate(curwin); checkupdate(curwin);
while (lnum <= end) { while (lnum <= end) {
/* Find the deepest fold for "start". */ // Find the deepest fold for "start".
gap = &curwin->w_folds; garray_T *gap = &curwin->w_folds;
found_ga = NULL; garray_T *found_ga = NULL;
lnum_off = 0; linenr_T lnum_off = 0;
use_level = FALSE; bool use_level = false;
for (;; ) { for (;; ) {
if (!foldFind(gap, lnum - lnum_off, &fp)) if (!foldFind(gap, lnum - lnum_off, &fp))
break; break;
@ -728,7 +719,7 @@ deleteFold(
parseMarker(curwin); parseMarker(curwin);
deleteFoldMarkers(found_fp, recursive, found_off); deleteFoldMarkers(found_fp, recursive, found_off);
} }
did_one = TRUE; did_one = true;
/* redraw window */ /* redraw window */
changed_window_setting(); changed_window_setting();
@ -787,8 +778,8 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
(void)foldFind(&wp->w_folds, top, &fp); (void)foldFind(&wp->w_folds, top, &fp);
while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len while (fp < (fold_T *)wp->w_folds.ga_data + wp->w_folds.ga_len
&& fp->fd_top < bot) { && fp->fd_top < bot) {
fp->fd_small = MAYBE; fp->fd_small = kNone;
++fp; fp++;
} }
if (foldmethodIsIndent(wp) if (foldmethodIsIndent(wp)
@ -831,44 +822,34 @@ void foldUpdateAll(win_T *win)
redraw_win_later(win, NOT_VALID); redraw_win_later(win, NOT_VALID);
} }
/* foldMoveTo() {{{2 */ // foldMoveTo() {{{2
/* //
* If "updown" is FALSE: Move to the start or end of the fold. // If "updown" is false: Move to the start or end of the fold.
* If "updown" is TRUE: move to fold at the same level. // If "updown" is true: move to fold at the same level.
* If not moved return FAIL. // If not moved return FAIL.
*/ int foldMoveTo(
int const bool updown,
foldMoveTo( const int dir, // FORWARD or BACKWARD
int updown, const long count
int dir, // FORWARD or BACKWARD
long count
) )
{ {
long n;
int retval = FAIL; int retval = FAIL;
linenr_T lnum_off;
linenr_T lnum_found;
linenr_T lnum; linenr_T lnum;
int use_level;
int maybe_small;
garray_T *gap;
fold_T *fp; fold_T *fp;
int level;
int last;
checkupdate(curwin); checkupdate(curwin);
/* Repeat "count" times. */ // Repeat "count" times.
for (n = 0; n < count; ++n) { for (long n = 0; n < count; n++) {
/* Find nested folds. Stop when a fold is closed. The deepest fold // Find nested folds. Stop when a fold is closed. The deepest fold
* that moves the cursor is used. */ // that moves the cursor is used.
lnum_off = 0; linenr_T lnum_off = 0;
gap = &curwin->w_folds; garray_T *gap = &curwin->w_folds;
use_level = FALSE; bool use_level = false;
maybe_small = FALSE; bool maybe_small = false;
lnum_found = curwin->w_cursor.lnum; linenr_T lnum_found = curwin->w_cursor.lnum;
level = 0; int level = 0;
last = FALSE; bool last = false;
for (;; ) { for (;; ) {
if (!foldFind(gap, curwin->w_cursor.lnum - lnum_off, &fp)) { if (!foldFind(gap, curwin->w_cursor.lnum - lnum_off, &fp)) {
if (!updown) if (!updown)
@ -886,14 +867,15 @@ foldMoveTo(
} }
/* don't look for contained folds, they will always move /* don't look for contained folds, they will always move
* the cursor too far. */ * the cursor too far. */
last = TRUE; last = true;
} }
if (!last) { if (!last) {
/* Check if this fold is closed. */ /* Check if this fold is closed. */
if (check_closed(curwin, fp, &use_level, level, if (check_closed(curwin, fp, &use_level, level,
&maybe_small, lnum_off)) &maybe_small, lnum_off)) {
last = TRUE; last = true;
}
/* "[z" and "]z" stop at closed fold */ /* "[z" and "]z" stop at closed fold */
if (last && !updown) if (last && !updown)
@ -1306,25 +1288,21 @@ static void foldOpenNested(fold_T *fpr)
} }
} }
/* deleteFoldEntry() {{{2 */ // deleteFoldEntry() {{{2
/* // Delete fold "idx" from growarray "gap".
* Delete fold "idx" from growarray "gap". // When "recursive" is true also delete all the folds contained in it.
* When "recursive" is TRUE also delete all the folds contained in it. // When "recursive" is false contained folds are moved one level up.
* When "recursive" is FALSE contained folds are moved one level up. static void deleteFoldEntry(garray_T *const gap, const int idx,
*/ const bool recursive)
static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
{ {
fold_T *fp; fold_T *fp = (fold_T *)gap->ga_data + idx;
int i;
fold_T *nfp;
fp = (fold_T *)gap->ga_data + idx;
if (recursive || GA_EMPTY(&fp->fd_nested)) { if (recursive || GA_EMPTY(&fp->fd_nested)) {
/* recursively delete the contained folds */ // recursively delete the contained folds
deleteFoldRecurse(&fp->fd_nested); deleteFoldRecurse(&fp->fd_nested);
--gap->ga_len; gap->ga_len--;
if (idx < gap->ga_len) if (idx < gap->ga_len) {
memmove(fp, fp + 1, sizeof(fold_T) * (size_t)(gap->ga_len - idx)); memmove(fp, fp + 1, sizeof(*fp) * (size_t)(gap->ga_len - idx));
}
} else { } else {
/* Move nested folds one level up, to overwrite the fold that is /* Move nested folds one level up, to overwrite the fold that is
* deleted. */ * deleted. */
@ -1334,22 +1312,24 @@ static void deleteFoldEntry(garray_T *gap, int idx, int recursive)
/* Get "fp" again, the array may have been reallocated. */ /* Get "fp" again, the array may have been reallocated. */
fp = (fold_T *)gap->ga_data + idx; fp = (fold_T *)gap->ga_data + idx;
/* adjust fd_top and fd_flags for the moved folds */ // adjust fd_top and fd_flags for the moved folds
nfp = (fold_T *)fp->fd_nested.ga_data; fold_T *nfp = (fold_T *)fp->fd_nested.ga_data;
for (i = 0; i < moved; ++i) { for (int i = 0; i < moved; i++) {
nfp[i].fd_top += fp->fd_top; nfp[i].fd_top += fp->fd_top;
if (fp->fd_flags == FD_LEVEL) if (fp->fd_flags == FD_LEVEL)
nfp[i].fd_flags = FD_LEVEL; nfp[i].fd_flags = FD_LEVEL;
if (fp->fd_small == MAYBE) if (fp->fd_small == kNone) {
nfp[i].fd_small = MAYBE; nfp[i].fd_small = kNone;
}
} }
/* move the existing folds down to make room */ // move the existing folds down to make room
if (idx + 1 < gap->ga_len) if (idx + 1 < gap->ga_len) {
memmove(fp + moved, fp + 1, memmove(fp + moved, fp + 1,
sizeof(fold_T) * (size_t)(gap->ga_len - (idx + 1))); sizeof(*fp) * (size_t)(gap->ga_len - (idx + 1)));
/* move the contained folds one level up */ }
memmove(fp, nfp, sizeof(fold_T) * (size_t)moved); // move the contained folds one level up
memmove(fp, nfp, sizeof(*fp) * (size_t)moved);
xfree(nfp); xfree(nfp);
gap->ga_len += moved - 1; gap->ga_len += moved - 1;
} }
@ -1429,14 +1409,15 @@ static void foldMarkAdjustRecurse(garray_T *gap, linenr_T line1, linenr_T line2,
fp->fd_top += amount_after; fp->fd_top += amount_after;
} else { } else {
if (fp->fd_top >= top && last <= line2) { if (fp->fd_top >= top && last <= line2) {
/* 4. fold completely contained in range */ // 4. fold completely contained in range
if (amount == MAXLNUM) { if (amount == MAXLNUM) {
/* Deleting lines: delete the fold completely */ // Deleting lines: delete the fold completely
deleteFoldEntry(gap, i, TRUE); deleteFoldEntry(gap, i, true);
--i; /* adjust index for deletion */ i--; // adjust index for deletion
--fp; fp--;
} else } else {
fp->fd_top += amount; fp->fd_top += amount;
}
} else { } else {
if (fp->fd_top < top) { if (fp->fd_top < top) {
/* 2 or 3: need to correct nested folds too */ /* 2 or 3: need to correct nested folds too */
@ -1505,36 +1486,40 @@ static int getDeepestNestingRecurse(garray_T *gap)
/* /*
* Check if a fold is closed and update the info needed to check nested folds. * Check if a fold is closed and update the info needed to check nested folds.
*/ */
static int static bool check_closed(
check_closed( win_T *const win,
win_T *win, fold_T *const fp,
fold_T *fp, bool *const use_levelp, // true: outer fold had FD_LEVEL
int *use_levelp, // TRUE: outer fold had FD_LEVEL const int level, // folding depth
int level, // folding depth bool *const maybe_smallp, // true: outer this had fd_small == kNone
int *maybe_smallp, // TRUE: outer this had fd_small == MAYBE const linenr_T lnum_off // line number offset for fp->fd_top
linenr_T lnum_off // line number offset for fp->fd_top
) )
{ {
int closed = FALSE; bool closed = false;
/* Check if this fold is closed. If the flag is FD_LEVEL this /* Check if this fold is closed. If the flag is FD_LEVEL this
* fold and all folds it contains depend on 'foldlevel'. */ * fold and all folds it contains depend on 'foldlevel'. */
if (*use_levelp || fp->fd_flags == FD_LEVEL) { if (*use_levelp || fp->fd_flags == FD_LEVEL) {
*use_levelp = TRUE; *use_levelp = true;
if (level >= win->w_p_fdl) if (level >= win->w_p_fdl) {
closed = TRUE; closed = true;
} else if (fp->fd_flags == FD_CLOSED) }
closed = TRUE; } else if (fp->fd_flags == FD_CLOSED) {
closed = true;
}
/* Small fold isn't closed anyway. */ // Small fold isn't closed anyway.
if (fp->fd_small == MAYBE) if (fp->fd_small == kNone) {
*maybe_smallp = TRUE; *maybe_smallp = true;
}
if (closed) { if (closed) {
if (*maybe_smallp) if (*maybe_smallp) {
fp->fd_small = MAYBE; fp->fd_small = kNone;
}
checkSmall(win, fp, lnum_off); checkSmall(win, fp, lnum_off);
if (fp->fd_small == TRUE) if (fp->fd_small == kTrue) {
closed = FALSE; closed = false;
}
} }
return closed; return closed;
} }
@ -1545,43 +1530,38 @@ check_closed(
*/ */
static void static void
checkSmall( checkSmall(
win_T *wp, win_T *const wp,
fold_T *fp, fold_T *const fp,
linenr_T lnum_off // offset for fp->fd_top const linenr_T lnum_off // offset for fp->fd_top
) )
{ {
int count; if (fp->fd_small == kNone) {
int n; // Mark any nested folds to maybe-small
if (fp->fd_small == MAYBE) {
/* Mark any nested folds to maybe-small */
setSmallMaybe(&fp->fd_nested); setSmallMaybe(&fp->fd_nested);
if (fp->fd_len > curwin->w_p_fml) if (fp->fd_len > curwin->w_p_fml) {
fp->fd_small = FALSE; fp->fd_small = kFalse;
else { } else {
count = 0; int count = 0;
for (n = 0; n < fp->fd_len; ++n) { for (int n = 0; n < fp->fd_len; n++) {
count += plines_win_nofold(wp, fp->fd_top + lnum_off + n); count += plines_win_nofold(wp, fp->fd_top + lnum_off + n);
if (count > curwin->w_p_fml) { if (count > curwin->w_p_fml) {
fp->fd_small = FALSE; fp->fd_small = kFalse;
return; return;
} }
} }
fp->fd_small = TRUE; fp->fd_small = kTrue;
} }
} }
} }
/* setSmallMaybe() {{{2 */ // setSmallMaybe() {{{2
/* // Set small flags in "gap" to kNone.
* Set small flags in "gap" to MAYBE.
*/
static void setSmallMaybe(garray_T *gap) static void setSmallMaybe(garray_T *gap)
{ {
fold_T *fp = (fold_T *)gap->ga_data; fold_T *fp = (fold_T *)gap->ga_data;
for (int i = 0; i < gap->ga_len; ++i) { for (int i = 0; i < gap->ga_len; i++) {
fp[i].fd_small = MAYBE; fp[i].fd_small = kNone;
} }
} }
@ -1896,13 +1876,10 @@ void foldtext_cleanup(char_u *str)
* Update the folding for window "wp", at least from lines "top" to "bot". * Update the folding for window "wp", at least from lines "top" to "bot".
* Return TRUE if any folds did change. * Return TRUE if any folds did change.
*/ */
static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot) static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
{ {
linenr_T start;
linenr_T end;
fline_T fline; fline_T fline;
void (*getlevel)(fline_T *); void (*getlevel)(fline_T *);
int level;
fold_T *fp; fold_T *fp;
/* Avoid problems when being called recursively. */ /* Avoid problems when being called recursively. */
@ -1928,12 +1905,13 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
bot += diff_context; bot += diff_context;
} }
/* When deleting lines at the end of the buffer "top" can be past the end // When deleting lines at the end of the buffer "top" can be past the end
* of the buffer. */ // of the buffer.
if (top > wp->w_buffer->b_ml.ml_line_count) if (top > wp->w_buffer->b_ml.ml_line_count) {
top = wp->w_buffer->b_ml.ml_line_count; top = wp->w_buffer->b_ml.ml_line_count;
}
fold_changed = FALSE; fold_changed = false;
fline.wp = wp; fline.wp = wp;
fline.off = 0; fline.off = 0;
fline.lvl = 0; fline.lvl = 0;
@ -1954,8 +1932,8 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
/* Need to get the level of the line above top, it is used if there is /* Need to get the level of the line above top, it is used if there is
* no marker at the top. */ * no marker at the top. */
if (top > 1) { if (top > 1) {
/* Get the fold level at top - 1. */ // Get the fold level at top - 1.
level = foldLevelWin(wp, top - 1); const int level = foldLevelWin(wp, top - 1);
/* The fold may end just above the top, check for that. */ /* The fold may end just above the top, check for that. */
fline.lnum = top - 1; fline.lnum = top - 1;
@ -2031,11 +2009,12 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
} }
} }
start = fline.lnum; linenr_T start = fline.lnum;
end = bot; linenr_T end = bot;
/* Do at least one line. */ // Do at least one line.
if (start > end && end < wp->w_buffer->b_ml.ml_line_count) if (start > end && end < wp->w_buffer->b_ml.ml_line_count) {
end = start; end = start;
}
while (!got_int) { while (!got_int) {
/* Always stop at the end of the file ("end" can be past the end of /* Always stop at the end of the file ("end" can be past the end of
* the file). */ * the file). */
@ -2126,11 +2105,10 @@ static void foldUpdateIEMS(win_T *wp, linenr_T top, linenr_T bot)
* Returns bot, which may have been increased for lines that also need to be * Returns bot, which may have been increased for lines that also need to be
* updated as a result of a detected change in the fold. * updated as a result of a detected change in the fold.
*/ */
static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level, static linenr_T foldUpdateIEMSRecurse(
linenr_T startlnum, fline_T *flp, garray_T *const gap, const int level, const linenr_T startlnum,
LevelGetter getlevel, fline_T *const flp, LevelGetter getlevel, linenr_T bot,
linenr_T bot, const char topflags // containing fold flags
char topflags /* containing fold flags */
) )
{ {
linenr_T ll; linenr_T ll;
@ -2138,10 +2116,10 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
fold_T *fp2; fold_T *fp2;
int lvl = level; int lvl = level;
linenr_T startlnum2 = startlnum; linenr_T startlnum2 = startlnum;
linenr_T firstlnum = flp->lnum; /* first lnum we got */ const linenr_T firstlnum = flp->lnum; // first lnum we got
int i; int i;
int finish = FALSE; bool finish = false;
linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off; const linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off;
int concat; int concat;
/* /*
@ -2309,8 +2287,9 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
* found. */ * found. */
if (getlevel == foldlevelMarker if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr || getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax) || getlevel == foldlevelSyntax) {
finish = TRUE; finish = true;
}
} }
if (fp->fd_top == startlnum && concat) { if (fp->fd_top == startlnum && concat) {
i = (int)(fp - (fold_T *)gap->ga_data); i = (int)(fp - (fold_T *)gap->ga_data);
@ -2325,11 +2304,10 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
break; break;
} }
if (fp->fd_top >= startlnum) { if (fp->fd_top >= startlnum) {
/* A fold that starts at or after startlnum and stops // A fold that starts at or after startlnum and stops
* before the new fold must be deleted. Continue // before the new fold must be deleted. Continue
* looking for the next one. */ // looking for the next one.
deleteFoldEntry(gap, deleteFoldEntry(gap, (int)(fp - (fold_T *)gap->ga_data), true);
(int)(fp - (fold_T *)gap->ga_data), TRUE);
} else { } else {
/* A fold has some lines above startlnum, truncate it /* A fold has some lines above startlnum, truncate it
* to stop just above startlnum. */ * to stop just above startlnum. */
@ -2337,7 +2315,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
foldMarkAdjustRecurse(&fp->fd_nested, foldMarkAdjustRecurse(&fp->fd_nested,
(linenr_T)fp->fd_len, (linenr_T)MAXLNUM, (linenr_T)fp->fd_len, (linenr_T)MAXLNUM,
(linenr_T)MAXLNUM, 0L); (linenr_T)MAXLNUM, 0L);
fold_changed = TRUE; fold_changed = true;
} }
} else { } else {
/* Insert new fold. Careful: ga_data may be NULL and it /* Insert new fold. Careful: ga_data may be NULL and it
@ -2361,14 +2339,15 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
flp->wp->w_fold_manual = true; flp->wp->w_fold_manual = true;
} else } else
fp->fd_flags = (fp - 1)->fd_flags; fp->fd_flags = (fp - 1)->fd_flags;
fp->fd_small = MAYBE; fp->fd_small = kNone;
/* If using the "marker", "expr" or "syntax" method, we // If using the "marker", "expr" or "syntax" method, we
* need to continue until the end of the fold is found. */ // need to continue until the end of the fold is found.
if (getlevel == foldlevelMarker if (getlevel == foldlevelMarker
|| getlevel == foldlevelExpr || getlevel == foldlevelExpr
|| getlevel == foldlevelSyntax) || getlevel == foldlevelSyntax) {
finish = TRUE; finish = true;
fold_changed = TRUE; }
fold_changed = true;
break; break;
} }
} }
@ -2387,12 +2366,11 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
* Check "fp" for safety. * Check "fp" for safety.
*/ */
if (lvl > level && fp != NULL) { if (lvl > level && fp != NULL) {
/* // There is a nested fold, handle it recursively.
* There is a nested fold, handle it recursively. // At least do one line (can happen when finish is true).
*/ if (bot < flp->lnum) {
/* At least do one line (can happen when finish is TRUE). */
if (bot < flp->lnum)
bot = flp->lnum; bot = flp->lnum;
}
/* Line numbers in the nested fold are relative to the start of /* Line numbers in the nested fold are relative to the start of
* this fold. */ * this fold. */
@ -2454,8 +2432,8 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
/* Current fold at least extends until lnum. */ /* Current fold at least extends until lnum. */
if (fp->fd_len < flp->lnum - fp->fd_top) { if (fp->fd_len < flp->lnum - fp->fd_top) {
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; fold_changed = true;
} }
/* Delete contained folds from the end of the last one found until where /* Delete contained folds from the end of the last one found until where
@ -2482,8 +2460,9 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
foldSplit(gap, i, flp->lnum, bot); foldSplit(gap, i, flp->lnum, bot);
fp = (fold_T *)gap->ga_data + i; fp = (fold_T *)gap->ga_data + i;
} }
} else } else {
fp->fd_len = flp->lnum - fp->fd_top; fp->fd_len = flp->lnum - fp->fd_top;
}
fold_changed = true; fold_changed = true;
} }
} }
@ -2502,7 +2481,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
(linenr_T)MAXLNUM, (long)(fp2->fd_top - flp->lnum)); (linenr_T)MAXLNUM, (long)(fp2->fd_top - flp->lnum));
fp2->fd_len -= flp->lnum - fp2->fd_top; fp2->fd_len -= flp->lnum - fp2->fd_top;
fp2->fd_top = flp->lnum; fp2->fd_top = flp->lnum;
fold_changed = TRUE; fold_changed = true;
} }
if (lvl >= level) { if (lvl >= level) {
@ -2511,8 +2490,8 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *gap, int level,
} }
break; break;
} }
fold_changed = TRUE; fold_changed = true;
deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE); deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), true);
} }
/* Need to redraw the lines we inspected, which might be further down than /* Need to redraw the lines we inspected, which might be further down than
@ -2548,36 +2527,32 @@ static void foldInsert(garray_T *gap, int i)
* The caller must first have taken care of any nested folds from "top" to * The caller must first have taken care of any nested folds from "top" to
* "bot"! * "bot"!
*/ */
static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot) static void foldSplit(garray_T *const gap, const int i, const linenr_T top,
const linenr_T bot)
{ {
fold_T *fp;
fold_T *fp2; fold_T *fp2;
garray_T *gap1;
garray_T *gap2;
int idx;
int len;
/* The fold continues below bot, need to split it. */ /* The fold continues below bot, need to split it. */
foldInsert(gap, i + 1); foldInsert(gap, i + 1);
fp = (fold_T *)gap->ga_data + i; fold_T *const fp = (fold_T *)gap->ga_data + i;
fp[1].fd_top = bot + 1; fp[1].fd_top = bot + 1;
// check for wrap around (MAXLNUM, and 32bit) // check for wrap around (MAXLNUM, and 32bit)
assert(fp[1].fd_top > bot); assert(fp[1].fd_top > bot);
fp[1].fd_len = fp->fd_len - (fp[1].fd_top - fp->fd_top); fp[1].fd_len = fp->fd_len - (fp[1].fd_top - fp->fd_top);
fp[1].fd_flags = fp->fd_flags; fp[1].fd_flags = fp->fd_flags;
fp[1].fd_small = MAYBE; fp[1].fd_small = kNone;
fp->fd_small = MAYBE; fp->fd_small = kNone;
/* Move nested folds below bot to new fold. There can't be /* Move nested folds below bot to new fold. There can't be
* any between top and bot, they have been removed by the caller. */ * any between top and bot, they have been removed by the caller. */
gap1 = &fp->fd_nested; garray_T *const gap1 = &fp->fd_nested;
gap2 = &fp[1].fd_nested; garray_T *const gap2 = &fp[1].fd_nested;
(void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2)); (void)(foldFind(gap1, bot + 1 - fp->fd_top, &fp2));
len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2); const int len = (int)((fold_T *)gap1->ga_data + gap1->ga_len - fp2);
if (len > 0) { if (len > 0) {
ga_grow(gap2, len); ga_grow(gap2, len);
for (idx = 0; idx < len; ++idx) { for (int idx = 0; idx < len; idx++) {
((fold_T *)gap2->ga_data)[idx] = fp2[idx]; ((fold_T *)gap2->ga_data)[idx] = fp2[idx];
((fold_T *)gap2->ga_data)[idx].fd_top ((fold_T *)gap2->ga_data)[idx].fd_top
-= fp[1].fd_top - fp->fd_top; -= fp[1].fd_top - fp->fd_top;
@ -2586,7 +2561,7 @@ static void foldSplit(garray_T *gap, int i, linenr_T top, linenr_T bot)
gap1->ga_len -= len; gap1->ga_len -= len;
} }
fp->fd_len = top - fp->fd_top; fp->fd_len = top - fp->fd_top;
fold_changed = TRUE; fold_changed = true;
} }
/* foldRemove() {{{2 */ /* foldRemove() {{{2 */
@ -2848,8 +2823,8 @@ static void foldMerge(fold_T *fp1, garray_T *gap, fold_T *fp2)
} }
fp1->fd_len += fp2->fd_len; fp1->fd_len += fp2->fd_len;
deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), TRUE); deleteFoldEntry(gap, (int)(fp2 - (fold_T *)gap->ga_data), true);
fold_changed = TRUE; fold_changed = true;
} }
/* foldlevelIndent() {{{2 */ /* foldlevelIndent() {{{2 */

View File

@ -191,7 +191,7 @@ EXTERN int cmdline_star INIT(= FALSE); /* cmdline is crypted */
EXTERN int exec_from_reg INIT(= FALSE); /* executing register */ EXTERN int exec_from_reg INIT(= FALSE); /* executing register */
EXTERN int screen_cleared INIT(= FALSE); /* screen has been cleared */ EXTERN TriState screen_cleared INIT(= kFalse); // screen has been cleared
/* /*
* When '$' is included in 'cpoptions' option set: * When '$' is included in 'cpoptions' option set:
@ -952,9 +952,9 @@ EXTERN char psepcN INIT(= '/'); // abnormal path separator character
EXTERN char pseps[2] INIT(= { '\\', 0 }); // normal path separator string EXTERN char pseps[2] INIT(= { '\\', 0 }); // normal path separator string
#endif #endif
/* Set to TRUE when an operator is being executed with virtual editing, MAYBE // Set to kTrue when an operator is being executed with virtual editing
* when no operator is being executed, FALSE otherwise. */ // kNone when no operator is being executed, kFalse otherwise.
EXTERN int virtual_op INIT(= MAYBE); EXTERN TriState virtual_op INIT(= kNone);
/* Display tick, incremented for each call to update_screen() */ /* Display tick, incremented for each call to update_screen() */
EXTERN disptick_T display_tick INIT(= 0); EXTERN disptick_T display_tick INIT(= 0);

View File

@ -134,9 +134,9 @@ static int current_syn_id;
#define PRCOLOR_BLACK 0 #define PRCOLOR_BLACK 0
#define PRCOLOR_WHITE 0xffffff #define PRCOLOR_WHITE 0xffffff
static int curr_italic; static TriState curr_italic;
static int curr_bold; static TriState curr_bold;
static int curr_underline; static TriState curr_underline;
static uint32_t curr_bg; static uint32_t curr_bg;
static uint32_t curr_fg; static uint32_t curr_fg;
static int page_count; static int page_count;
@ -417,7 +417,8 @@ static void prt_set_bg(uint32_t bg)
} }
} }
static void prt_set_font(int bold, int italic, int underline) static void prt_set_font(const TriState bold, const TriState italic,
const TriState underline)
{ {
if (curr_bold != bold if (curr_bold != bold
|| curr_italic != italic || curr_italic != italic
@ -429,34 +430,32 @@ static void prt_set_font(int bold, int italic, int underline)
} }
} }
/* // Print the line number in the left margin.
* Print the line number in the left margin. static void prt_line_number(prt_settings_T *const psettings,
*/ const int page_line, const linenr_T lnum)
static void prt_line_number(prt_settings_T *psettings, int page_line, linenr_T lnum)
{ {
int i;
char_u tbuf[20];
prt_set_fg(psettings->number.fg_color); prt_set_fg(psettings->number.fg_color);
prt_set_bg(psettings->number.bg_color); prt_set_bg(psettings->number.bg_color);
prt_set_font(psettings->number.bold, psettings->number.italic, prt_set_font(psettings->number.bold, psettings->number.italic,
psettings->number.underline); psettings->number.underline);
mch_print_start_line(TRUE, page_line); mch_print_start_line(true, page_line);
/* Leave two spaces between the number and the text; depends on // Leave two spaces between the number and the text; depends on
* PRINT_NUMBER_WIDTH. */ // PRINT_NUMBER_WIDTH.
sprintf((char *)tbuf, "%6ld", (long)lnum); char_u tbuf[20];
for (i = 0; i < 6; i++) snprintf((char *)tbuf, sizeof(tbuf), "%6ld", (long)lnum);
for (int i = 0; i < 6; i++) {
(void)mch_print_text_out(&tbuf[i], 1); (void)mch_print_text_out(&tbuf[i], 1);
}
if (psettings->do_syntax) if (psettings->do_syntax) {
/* Set colors for next character. */ // Set colors for next character.
current_syn_id = -1; current_syn_id = -1;
else { } else {
/* Set colors and font back to normal. */ // Set colors and font back to normal.
prt_set_fg(PRCOLOR_BLACK); prt_set_fg(PRCOLOR_BLACK);
prt_set_bg(PRCOLOR_WHITE); prt_set_bg(PRCOLOR_WHITE);
prt_set_font(FALSE, FALSE, FALSE); prt_set_font(kFalse, kFalse, kFalse);
} }
} }
@ -499,22 +498,20 @@ int prt_get_unit(int idx)
return u; return u;
} }
/* // Print the page header.
* Print the page header. static void prt_header(prt_settings_T *const psettings, const int pagenum,
*/ const linenr_T lnum)
static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum)
{ {
int width = psettings->chars_per_line; int width = psettings->chars_per_line;
int page_line;
char_u *tbuf;
char_u *p;
/* Also use the space for the line number. */ // Also use the space for the line number.
if (prt_use_number()) if (prt_use_number()) {
width += PRINT_NUMBER_WIDTH; width += PRINT_NUMBER_WIDTH;
}
assert(width >= 0); assert(width >= 0);
tbuf = xmalloc((size_t)width + IOSIZE); const size_t tbuf_size = (size_t)width + IOSIZE;
char_u *tbuf = xmalloc(tbuf_size);
if (*p_header != NUL) { if (*p_header != NUL) {
linenr_T tmp_lnum, tmp_topline, tmp_botline; linenr_T tmp_lnum, tmp_topline, tmp_botline;
@ -543,38 +540,40 @@ static void prt_header(prt_settings_T *psettings, int pagenum, linenr_T lnum)
curwin->w_cursor.lnum = tmp_lnum; curwin->w_cursor.lnum = tmp_lnum;
curwin->w_topline = tmp_topline; curwin->w_topline = tmp_topline;
curwin->w_botline = tmp_botline; curwin->w_botline = tmp_botline;
} else } else {
sprintf((char *)tbuf, _("Page %d"), pagenum); snprintf((char *)tbuf, tbuf_size, _("Page %d"), pagenum);
}
prt_set_fg(PRCOLOR_BLACK); prt_set_fg(PRCOLOR_BLACK);
prt_set_bg(PRCOLOR_WHITE); prt_set_bg(PRCOLOR_WHITE);
prt_set_font(TRUE, FALSE, FALSE); prt_set_font(kTrue, kFalse, kFalse);
/* Use a negative line number to indicate printing in the top margin. */ // Use a negative line number to indicate printing in the top margin.
page_line = 0 - prt_header_height(); int page_line = 0 - prt_header_height();
mch_print_start_line(TRUE, page_line); mch_print_start_line(true, page_line);
for (p = tbuf; *p != NUL; ) { for (char_u *p = tbuf; *p != NUL; ) {
int l = (*mb_ptr2len)(p); const int l = (*mb_ptr2len)(p);
assert(l >= 0); assert(l >= 0);
if (mch_print_text_out(p, (size_t)l)) { if (mch_print_text_out(p, (size_t)l)) {
++page_line; page_line++;
if (page_line >= 0) /* out of room in header */ if (page_line >= 0) { // out of room in header
break; break;
mch_print_start_line(TRUE, page_line); }
mch_print_start_line(true, page_line);
} }
p += l; p += l;
} }
xfree(tbuf); xfree(tbuf);
if (psettings->do_syntax) if (psettings->do_syntax) {
/* Set colors for next character. */ // Set colors for next character.
current_syn_id = -1; current_syn_id = -1;
else { } else {
/* Set colors and font back to normal. */ // Set colors and font back to normal.
prt_set_fg(PRCOLOR_BLACK); prt_set_fg(PRCOLOR_BLACK);
prt_set_bg(PRCOLOR_WHITE); prt_set_bg(PRCOLOR_WHITE);
prt_set_font(FALSE, FALSE, FALSE); prt_set_font(kFalse, kFalse, kFalse);
} }
} }
@ -640,21 +639,19 @@ void ex_hardcopy(exarg_T *eap)
else else
settings.do_syntax = settings.has_color; settings.do_syntax = settings.has_color;
/* Set up printing attributes for line numbers */ // Set up printing attributes for line numbers
settings.number.fg_color = PRCOLOR_BLACK; settings.number.fg_color = PRCOLOR_BLACK;
settings.number.bg_color = PRCOLOR_WHITE; settings.number.bg_color = PRCOLOR_WHITE;
settings.number.bold = FALSE; settings.number.bold = kFalse;
settings.number.italic = TRUE; settings.number.italic = kTrue;
settings.number.underline = FALSE; settings.number.underline = kFalse;
/*
* Syntax highlighting of line numbers.
*/
if (prt_use_number() && settings.do_syntax) {
int id;
id = syn_name2id((char_u *)"LineNr"); // Syntax highlighting of line numbers.
if (id > 0) if (prt_use_number() && settings.do_syntax) {
int id = syn_name2id((char_u *)"LineNr");
if (id > 0) {
id = syn_get_final_id(id); id = syn_get_final_id(id);
}
prt_get_attr(id, &settings.number, settings.modec); prt_get_attr(id, &settings.number, settings.modec);
} }
@ -672,13 +669,13 @@ void ex_hardcopy(exarg_T *eap)
/* Set colors and font to normal. */ /* Set colors and font to normal. */
curr_bg = 0xffffffff; curr_bg = 0xffffffff;
curr_fg = 0xffffffff; curr_fg = 0xffffffff;
curr_italic = MAYBE; curr_italic = kNone;
curr_bold = MAYBE; curr_bold = kNone;
curr_underline = MAYBE; curr_underline = kNone;
prt_set_fg(PRCOLOR_BLACK); prt_set_fg(PRCOLOR_BLACK);
prt_set_bg(PRCOLOR_WHITE); prt_set_bg(PRCOLOR_WHITE);
prt_set_font(FALSE, FALSE, FALSE); prt_set_font(kFalse, kFalse, kFalse);
current_syn_id = -1; current_syn_id = -1;
jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present jobsplit = (printer_opts[OPT_PRINT_JOBSPLIT].present
@ -841,7 +838,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
tab_spaces = ppos->lead_spaces; tab_spaces = ppos->lead_spaces;
} }
mch_print_start_line(0, page_line); mch_print_start_line(false, page_line);
line = ml_get(ppos->file_line); line = ml_get(ppos->file_line);
/* /*
@ -1266,8 +1263,8 @@ static int prt_do_moveto;
static int prt_need_font; static int prt_need_font;
static int prt_font; static int prt_font;
static int prt_need_underline; static int prt_need_underline;
static int prt_underline; static TriState prt_underline;
static int prt_do_underline; static TriState prt_do_underline;
static int prt_need_fgcol; static int prt_need_fgcol;
static uint32_t prt_fgcol; static uint32_t prt_fgcol;
static int prt_need_bgcol; static int prt_need_bgcol;
@ -2855,7 +2852,7 @@ int mch_print_begin_page(char_u *str)
/* We have reset the font attributes, force setting them again. */ /* We have reset the font attributes, force setting them again. */
curr_bg = 0xffffffff; curr_bg = 0xffffffff;
curr_fg = 0xffffffff; curr_fg = 0xffffffff;
curr_bold = MAYBE; curr_bold = kNone;
return !prt_file_error; return !prt_file_error;
} }
@ -2868,11 +2865,12 @@ int mch_print_blank_page(void)
static double prt_pos_x = 0; static double prt_pos_x = 0;
static double prt_pos_y = 0; static double prt_pos_y = 0;
void mch_print_start_line(int margin, int page_line) void mch_print_start_line(const bool margin, const int page_line)
{ {
prt_pos_x = prt_left_margin; prt_pos_x = prt_left_margin;
if (margin) if (margin) {
prt_pos_x -= prt_number_width; prt_pos_x -= prt_number_width;
}
prt_pos_y = prt_top_margin - prt_first_line_height - prt_pos_y = prt_top_margin - prt_first_line_height -
page_line * prt_line_height; page_line * prt_line_height;
@ -3059,7 +3057,8 @@ int mch_print_text_out(char_u *const textp, size_t len)
return need_break; return need_break;
} }
void mch_print_set_font(int iBold, int iItalic, int iUnderline) void mch_print_set_font(const TriState iBold, const TriState iItalic,
const TriState iUnderline)
{ {
int font = 0; int font = 0;

View File

@ -4,6 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> // for size_t #include <stdlib.h> // for size_t
#include "nvim/globals.h" // for TriState
#include "nvim/types.h" // for char_u #include "nvim/types.h" // for char_u
#include "nvim/ex_cmds_defs.h" // for exarg_T #include "nvim/ex_cmds_defs.h" // for exarg_T
@ -13,9 +14,9 @@
typedef struct { typedef struct {
uint32_t fg_color; uint32_t fg_color;
uint32_t bg_color; uint32_t bg_color;
int bold; TriState bold;
int italic; TriState italic;
int underline; TriState underline;
int undercurl; int undercurl;
} prt_text_attr_T; } prt_text_attr_T;

View File

@ -63,8 +63,8 @@ ex_menu(exarg_T *eap)
char_u *p; char_u *p;
int i; int i;
long pri_tab[MENUDEPTH + 1]; long pri_tab[MENUDEPTH + 1];
int enable = MAYBE; /* TRUE for "menu enable", FALSE for "menu TriState enable = kNone; // kTrue for "menu enable",
* disable */ // kFalse for "menu disable
vimmenu_T menuarg; vimmenu_T menuarg;
modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu); modes = get_menu_cmd_modes(eap->cmd, eap->forceit, &noremap, &unmenu);
@ -133,10 +133,10 @@ ex_menu(exarg_T *eap)
* Check for "disable" or "enable" argument. * Check for "disable" or "enable" argument.
*/ */
if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) { if (STRNCMP(arg, "enable", 6) == 0 && ascii_iswhite(arg[6])) {
enable = TRUE; enable = kTrue;
arg = skipwhite(arg + 6); arg = skipwhite(arg + 6);
} else if (STRNCMP(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) { } else if (STRNCMP(arg, "disable", 7) == 0 && ascii_iswhite(arg[7])) {
enable = FALSE; enable = kFalse;
arg = skipwhite(arg + 7); arg = skipwhite(arg + 7);
} }
@ -160,22 +160,21 @@ ex_menu(exarg_T *eap)
/* /*
* If there is only a menu name, display menus with that name. * If there is only a menu name, display menus with that name.
*/ */
if (*map_to == NUL && !unmenu && enable == MAYBE) { if (*map_to == NUL && !unmenu && enable == kNone) {
show_menus(menu_path, modes); show_menus(menu_path, modes);
goto theend; goto theend;
} else if (*map_to != NUL && (unmenu || enable != MAYBE)) { } else if (*map_to != NUL && (unmenu || enable != kNone)) {
EMSG(_(e_trailing)); EMSG(_(e_trailing));
goto theend; goto theend;
} }
if (enable != MAYBE) { if (enable != kNone) {
/* // Change sensitivity of the menu.
* Change sensitivity of the menu. // For the PopUp menu, remove a menu for each mode separately.
* For the PopUp menu, remove a menu for each mode separately. // Careful: menu_nable_recurse() changes menu_path.
* Careful: menu_nable_recurse() changes menu_path. if (STRCMP(menu_path, "*") == 0) { // meaning: do all menus
*/
if (STRCMP(menu_path, "*") == 0) /* meaning: do all menus */
menu_path = (char_u *)""; menu_path = (char_u *)"";
}
if (menu_is_popup(menu_path)) { if (menu_is_popup(menu_path)) {
for (i = 0; i < MENU_INDEX_TIP; ++i) for (i = 0; i < MENU_INDEX_TIP; ++i)

View File

@ -1203,16 +1203,15 @@ int get_last_leader_offset(char_u *line, char_u **flags)
/* /*
* Return the number of window lines occupied by buffer line "lnum". * Return the number of window lines occupied by buffer line "lnum".
*/ */
int plines(linenr_T lnum) int plines(const linenr_T lnum)
{ {
return plines_win(curwin, lnum, TRUE); return plines_win(curwin, lnum, true);
} }
int int plines_win(
plines_win ( win_T *const wp,
win_T *wp, const linenr_T lnum,
linenr_T lnum, const bool winheight // when true limit to window height
int winheight /* when TRUE limit to window height */
) )
{ {
/* Check for filler lines above this buffer line. When folded the result /* Check for filler lines above this buffer line. When folded the result
@ -1220,34 +1219,34 @@ plines_win (
return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum); return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
} }
int plines_nofill(linenr_T lnum) int plines_nofill(const linenr_T lnum)
{ {
return plines_win_nofill(curwin, lnum, TRUE); return plines_win_nofill(curwin, lnum, true);
} }
int int plines_win_nofill(
plines_win_nofill ( win_T *const wp,
win_T *wp, const linenr_T lnum,
linenr_T lnum, const bool winheight // when true limit to window height
int winheight /* when TRUE limit to window height */
) )
{ {
int lines; if (!wp->w_p_wrap) {
if (!wp->w_p_wrap)
return 1; return 1;
}
if (wp->w_width == 0) if (wp->w_width == 0) {
return 1; return 1;
}
/* A folded lines is handled just like an empty line. */ // A folded lines is handled just like an empty line.
/* NOTE: Caller must handle lines that are MAYBE folded. */ if (lineFolded(wp, lnum)) {
if (lineFolded(wp, lnum) == TRUE)
return 1; return 1;
}
lines = plines_win_nofold(wp, lnum); const int lines = plines_win_nofold(wp, lnum);
if (winheight > 0 && lines > wp->w_height) if (winheight && lines > wp->w_height) {
return wp->w_height; return wp->w_height;
}
return lines; return lines;
} }
@ -1347,11 +1346,12 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last)
++count; /* count 1 for "+-- folded" line */ ++count; /* count 1 for "+-- folded" line */
first += x; first += x;
} else { } else {
if (first == wp->w_topline) if (first == wp->w_topline) {
count += plines_win_nofill(wp, first, TRUE) + wp->w_topfill; count += plines_win_nofill(wp, first, true) + wp->w_topfill;
else } else {
count += plines_win(wp, first, TRUE); count += plines_win(wp, first, true);
++first; }
first++;
} }
} }
return count; return count;

View File

@ -2015,7 +2015,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
default: default:
clearopbeep(oap); clearopbeep(oap);
} }
virtual_op = MAYBE; virtual_op = kNone;
if (!gui_yank) { if (!gui_yank) {
/* /*
* if 'sol' not set, go back to old column for some commands * if 'sol' not set, go back to old column for some commands
@ -2090,7 +2090,7 @@ static void op_colon(oparg_T *oap)
*/ */
static void op_function(oparg_T *oap) static void op_function(oparg_T *oap)
{ {
int save_virtual_op = virtual_op; const TriState save_virtual_op = virtual_op;
if (*p_opfunc == NUL) if (*p_opfunc == NUL)
EMSG(_("E774: 'operatorfunc' is empty")); EMSG(_("E774: 'operatorfunc' is empty"));
@ -2113,7 +2113,7 @@ static void op_function(oparg_T *oap)
// Reset virtual_op so that 'virtualedit' can be changed in the // Reset virtual_op so that 'virtualedit' can be changed in the
// function. // function.
virtual_op = MAYBE; virtual_op = kNone;
(void)call_func_retnr(p_opfunc, 1, argv, false); (void)call_func_retnr(p_opfunc, 1, argv, false);

View File

@ -5383,7 +5383,7 @@ void cursor_pos_info(dict_T *dict)
case Ctrl_V: case Ctrl_V:
virtual_op = virtual_active(); virtual_op = virtual_active();
block_prep(&oparg, &bd, lnum, 0); block_prep(&oparg, &bd, lnum, 0);
virtual_op = MAYBE; virtual_op = kNone;
s = bd.textstart; s = bd.textstart;
len = (long)bd.textlen; len = (long)bd.textlen;
break; break;

View File

@ -783,17 +783,19 @@ static void win_update(win_T *wp)
} }
} }
(void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, true, NULL);
if (mod_top > lnumt) if (mod_top > lnumt) {
mod_top = lnumt; mod_top = lnumt;
}
/* Now do the same for the bottom line (one above mod_bot). */ // Now do the same for the bottom line (one above mod_bot).
--mod_bot; mod_bot--;
(void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, true, NULL);
++mod_bot; mod_bot++;
if (mod_bot < lnumb) if (mod_bot < lnumb) {
mod_bot = lnumb; mod_bot = lnumb;
} }
}
/* When a change starts above w_topline and the end is below /* When a change starts above w_topline and the end is below
* w_topline, start redrawing at w_topline. * w_topline, start redrawing at w_topline.
@ -833,12 +835,13 @@ static void win_update(win_T *wp)
type = VALID; type = VALID;
} }
/* Trick: we want to avoid clearing the screen twice. screenclear() will // Trick: we want to avoid clearing the screen twice. screenclear() will
* set "screen_cleared" to TRUE. The special value MAYBE (which is still // set "screen_cleared" to kTrue. The special value kNone (which is still
* non-zero and thus not FALSE) will indicate that screenclear() was not // non-zero and thus not kFalse) will indicate that screenclear() was not
* called. */ // called.
if (screen_cleared) if (screen_cleared) {
screen_cleared = MAYBE; screen_cleared = kNone;
}
/* /*
* If there are no changes on the screen that require a complete redraw, * If there are no changes on the screen that require a complete redraw,
@ -875,7 +878,7 @@ static void win_update(win_T *wp)
++j; ++j;
if (j >= wp->w_height - 2) if (j >= wp->w_height - 2)
break; break;
(void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); (void)hasFoldingWin(wp, ln, NULL, &ln, true, NULL);
} }
} else } else
j = wp->w_lines[0].wl_lnum - wp->w_topline; j = wp->w_lines[0].wl_lnum - wp->w_topline;
@ -987,7 +990,7 @@ static void win_update(win_T *wp)
* when it won't get updated below. */ * when it won't get updated below. */
if (wp->w_p_diff && bot_start > 0) if (wp->w_p_diff && bot_start > 0)
wp->w_lines[0].wl_size = wp->w_lines[0].wl_size =
plines_win_nofill(wp, wp->w_topline, TRUE) plines_win_nofill(wp, wp->w_topline, true)
+ wp->w_topfill; + wp->w_topfill;
} }
} }
@ -999,23 +1002,26 @@ static void win_update(win_T *wp)
if (mid_start == 0) { if (mid_start == 0) {
mid_end = wp->w_height; mid_end = wp->w_height;
if (ONE_WINDOW) { if (ONE_WINDOW) {
/* Clear the screen when it was not done by win_del_lines() or // Clear the screen when it was not done by win_del_lines() or
* win_ins_lines() above, "screen_cleared" is FALSE or MAYBE // win_ins_lines() above, "screen_cleared" is kFalse or kNone
* then. */ // then.
if (screen_cleared != TRUE) if (screen_cleared != kTrue) {
screenclear(); screenclear();
/* The screen was cleared, redraw the tab pages line. */ }
if (redraw_tabline) // The screen was cleared, redraw the tab pages line.
if (redraw_tabline) {
draw_tabline(); draw_tabline();
} }
} }
}
/* When win_del_lines() or win_ins_lines() caused the screen to be /* When win_del_lines() or win_ins_lines() caused the screen to be
* cleared (only happens for the first window) or when screenclear() * cleared (only happens for the first window) or when screenclear()
* was called directly above, "must_redraw" will have been set to * was called directly above, "must_redraw" will have been set to
* NOT_VALID, need to reset it here to avoid redrawing twice. */ * NOT_VALID, need to reset it here to avoid redrawing twice. */
if (screen_cleared == TRUE) if (screen_cleared == kTrue) {
must_redraw = 0; must_redraw = 0;
}
} else { } else {
/* Not VALID or INVERTED: redraw all lines. */ /* Not VALID or INVERTED: redraw all lines. */
mid_start = 0; mid_start = 0;
@ -1303,15 +1309,15 @@ static void win_update(win_T *wp)
/* Able to count old number of rows: Count new window /* Able to count old number of rows: Count new window
* rows, and may insert/delete lines */ * rows, and may insert/delete lines */
j = idx; j = idx;
for (l = lnum; l < mod_bot; ++l) { for (l = lnum; l < mod_bot; l++) {
if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) if (hasFoldingWin(wp, l, NULL, &l, true, NULL)) {
++new_rows; new_rows++;
else if (l == wp->w_topline) } else if (l == wp->w_topline) {
new_rows += plines_win_nofill(wp, l, TRUE) new_rows += plines_win_nofill(wp, l, true) + wp->w_topfill;
+ wp->w_topfill; } else {
else new_rows += plines_win(wp, l, true);
new_rows += plines_win(wp, l, TRUE); }
++j; j++;
if (new_rows > wp->w_height - row - 2) { if (new_rows > wp->w_height - row - 2) {
/* it's getting too much, must redraw the rest */ /* it's getting too much, must redraw the rest */
new_rows = 9999; new_rows = 9999;
@ -1441,12 +1447,13 @@ static void win_update(win_T *wp)
} }
wp->w_lines[idx].wl_lnum = lnum; wp->w_lines[idx].wl_lnum = lnum;
wp->w_lines[idx].wl_valid = TRUE; wp->w_lines[idx].wl_valid = true;
if (row > wp->w_height) { /* past end of screen */ if (row > wp->w_height) { // past end of screen
/* we may need the size of that too long line later on */ // we may need the size of that too long line later on
if (dollar_vcol == -1) if (dollar_vcol == -1) {
wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); wp->w_lines[idx].wl_size = plines_win(wp, lnum, true);
++idx; }
idx++;
break; break;
} }
if (dollar_vcol == -1) if (dollar_vcol == -1)
@ -5520,11 +5527,13 @@ static void prepare_search_hl(win_T *wp, linenr_T lnum)
&& re_multiline(shl->rm.regprog)) { && re_multiline(shl->rm.regprog)) {
if (shl->first_lnum == 0) { if (shl->first_lnum == 0) {
for (shl->first_lnum = lnum; for (shl->first_lnum = lnum;
shl->first_lnum > wp->w_topline; --shl->first_lnum) shl->first_lnum > wp->w_topline;
if (hasFoldingWin(wp, shl->first_lnum - 1, shl->first_lnum--) {
NULL, NULL, TRUE, NULL)) if (hasFoldingWin(wp, shl->first_lnum - 1, NULL, NULL, true, NULL)) {
break; break;
} }
}
}
if (cur != NULL) { if (cur != NULL) {
cur->pos.cur = 0; cur->pos.cur = 0;
} }
@ -6067,7 +6076,7 @@ static void screenclear2(void)
ui_call_grid_clear(1); // clear the display ui_call_grid_clear(1); // clear the display
clear_cmdline = false; clear_cmdline = false;
mode_displayed = false; mode_displayed = false;
screen_cleared = true; // can use contents of ScreenLines now screen_cleared = kTrue; // can use contents of ScreenLines now
win_rest_invalid(firstwin); win_rest_invalid(firstwin);
redraw_cmdline = TRUE; redraw_cmdline = TRUE;

View File

@ -1549,37 +1549,31 @@ static bool find_rawstring_end(char_u *linep, pos_T *startpos, pos_T *endpos)
pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
{ {
static pos_T pos; /* current search position */ static pos_T pos; // current search position
int findc = 0; /* matching brace */ int findc = 0; // matching brace
int c; int count = 0; // cumulative number of braces
int count = 0; /* cumulative number of braces */ int backwards = false; // init for gcc
int backwards = false; /* init for gcc */ bool raw_string = false; // search for raw string
int raw_string = false; /* search for raw string */ bool inquote = false; // true when inside quotes
int inquote = false; /* true when inside quotes */
char_u *linep; /* pointer to current line */
char_u *ptr; char_u *ptr;
int do_quotes; /* check for quotes in current line */ int hash_dir = 0; // Direction searched for # things
int at_start; /* do_quotes value at start position */ int comment_dir = 0; // Direction searched for comments
int hash_dir = 0; /* Direction searched for # things */ int traveled = 0; // how far we've searched so far
int comment_dir = 0; /* Direction searched for comments */ bool ignore_cend = false; // ignore comment end
pos_T match_pos; /* Where last slash-star was found */ int match_escaped = 0; // search for escaped match
int start_in_quotes; /* start position is in quotes */ int dir; // Direction to search
int traveled = 0; /* how far we've searched so far */ int comment_col = MAXCOL; // start of / / comment
int ignore_cend = FALSE; /* ignore comment end */ bool lispcomm = false; // inside of Lisp-style comment
int cpo_match; /* vi compatible matching */ bool lisp = curbuf->b_p_lisp; // engage Lisp-specific hacks ;)
int cpo_bsl; /* don't recognize backslashes */
int match_escaped = 0; /* search for escaped match */
int dir; /* Direction to search */
int comment_col = MAXCOL; /* start of / / comment */
int lispcomm = FALSE; /* inside of Lisp-style comment */
int lisp = curbuf->b_p_lisp; /* engage Lisp-specific hacks ;) */
pos = curwin->w_cursor; pos = curwin->w_cursor;
pos.coladd = 0; pos.coladd = 0;
linep = ml_get(pos.lnum); char_u *linep = ml_get(pos.lnum); // pointer to current line
cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL); // vi compatible matching
cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL); bool cpo_match = (vim_strchr(p_cpo, CPO_MATCH) != NULL);
// don't recognize backslashes
bool cpo_bsl = (vim_strchr(p_cpo, CPO_MATCHBSL) != NULL);
/* Direction to search when initc is '/', '*' or '#' */ /* Direction to search when initc is '/', '*' or '#' */
if (flags & FM_BACKWARD) if (flags & FM_BACKWARD)
@ -1748,13 +1742,16 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
} }
} }
/* This is just guessing: when 'rightleft' is set, search for a matching // This is just guessing: when 'rightleft' is set, search for a matching
* paren/brace in the other direction. */ // paren/brace in the other direction.
if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL) if (curwin->w_p_rl && vim_strchr((char_u *)"()[]{}<>", initc) != NULL) {
backwards = !backwards; backwards = !backwards;
}
do_quotes = -1; int do_quotes = -1; // check for quotes in current line
start_in_quotes = MAYBE; int at_start; // do_quotes value at start position
TriState start_in_quotes = kNone; // start position is in quotes
pos_T match_pos; // Where last slash-star was found
clearpos(&match_pos); clearpos(&match_pos);
/* backward search: Check if this line contains a single-line comment */ /* backward search: Check if this line contains a single-line comment */
@ -1762,8 +1759,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
|| lisp || lisp
) )
comment_col = check_linecomment(linep); comment_col = check_linecomment(linep);
if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) if (lisp && comment_col != MAXCOL && pos.col > (colnr_T)comment_col) {
lispcomm = TRUE; /* find match inside this comment */ lispcomm = true; // find match inside this comment
}
while (!got_int) { while (!got_int) {
/* /*
* Go to the next position, forward or backward. We could use * Go to the next position, forward or backward. We could use
@ -1925,26 +1923,29 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
* one for a '\' at the end. * one for a '\' at the end.
*/ */
if (!do_quotes) { if (!do_quotes) {
inquote = FALSE; inquote = false;
if (ptr[-1] == '\\') { if (ptr[-1] == '\\') {
do_quotes = 1; do_quotes = 1;
if (start_in_quotes == MAYBE) { if (start_in_quotes == kNone) {
/* Do we need to use at_start here? */ // Do we need to use at_start here?
inquote = TRUE; inquote = true;
start_in_quotes = TRUE; start_in_quotes = kTrue;
} else if (backwards) } else if (backwards) {
inquote = TRUE; inquote = true;
}
} }
if (pos.lnum > 1) { if (pos.lnum > 1) {
ptr = ml_get(pos.lnum - 1); ptr = ml_get(pos.lnum - 1);
if (*ptr && *(ptr + STRLEN(ptr) - 1) == '\\') { if (*ptr && *(ptr + STRLEN(ptr) - 1) == '\\') {
do_quotes = 1; do_quotes = 1;
if (start_in_quotes == MAYBE) { if (start_in_quotes == kNone) {
inquote = at_start; inquote = at_start;
if (inquote) if (inquote) {
start_in_quotes = TRUE; start_in_quotes = kTrue;
} else if (!backwards) }
inquote = TRUE; } else if (!backwards) {
inquote = true;
}
} }
/* ml_get() only keeps one line, need to get linep again */ /* ml_get() only keeps one line, need to get linep again */
@ -1952,8 +1953,9 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
} }
} }
} }
if (start_in_quotes == MAYBE) if (start_in_quotes == kNone) {
start_in_quotes = FALSE; start_in_quotes = kFalse;
}
/* /*
* If 'smartmatch' is set: * If 'smartmatch' is set:
@ -1966,13 +1968,13 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
* inquote if the number of quotes in a line is even, unless this * inquote if the number of quotes in a line is even, unless this
* line or the previous one ends in a '\'. Complicated, isn't it? * line or the previous one ends in a '\'. Complicated, isn't it?
*/ */
c = PTR2CHAR(linep + pos.col); const int c = PTR2CHAR(linep + pos.col);
switch (c) { switch (c) {
case NUL: case NUL:
/* at end of line without trailing backslash, reset inquote */ /* at end of line without trailing backslash, reset inquote */
if (pos.col == 0 || linep[pos.col - 1] != '\\') { if (pos.col == 0 || linep[pos.col - 1] != '\\') {
inquote = FALSE; inquote = false;
start_in_quotes = FALSE; start_in_quotes = kFalse;
} }
break; break;
@ -1987,7 +1989,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
break; break;
if ((((int)pos.col - 1 - col) & 1) == 0) { if ((((int)pos.col - 1 - col) & 1) == 0) {
inquote = !inquote; inquote = !inquote;
start_in_quotes = FALSE; start_in_quotes = kFalse;
} }
} }
break; break;
@ -2039,7 +2041,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
/* Check for match outside of quotes, and inside of /* Check for match outside of quotes, and inside of
* quotes when the start is also inside of quotes. */ * quotes when the start is also inside of quotes. */
if ((!inquote || start_in_quotes == TRUE) if ((!inquote || start_in_quotes == kTrue)
&& (c == initc || c == findc)) { && (c == initc || c == findc)) {
int col, bslcnt = 0; int col, bslcnt = 0;

View File

@ -73,13 +73,13 @@ getkey:
} }
} }
/// Return TRUE if in the current mode we need to use virtual. /// Return true if in the current mode we need to use virtual.
int virtual_active(void) bool virtual_active(void)
{ {
// While an operator is being executed we return "virtual_op", because // While an operator is being executed we return "virtual_op", because
// VIsual_active has already been reset, thus we can't check for "block" // VIsual_active has already been reset, thus we can't check for "block"
// being used. // being used.
if (virtual_op != MAYBE) { if (virtual_op != kNone) {
return virtual_op; return virtual_op;
} }
return ve_flags == VE_ALL return ve_flags == VE_ALL

View File

@ -4848,8 +4848,8 @@ void scroll_to_fraction(win_T *wp, int prev_height)
sline = wp->w_wrow - line_size; sline = wp->w_wrow - line_size;
if (sline >= 0) { if (sline >= 0) {
/* Make sure the whole cursor line is visible, if possible. */ // Make sure the whole cursor line is visible, if possible.
int rows = plines_win(wp, lnum, FALSE); const int rows = plines_win(wp, lnum, false);
if (sline > wp->w_height - rows) { if (sline > wp->w_height - rows) {
sline = wp->w_height - rows; sline = wp->w_height - rows;
@ -4884,12 +4884,13 @@ void scroll_to_fraction(win_T *wp, int prev_height)
--sline; --sline;
break; break;
} }
--lnum; lnum--;
if (lnum == wp->w_topline) if (lnum == wp->w_topline) {
line_size = plines_win_nofill(wp, lnum, TRUE) line_size = plines_win_nofill(wp, lnum, true)
+ wp->w_topfill; + wp->w_topfill;
else } else {
line_size = plines_win(wp, lnum, TRUE); line_size = plines_win(wp, lnum, true);
}
sline -= line_size; sline -= line_size;
} }