aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2022-07-02 12:29:27 +0100
committerGitHub <noreply@github.com>2022-07-02 04:29:27 -0700
commited429c00d76414d07d7c7129f65ddf9be68e24f4 (patch)
tree62e78cec457de973a375872916f51b200a519f09 /src
parent662681694bf2e30b1f33ad235274c82a334ff742 (diff)
downloadrneovim-ed429c00d76414d07d7c7129f65ddf9be68e24f4.tar.gz
rneovim-ed429c00d76414d07d7c7129f65ddf9be68e24f4.tar.bz2
rneovim-ed429c00d76414d07d7c7129f65ddf9be68e24f4.zip
refactor(fold): style #19175
* refactor(fold): update comment formatting * refactor(fold): use post-increment/decrement * refactor(fold): reduce scope of local variables * refactor(fold): use booleans
Diffstat (limited to 'src')
-rw-r--r--src/nvim/ex_docmd.c2
-rw-r--r--src/nvim/fold.c533
-rw-r--r--src/nvim/globals.h9
-rw-r--r--src/nvim/message.c4
4 files changed, 234 insertions, 314 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 8fe62ae424..763aca62ef 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -2341,7 +2341,7 @@ static char *do_one_cmd(char **cmdlinep, int flags, cstack_T *cstack, LineGetter
do_return(&ea, TRUE, FALSE, NULL);
}
}
- need_rethrow = check_cstack = FALSE;
+ need_rethrow = check_cstack = false;
doend:
// can happen with zero line number
diff --git a/src/nvim/fold.c b/src/nvim/fold.c
index 3c3aaa1031..8f26e03a94 100644
--- a/src/nvim/fold.c
+++ b/src/nvim/fold.c
@@ -3,9 +3,7 @@
// vim: set fdm=marker fdl=1 fdc=3
-/*
- * fold.c: code for folding
- */
+// fold.c: code for folding
#include <inttypes.h>
#include <string.h>
@@ -41,12 +39,12 @@
// local declarations. {{{1
// typedef fold_T {{{2
-/*
- * The toplevel folds for each window are stored in the w_folds growarray.
- * Each toplevel fold can contain an array of second level folds in the
- * fd_nested growarray.
- * The info stored in both growarrays is the same: An array of fold_T.
- */
+
+// The toplevel folds for each window are stored in the w_folds growarray.
+// Each toplevel fold can contain an array of second level folds in the
+// fd_nested growarray.
+// 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
@@ -93,20 +91,16 @@ typedef void (*LevelGetter)(fline_T *);
#endif
static char *e_nofold = N_("E490: No fold found");
-/*
- * While updating the folds lines between invalid_top and invalid_bot have an
- * undefined fold level. Only used for the window currently being updated.
- */
+// While updating the folds lines between invalid_top and invalid_bot have an
+// undefined fold level. Only used for the window currently being updated.
static linenr_T invalid_top = (linenr_T)0;
static linenr_T invalid_bot = (linenr_T)0;
-/*
- * When using 'foldexpr' we sometimes get the level of the next line, which
- * calls foldlevel() to get the level of the current line, which hasn't been
- * stored yet. To get around this chicken-egg problem the level of the
- * previous line is stored here when available. prev_lnum is zero when the
- * level is not available.
- */
+// When using 'foldexpr' we sometimes get the level of the next line, which
+// calls foldlevel() to get the level of the current line, which hasn't been
+// stored yet. To get around this chicken-egg problem the level of the
+// previous line is stored here when available. prev_lnum is zero when the
+// level is not available.
static linenr_T prev_lnum = 0;
static int prev_lnum_lvl = -1;
@@ -130,7 +124,7 @@ void copyFoldingState(win_T *wp_from, win_T *wp_to)
}
// hasAnyFolding() {{{2
-/// @return TRUE if there may be folded lines in the current window.
+/// @return true if there may be folded lines in the current window.
int hasAnyFolding(win_T *win)
{
// very simple now, but can become more complex later
@@ -160,16 +154,6 @@ bool hasFolding(linenr_T lnum, linenr_T *firstp, linenr_T *lastp)
bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp,
linenr_T *const lastp, const bool cache, foldinfo_T *const infop)
{
- bool had_folded = false;
- linenr_T first = 0;
- linenr_T last = 0;
- linenr_T lnum_rel = lnum;
- fold_T *fp;
- int level = 0;
- bool use_level = false;
- bool maybe_small = false;
- int low_level = 0;
-
checkupdate(win);
// Return quickly when there is no folding at all in this window.
@@ -180,11 +164,13 @@ bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp
return false;
}
+ bool had_folded = false;
+ linenr_T first = 0;
+ linenr_T last = 0;
+
if (cache) {
- /*
- * 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.
- */
+ // 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.
const int x = find_wl_entry(win, lnum);
if (x >= 0) {
first = win->w_lines[x].wl_lnum;
@@ -193,10 +179,15 @@ bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp
}
}
+ linenr_T lnum_rel = lnum;
+ int level = 0;
+ int low_level = 0;
+ fold_T *fp;
+ bool maybe_small = false;
+ bool use_level = false;
+
if (first == 0) {
- /*
- * Recursively search for a fold that contains "lnum".
- */
+ // Recursively search for a fold that contains "lnum".
garray_T *gap = &win->w_folds;
for (;;) {
if (!foldFind(gap, lnum_rel, &fp)) {
@@ -224,7 +215,7 @@ bool hasFoldingWin(win_T *const win, const linenr_T lnum, linenr_T *const firstp
// relative to containing fold.
gap = &fp->fd_nested;
lnum_rel -= fp->fd_top;
- ++level;
+ level++;
}
}
@@ -311,42 +302,42 @@ foldinfo_T fold_info(win_T *win, linenr_T lnum)
}
// foldmethodIsManual() {{{2
-/// @return TRUE if 'foldmethod' is "manual"
+/// @return true if 'foldmethod' is "manual"
int foldmethodIsManual(win_T *wp)
{
return wp->w_p_fdm[3] == 'u';
}
// foldmethodIsIndent() {{{2
-/// @return TRUE if 'foldmethod' is "indent"
+/// @return true if 'foldmethod' is "indent"
int foldmethodIsIndent(win_T *wp)
{
return wp->w_p_fdm[0] == 'i';
}
// foldmethodIsExpr() {{{2
-/// @return TRUE if 'foldmethod' is "expr"
+/// @return true if 'foldmethod' is "expr"
int foldmethodIsExpr(win_T *wp)
{
return wp->w_p_fdm[1] == 'x';
}
// foldmethodIsMarker() {{{2
-/// @return TRUE if 'foldmethod' is "marker"
+/// @return true if 'foldmethod' is "marker"
int foldmethodIsMarker(win_T *wp)
{
return wp->w_p_fdm[2] == 'r';
}
// foldmethodIsSyntax() {{{2
-/// @return TRUE if 'foldmethod' is "syntax"
+/// @return true if 'foldmethod' is "syntax"
int foldmethodIsSyntax(win_T *wp)
{
return wp->w_p_fdm[0] == 's';
}
// foldmethodIsDiff() {{{2
-/// @return TRUE if 'foldmethod' is "diff"
+/// @return true if 'foldmethod' is "diff"
int foldmethodIsDiff(win_T *wp)
{
return wp->w_p_fdm[0] == 'd';
@@ -372,18 +363,17 @@ void closeFoldRecurse(pos_T pos)
/// Open or Close folds for current window in lines "first" to "last".
/// Used for "zo", "zO", "zc" and "zC" in Visual mode.
///
-/// @param opening TRUE to open, FALSE to close
-/// @param recurse TRUE to do it recursively
-/// @param had_visual TRUE when Visual selection used
+/// @param opening true to open, false to close
+/// @param recurse true to do it recursively
+/// @param had_visual true when Visual selection used
void opFoldRange(pos_T firstpos, pos_T lastpos, int opening, int recurse, int had_visual)
{
int done = DONE_NOTHING; // avoid error messages
linenr_T first = firstpos.lnum;
linenr_T last = lastpos.lnum;
- linenr_T lnum;
linenr_T lnum_next;
- for (lnum = first; lnum <= last; lnum = lnum_next + 1) {
+ for (linenr_T lnum = first; lnum <= last; lnum = lnum_next + 1) {
pos_T temp = { lnum, 0, 0 };
lnum_next = lnum;
// Opening one level only: next fold to open is after the one going to
@@ -426,12 +416,10 @@ void openFoldRecurse(pos_T pos)
/// Open folds until the cursor line is not in a closed fold.
void foldOpenCursor(void)
{
- int done;
-
checkupdate(curwin);
if (hasAnyFolding(curwin)) {
for (;;) {
- done = DONE_NOTHING;
+ int done = DONE_NOTHING;
(void)setManualFold(curwin->w_cursor, true, false, &done);
if (!(done & DONE_ACTION)) {
break;
@@ -447,9 +435,7 @@ void newFoldLevel(void)
newFoldLevelWin(curwin);
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
- /*
- * Set the same foldlevel in other windows in diff mode.
- */
+ // Set the same foldlevel in other windows in diff mode.
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
wp->w_p_fdl = curwin->w_p_fdl;
@@ -461,15 +447,13 @@ void newFoldLevel(void)
static void newFoldLevelWin(win_T *wp)
{
- fold_T *fp;
-
checkupdate(wp);
if (wp->w_fold_manual) {
// Set all flags for the first level of folds to FD_LEVEL. Following
// manual open/close will then change the flags to FD_OPEN or
// FD_CLOSED for those folds that don't use 'foldlevel'.
- fp = (fold_T *)wp->w_folds.ga_data;
- for (int i = 0; i < wp->w_folds.ga_len; ++i) {
+ fold_T *fp = (fold_T *)wp->w_folds.ga_data;
+ for (int i = 0; i < wp->w_folds.ga_len; i++) {
fp[i].fd_flags = FD_LEVEL;
}
wp->w_fold_manual = false;
@@ -491,19 +475,18 @@ void foldCheckClose(void)
}
// checkCloseRec() {{{2
-static int checkCloseRec(garray_T *gap, linenr_T lnum, int level)
+static bool checkCloseRec(garray_T *gap, linenr_T lnum, int level)
{
- fold_T *fp;
- int retval = FALSE;
+ bool retval = false;
- fp = (fold_T *)gap->ga_data;
- for (int i = 0; i < gap->ga_len; ++i) {
+ fold_T *fp = (fold_T *)gap->ga_data;
+ for (int i = 0; i < gap->ga_len; i++) {
// Only manually opened folds may need to be closed.
if (fp[i].fd_flags == FD_OPEN) {
if (level <= 0 && (lnum < fp[i].fd_top
|| lnum >= fp[i].fd_top + fp[i].fd_len)) {
fp[i].fd_flags = FD_LEVEL;
- retval = TRUE;
+ retval = true;
} else {
retval |= checkCloseRec(&fp[i].fd_nested, lnum - fp[i].fd_top,
level - 1);
@@ -514,19 +497,19 @@ static int checkCloseRec(garray_T *gap, linenr_T lnum, int level)
}
// foldCreateAllowed() {{{2
-/// @return TRUE if it's allowed to manually create or delete a fold or,
-/// give an error message and return FALSE if not.
+/// @return true if it's allowed to manually create or delete a fold or,
+/// give an error message and return false if not.
int foldManualAllowed(bool create)
{
if (foldmethodIsManual(curwin) || foldmethodIsMarker(curwin)) {
- return TRUE;
+ return true;
}
if (create) {
emsg(_("E350: Cannot create fold with current 'foldmethod'"));
} else {
emsg(_("E351: Cannot delete fold with current 'foldmethod'"));
}
- return FALSE;
+ return false;
}
// foldCreate() {{{2
@@ -534,13 +517,8 @@ int foldManualAllowed(bool create)
/// window.
void foldCreate(win_T *wp, pos_T start, pos_T end)
{
- fold_T *fp;
- garray_T *gap;
- garray_T fold_ga;
- int i;
- int cont;
- int use_level = FALSE;
- int closed = FALSE;
+ int use_level = false;
+ int closed = false;
int level = 0;
pos_T start_rel = start;
pos_T end_rel = end;
@@ -561,11 +539,14 @@ void foldCreate(win_T *wp, pos_T start, pos_T end)
checkupdate(wp);
+ int i;
+
// Find the place to insert the new fold
- gap = &wp->w_folds;
+ garray_T *gap = &wp->w_folds;
if (gap->ga_len == 0) {
i = 0;
} else {
+ fold_T *fp;
for (;;) {
if (!foldFind(gap, start_rel.lnum, &fp)) {
break;
@@ -599,10 +580,12 @@ void foldCreate(win_T *wp, pos_T start, pos_T end)
ga_grow(gap, 1);
{
- fp = (fold_T *)gap->ga_data + i;
+ fold_T *fp = (fold_T *)gap->ga_data + i;
+ garray_T fold_ga;
ga_init(&fold_ga, (int)sizeof(fold_T), 10);
// Count number of folds that will be contained in the new fold.
+ int cont;
for (cont = 0; i + cont < gap->ga_len; cont++) {
if (fp[cont].fd_top > end_rel.lnum) {
break;
@@ -668,7 +651,6 @@ void foldCreate(win_T *wp, pos_T start, pos_T end)
void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const int recursive,
const bool had_visual)
{
- fold_T *fp;
fold_T *found_fp = NULL;
linenr_T found_off = 0;
bool maybe_small = false;
@@ -687,6 +669,7 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const
linenr_T lnum_off = 0;
bool use_level = false;
for (;;) {
+ fold_T *fp;
if (!foldFind(gap, lnum - lnum_off, &fp)) {
break;
}
@@ -704,10 +687,10 @@ void deleteFold(win_T *const wp, const linenr_T start, const linenr_T end, const
// check nested folds
gap = &fp->fd_nested;
lnum_off += fp->fd_top;
- ++level;
+ level++;
}
if (found_ga == NULL) {
- ++lnum;
+ lnum++;
} else {
lnum = found_fp->fd_top + found_fp->fd_len + found_off;
@@ -808,7 +791,7 @@ void foldUpdate(win_T *wp, linenr_T top, linenr_T bot)
int save_got_int = got_int;
// reset got_int here, otherwise it won't work
- got_int = FALSE;
+ got_int = false;
foldUpdateIEMS(wp, top, bot);
got_int |= save_got_int;
}
@@ -944,7 +927,7 @@ int foldMoveTo(const bool updown, const int dir, const long count)
// Check nested folds (if any).
gap = &fp->fd_nested;
lnum_off += fp->fd_top;
- ++level;
+ level++;
}
if (lnum_found != curwin->w_cursor.lnum) {
if (retval == FAIL) {
@@ -970,15 +953,13 @@ void foldInitWin(win_T *new_win)
// find_wl_entry() {{{2
/// Find an entry in the win->w_lines[] array for buffer line "lnum".
-/// Only valid entries are considered (for entries where wl_valid is FALSE the
+/// Only valid entries are considered (for entries where wl_valid is false the
/// line number can be wrong).
///
/// @return index of entry or -1 if not found.
int find_wl_entry(win_T *win, linenr_T lnum)
{
- int i;
-
- for (i = 0; i < win->w_lines_valid; ++i) {
+ for (int i = 0; i < win->w_lines_valid; i++) {
if (win->w_lines[i].wl_valid) {
if (lnum < win->w_lines[i].wl_lnum) {
return -1;
@@ -995,13 +976,13 @@ int find_wl_entry(win_T *win, linenr_T lnum)
/// Adjust the Visual area to include any fold at the start or end completely.
void foldAdjustVisual(void)
{
- pos_T *start, *end;
- char_u *ptr;
-
if (!VIsual_active || !hasAnyFolding(curwin)) {
return;
}
+ pos_T *start, *end;
+ char_u *ptr;
+
if (ltoreq(VIsual, curwin->w_cursor)) {
start = &VIsual;
end = &curwin->w_cursor;
@@ -1035,9 +1016,6 @@ void foldAdjustCursor(void)
/// Will "clone" (i.e deep copy) a garray_T of folds.
void cloneFoldGrowArray(garray_T *from, garray_T *to)
{
- fold_T *from_p;
- fold_T *to_p;
-
ga_init(to, from->ga_itemsize, from->ga_growsize);
if (GA_EMPTY(from)) {
@@ -1046,8 +1024,8 @@ void cloneFoldGrowArray(garray_T *from, garray_T *to)
ga_grow(to, from->ga_len);
- from_p = (fold_T *)from->ga_data;
- to_p = (fold_T *)to->ga_data;
+ fold_T *from_p = (fold_T *)from->ga_data;
+ fold_T *to_p = (fold_T *)to->ga_data;
for (int i = 0; i < from->ga_len; i++) {
to_p->fd_top = from_p->fd_top;
@@ -1055,9 +1033,9 @@ void cloneFoldGrowArray(garray_T *from, garray_T *to)
to_p->fd_flags = from_p->fd_flags;
to_p->fd_small = from_p->fd_small;
cloneFoldGrowArray(&from_p->fd_nested, &to_p->fd_nested);
- ++to->ga_len;
- ++from_p;
- ++to_p;
+ to->ga_len++;
+ from_p++;
+ to_p++;
}
}
@@ -1069,22 +1047,17 @@ void cloneFoldGrowArray(garray_T *from, garray_T *to)
/// @return false when there is no fold that contains "lnum".
static bool foldFind(const garray_T *gap, linenr_T lnum, fold_T **fpp)
{
- linenr_T low, high;
- fold_T *fp;
-
if (gap->ga_len == 0) {
*fpp = NULL;
return false;
}
- /*
- * Perform a binary search.
- * "low" is lowest index of possible match.
- * "high" is highest index of possible match.
- */
- fp = (fold_T *)gap->ga_data;
- low = 0;
- high = gap->ga_len - 1;
+ // Perform a binary search.
+ // "low" is lowest index of possible match.
+ // "high" is highest index of possible match.
+ fold_T *fp = (fold_T *)gap->ga_data;
+ linenr_T low = 0;
+ linenr_T high = gap->ga_len - 1;
while (low <= high) {
linenr_T i = (low + high) / 2;
if (fp[i].fd_top > lnum) {
@@ -1110,10 +1083,9 @@ static int foldLevelWin(win_T *wp, linenr_T lnum)
fold_T *fp;
linenr_T lnum_rel = lnum;
int level = 0;
- garray_T *gap;
// Recursively search for a fold that contains "lnum".
- gap = &wp->w_folds;
+ garray_T *gap = &wp->w_folds;
for (;;) {
if (!foldFind(gap, lnum_rel, &fp)) {
break;
@@ -1121,7 +1093,7 @@ static int foldLevelWin(win_T *wp, linenr_T lnum)
// Check nested folds. Line number is relative to containing fold.
gap = &fp->fd_nested;
lnum_rel -= fp->fd_top;
- ++level;
+ level++;
}
return level;
@@ -1142,11 +1114,8 @@ static void checkupdate(win_T *wp)
/// Repeat "count" times.
static void setFoldRepeat(pos_T pos, long count, int do_open)
{
- int done;
- long n;
-
- for (n = 0; n < count; ++n) {
- done = DONE_NOTHING;
+ for (int n = 0; n < count; n++) {
+ int done = DONE_NOTHING;
(void)setManualFold(pos, do_open, false, &done);
if (!(done & DONE_ACTION)) {
// Only give an error message when no fold could be opened.
@@ -1162,18 +1131,15 @@ static void setFoldRepeat(pos_T pos, long count, int do_open)
/// Open or close the fold in the current window which contains "lnum".
/// Also does this for other windows in diff mode when needed.
///
-/// @param opening TRUE when opening, FALSE when closing
-/// @param recurse TRUE when closing/opening recursive
+/// @param opening true when opening, false when closing
+/// @param recurse true when closing/opening recursive
static linenr_T setManualFold(pos_T pos, int opening, int recurse, int *donep)
{
- linenr_T lnum = pos.lnum;
if (foldmethodIsDiff(curwin) && curwin->w_p_scb) {
linenr_T dlnum;
- /*
- * Do the same operation in other windows in diff mode. Calculate the
- * line number from the diffs.
- */
+ // Do the same operation in other windows in diff mode. Calculate the
+ // line number from the diffs.
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp != curwin && foldmethodIsDiff(wp) && wp->w_p_scb) {
dlnum = diff_lnum_win(curwin->w_cursor.lnum, wp);
@@ -1184,7 +1150,7 @@ static linenr_T setManualFold(pos_T pos, int opening, int recurse, int *donep)
}
}
- return setManualFoldWin(curwin, lnum, opening, recurse, donep);
+ return setManualFoldWin(curwin, pos.lnum, opening, recurse, donep);
}
// setManualFoldWin() {{{2
@@ -1194,31 +1160,27 @@ static linenr_T setManualFold(pos_T pos, int opening, int recurse, int *donep)
/// When "donep" is NULL give an error message when no fold was found for
/// "lnum", but only if "wp" is "curwin".
///
-/// @param opening TRUE when opening, FALSE when closing
-/// @param recurse TRUE when closing/opening recursive
+/// @param opening true when opening, false when closing
+/// @param recurse true when closing/opening recursive
///
/// @return the line number of the next line that could be closed.
-/// It's only valid when "opening" is TRUE!
+/// It's only valid when "opening" is true!
static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recurse, int *donep)
{
fold_T *fp;
fold_T *fp2;
fold_T *found = NULL;
- int j;
int level = 0;
- int use_level = FALSE;
- int found_fold = FALSE;
- garray_T *gap;
+ bool use_level = false;
+ bool found_fold = false;
linenr_T next = MAXLNUM;
linenr_T off = 0;
int done = 0;
checkupdate(wp);
- /*
- * Find the fold, open or close it.
- */
- gap = &wp->w_folds;
+ // Find the fold, open or close it.
+ garray_T *gap = &wp->w_folds;
for (;;) {
if (!foldFind(gap, lnum, &fp)) {
// If there is a following fold, continue there next time.
@@ -1229,7 +1191,7 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu
}
// lnum is inside this fold
- found_fold = TRUE;
+ found_fold = true;
// If there is a following fold, continue there next time.
if (fp + 1 < (fold_T *)gap->ga_data + gap->ga_len) {
@@ -1238,14 +1200,14 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu
// Change from level-dependent folding to manual.
if (use_level || fp->fd_flags == FD_LEVEL) {
- use_level = TRUE;
+ use_level = true;
if (level >= wp->w_p_fdl) {
fp->fd_flags = FD_CLOSED;
} else {
fp->fd_flags = FD_OPEN;
}
fp2 = (fold_T *)fp->fd_nested.ga_data;
- for (j = 0; j < fp->fd_nested.ga_len; ++j) {
+ for (int j = 0; j < fp->fd_nested.ga_len; j++) {
fp2[j].fd_flags = FD_LEVEL;
}
}
@@ -1273,7 +1235,7 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu
gap = &fp->fd_nested;
lnum -= fp->fd_top;
off += fp->fd_top;
- ++level;
+ level++;
}
if (found_fold) {
// When closing and not recurse, close deepest open fold.
@@ -1301,10 +1263,8 @@ static linenr_T setManualFoldWin(win_T *wp, linenr_T lnum, int opening, int recu
/// Open all nested folds in fold "fpr" recursively.
static void foldOpenNested(fold_T *fpr)
{
- fold_T *fp;
-
- fp = (fold_T *)fpr->fd_nested.ga_data;
- for (int i = 0; i < fpr->fd_nested.ga_len; ++i) {
+ fold_T *fp = (fold_T *)fpr->fd_nested.ga_data;
+ for (int i = 0; i < fpr->fd_nested.ga_len; i++) {
foldOpenNested(&fp[i]);
fp[i].fd_flags = FD_OPEN;
}
@@ -1390,14 +1350,12 @@ void foldMarkAdjust(win_T *wp, linenr_T line1, linenr_T line2, linenr_T amount,
static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, linenr_T line2,
linenr_T amount, linenr_T amount_after)
{
- fold_T *fp;
- linenr_T last;
- linenr_T top;
-
if (gap->ga_len == 0) {
return;
}
+ linenr_T top;
+
// In Insert mode an inserted line at the top of a fold is considered part
// of the fold, otherwise it isn't.
if ((State & MODE_INSERT) && amount == (linenr_T)1 && line2 == MAXLNUM) {
@@ -1407,25 +1365,22 @@ static void foldMarkAdjustRecurse(win_T *wp, garray_T *gap, linenr_T line1, line
}
// Find the fold containing or just below "line1".
+ fold_T *fp;
(void)foldFind(gap, line1, &fp);
- /*
- * Adjust all folds below "line1" that are affected.
- */
- for (int i = (int)(fp - (fold_T *)gap->ga_data); i < gap->ga_len; ++i, ++fp) {
- /*
- * Check for these situations:
- * 1 2 3
- * 1 2 3
- * line1 2 3 4 5
- * 2 3 4 5
- * 2 3 4 5
- * line2 2 3 4 5
- * 3 5 6
- * 3 5 6
- */
-
- last = fp->fd_top + fp->fd_len - 1; // last line of fold
+ // Adjust all folds below "line1" that are affected.
+ for (int i = (int)(fp - (fold_T *)gap->ga_data); i < gap->ga_len; i++, fp++) {
+ // Check for these situations:
+ // 1 2 3
+ // 1 2 3
+ // line1 2 3 4 5
+ // 2 3 4 5
+ // 2 3 4 5
+ // line2 2 3 4 5
+ // 3 5 6
+ // 3 5 6
+
+ linenr_T last = fp->fd_top + fp->fd_len - 1; // last line of fold
// 1. fold completely above line1: nothing to do
if (last < line1) {
@@ -1498,13 +1453,11 @@ int getDeepestNesting(win_T *wp)
static int getDeepestNestingRecurse(garray_T *gap)
{
- int level;
int maxlevel = 0;
- fold_T *fp;
- fp = (fold_T *)gap->ga_data;
- for (int i = 0; i < gap->ga_len; ++i) {
- level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
+ fold_T *fp = (fold_T *)gap->ga_data;
+ for (int i = 0; i < gap->ga_len; i++) {
+ int level = getDeepestNestingRecurse(&fp[i].fd_nested) + 1;
if (level > maxlevel) {
maxlevel = level;
}
@@ -1622,14 +1575,13 @@ static void foldCreateMarkers(win_T *wp, pos_T start, pos_T end)
static void foldAddMarker(buf_T *buf, pos_T pos, const char_u *marker, size_t markerlen)
{
char_u *cms = buf->b_p_cms;
- char_u *line;
char_u *newline;
char_u *p = (char_u *)strstr((char *)buf->b_p_cms, "%s");
bool line_is_comment = false;
linenr_T lnum = pos.lnum;
// Allocate a new line: old-line + 'cms'-start + marker + 'cms'-end
- line = ml_get_buf(buf, lnum, false);
+ char_u *line = ml_get_buf(buf, lnum, false);
size_t line_len = STRLEN(line);
size_t added = 0;
@@ -1681,14 +1633,12 @@ static void deleteFoldMarkers(win_T *wp, fold_T *fp, int recursive, linenr_T lnu
/// close-marker.
static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t markerlen)
{
- char_u *newline;
- char_u *cms = buf->b_p_cms;
- char_u *cms2;
-
// end marker may be missing and fold extends below the last line
if (lnum > buf->b_ml.ml_line_count) {
return;
}
+
+ char_u *cms = buf->b_p_cms;
char_u *line = ml_get_buf(buf, lnum, false);
for (char_u *p = line; *p != NUL; p++) {
if (STRNCMP(p, marker, markerlen) != 0) {
@@ -1697,11 +1647,11 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark
// Found the marker, include a digit if it's there.
size_t len = markerlen;
if (ascii_isdigit(p[len])) {
- ++len;
+ len++;
}
if (*cms != NUL) {
// Also delete 'commentstring' if it matches.
- cms2 = (char_u *)strstr((char *)cms, "%s");
+ char_u *cms2 = (char_u *)strstr((char *)cms, "%s");
if (p - line >= cms2 - cms
&& STRNCMP(p - (cms2 - cms), cms, cms2 - cms) == 0
&& STRNCMP(p + len, cms2 + 2, STRLEN(cms2 + 2)) == 0) {
@@ -1711,7 +1661,7 @@ static void foldDelMarker(buf_T *buf, linenr_T lnum, char_u *marker, size_t mark
}
if (u_save(lnum - 1, lnum + 1) == OK) {
// Make new line: text-before-marker + text-after-marker
- newline = xmalloc(STRLEN(line) - len + 1);
+ char_u *newline = xmalloc(STRLEN(line) - len + 1);
assert(p >= line);
memcpy(newline, line, (size_t)(p - line));
STRCPY(newline + (p - line), p + len);
@@ -1737,26 +1687,23 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
{
char_u *text = NULL;
// an error occurred when evaluating 'fdt' setting
- static int got_fdt_error = FALSE;
+ static bool got_fdt_error = false;
int save_did_emsg = did_emsg;
static win_T *last_wp = NULL;
static linenr_T last_lnum = 0;
if (last_wp == NULL || last_wp != wp || last_lnum > lnum || last_lnum == 0) {
// window changed, try evaluating foldtext setting once again
- got_fdt_error = FALSE;
+ got_fdt_error = false;
}
if (!got_fdt_error) {
// a previous error should not abort evaluating 'foldexpr'
- did_emsg = FALSE;
+ did_emsg = false;
}
if (*wp->w_p_fdt != NUL) {
char dashes[MAX_LEVEL + 2];
- win_T *save_curwin;
- int level;
- char_u *p;
// Set "v:foldstart" and "v:foldend".
set_vim_var_nr(VV_FOLDSTART, (varnumber_T)lnum);
@@ -1764,7 +1711,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
// Set "v:folddashes" to a string of "level" dashes.
// Set "v:foldlevel" to "level".
- level = foldinfo.fi_level;
+ int level = foldinfo.fi_level;
if (level > (int)sizeof(dashes) - 1) {
level = (int)sizeof(dashes) - 1;
}
@@ -1775,7 +1722,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
// skip evaluating foldtext on errors
if (!got_fdt_error) {
- save_curwin = curwin;
+ win_T *save_curwin = curwin;
curwin = wp;
curbuf = wp->w_buffer;
@@ -1786,7 +1733,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
emsg_silent--;
if (text == NULL || did_emsg) {
- got_fdt_error = TRUE;
+ got_fdt_error = true;
}
curwin = save_curwin;
@@ -1803,6 +1750,7 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
if (text != NULL) {
// Replace unprintable characters, if there are any. But
// replace a TAB with a space.
+ char_u *p;
for (p = text; *p != NUL; p++) {
int len = utfc_ptr2len((char *)p);
@@ -1840,11 +1788,6 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
/// Remove 'foldmarker' and 'commentstring' from "str" (in-place).
void foldtext_cleanup(char_u *str)
{
- char_u *s;
- char_u *p;
- bool did1 = false;
- bool did2 = false;
-
// Ignore leading and trailing white space in 'commentstring'.
char_u *cms_start = (char_u *)skipwhite((char *)curbuf->b_p_cms);
size_t cms_slen = STRLEN(cms_start);
@@ -1865,13 +1808,16 @@ void foldtext_cleanup(char_u *str)
}
// skip "%s" and white space after it
- s = (char_u *)skipwhite((char *)cms_end + 2);
+ char_u *s = (char_u *)skipwhite((char *)cms_end + 2);
cms_elen -= (size_t)(s - cms_end);
cms_end = s;
}
parseMarker(curwin);
- for (s = str; *s != NUL;) {
+ bool did1 = false;
+ bool did2 = false;
+
+ for (char_u *s = str; *s != NUL;) {
size_t len = 0;
if (STRNCMP(s, curwin->w_p_fmr, foldstartmarkerlen) == 0) {
len = foldstartmarkerlen;
@@ -1880,11 +1826,12 @@ void foldtext_cleanup(char_u *str)
}
if (len > 0) {
if (ascii_isdigit(s[len])) {
- ++len;
+ len++;
}
// May remove 'commentstring' start. Useful when it's a double
// quote and we already removed a double quote.
+ char_u *p;
for (p = s; p > str && ascii_iswhite(p[-1]); p--) {}
if (p >= str + cms_slen
&& STRNCMP(p - cms_slen, cms_start, cms_slen) == 0) {
@@ -1903,7 +1850,7 @@ void foldtext_cleanup(char_u *str)
}
if (len != 0) {
while (ascii_iswhite(s[len])) {
- ++len;
+ len++;
}
STRMOVE(s, s + len);
} else {
@@ -1920,10 +1867,6 @@ void foldtext_cleanup(char_u *str)
/// IEMS = "Indent Expr Marker Syntax"
static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
{
- fline_T fline;
- LevelGetter getlevel = NULL;
- fold_T *fp;
-
// Avoid problems when being called recursively.
if (invalid_top != (linenr_T)0) {
return;
@@ -1955,6 +1898,8 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
top = wp->w_buffer->b_ml.ml_line_count;
}
+ fline_T fline;
+
fold_changed = false;
fline.wp = wp;
fline.off = 0;
@@ -1967,6 +1912,8 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
invalid_top = top;
invalid_bot = bot;
+ LevelGetter getlevel = NULL;
+
if (foldmethodIsMarker(wp)) {
getlevel = foldlevelMarker;
@@ -2032,13 +1979,11 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
}
}
- /*
- * If folding is defined by the syntax, it is possible that a change in
- * one line will cause all sub-folds of the current fold to change (e.g.,
- * closing a C-style comment can cause folds in the subsequent lines to
- * appear). To take that into account we should adjust the value of "bot"
- * to point to the end of the current fold:
- */
+ // If folding is defined by the syntax, it is possible that a change in
+ // one line will cause all sub-folds of the current fold to change (e.g.,
+ // closing a C-style comment can cause folds in the subsequent lines to
+ // appear). To take that into account we should adjust the value of "bot"
+ // to point to the end of the current fold:
if (foldlevelSyntax == getlevel) {
garray_T *gap = &wp->w_folds;
fold_T *fpn = NULL;
@@ -2050,7 +1995,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
if (!foldFind(gap, lnum_rel, &fpn)) {
break;
}
- ++current_fdl;
+ current_fdl++;
fold_start_lnum += fpn->fd_top;
gap = &fpn->fd_nested;
@@ -2071,6 +2016,9 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
if (start > end && end < wp->w_buffer->b_ml.ml_line_count) {
end = start;
}
+
+ fold_T *fp;
+
while (!got_int) {
// Always stop at the end of the file ("end" can be past the end of
// the file).
@@ -2115,7 +2063,7 @@ static void foldUpdateIEMS(win_T *const wp, linenr_T top, linenr_T bot)
if (fline.lnum == wp->w_buffer->b_ml.ml_line_count) {
break;
}
- ++fline.lnum;
+ fline.lnum++;
fline.lvl = fline.lvl_next;
getlevel(&fline);
}
@@ -2173,23 +2121,12 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
const linenr_T startlnum, fline_T *const flp,
LevelGetter getlevel, linenr_T bot, const char topflags)
{
- linenr_T ll;
fold_T *fp = NULL;
- fold_T *fp2;
- int lvl = level;
- linenr_T startlnum2 = startlnum;
- const linenr_T firstlnum = flp->lnum; // first lnum we got
- int i;
- bool finish = false;
- const linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off;
- int concat;
-
- /*
- * If using the marker method, the start line is not the start of a fold
- * at the level we're dealing with and the level is non-zero, we must use
- * the previous fold. But ignore a fold that starts at or below
- * startlnum, it must be deleted.
- */
+
+ // If using the marker method, the start line is not the start of a fold
+ // at the level we're dealing with and the level is non-zero, we must use
+ // the previous fold. But ignore a fold that starts at or below
+ // startlnum, it must be deleted.
if (getlevel == foldlevelMarker && flp->start <= flp->lvl - level
&& flp->lvl > 0) {
(void)foldFind(gap, startlnum - 1, &fp);
@@ -2200,17 +2137,22 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
}
}
- /*
- * Loop over all lines in this fold, or until "bot" is hit.
- * Handle nested folds inside of this fold.
- * "flp->lnum" is the current line. When finding the end of the fold, it
- * is just below the end of the fold.
- * "*flp" contains the level of the line "flp->lnum" or a following one if
- * there are lines with an invalid fold level. "flp->lnum_save" is the
- * line number that was used to get the fold level (below "flp->lnum" when
- * it has an invalid fold level). When called the fold level is always
- * valid, thus "flp->lnum_save" is equal to "flp->lnum".
- */
+ fold_T *fp2;
+ int lvl = level;
+ linenr_T startlnum2 = startlnum;
+ const linenr_T firstlnum = flp->lnum; // first lnum we got
+ bool finish = false;
+ const linenr_T linecount = flp->wp->w_buffer->b_ml.ml_line_count - flp->off;
+
+ // Loop over all lines in this fold, or until "bot" is hit.
+ // Handle nested folds inside of this fold.
+ // "flp->lnum" is the current line. When finding the end of the fold, it
+ // is just below the end of the fold.
+ // "*flp" contains the level of the line "flp->lnum" or a following one if
+ // there are lines with an invalid fold level. "flp->lnum_save" is the
+ // line number that was used to get the fold level (below "flp->lnum" when
+ // it has an invalid fold level). When called the fold level is always
+ // valid, thus "flp->lnum_save" is equal to "flp->lnum".
flp->lnum_save = flp->lnum;
while (!got_int) {
// Updating folds can be slow, check for CTRL-C.
@@ -2240,15 +2182,15 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
&& getlevel != foldlevelSyntax) {
break;
}
- i = 0;
+ int i = 0;
fp2 = fp;
if (lvl >= level) {
// Compute how deep the folds currently are, if it's deeper
// than "lvl" then some must be deleted, need to update
// at least one nested fold.
- ll = flp->lnum - fp->fd_top;
+ int ll = flp->lnum - fp->fd_top;
while (foldFind(&fp2->fd_nested, ll, &fp2)) {
- ++i;
+ i++;
ll -= fp2->fd_top;
}
}
@@ -2273,13 +2215,12 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
|| flp->start != 0
|| flp->had_end <= MAX_LEVEL
|| flp->lnum == linecount)) {
- /*
- * Remove or update folds that have lines between startlnum and
- * firstlnum.
- */
+ // Remove or update folds that have lines between startlnum and
+ // firstlnum.
while (!got_int) {
// set concat to 1 if it's allowed to concatenate this fold
// with a previous one that touches it.
+ int concat;
if (flp->start != 0 || flp->had_end <= MAX_LEVEL) {
concat = 0;
} else {
@@ -2347,7 +2288,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
}
foldRemove(flp->wp, &fp->fd_nested, breakstart - fp->fd_top,
breakend - fp->fd_top);
- i = (int)(fp - (fold_T *)gap->ga_data);
+ int i = (int)(fp - (fold_T *)gap->ga_data);
foldSplit(flp->wp->w_buffer, gap, i, breakstart, breakend - 1);
fp = (fold_T *)gap->ga_data + i + 1;
// If using the "marker" or "syntax" method, we
@@ -2360,7 +2301,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
}
}
if (fp->fd_top == startlnum && concat) {
- i = (int)(fp - (fold_T *)gap->ga_data);
+ int i = (int)(fp - (fold_T *)gap->ga_data);
if (i != 0) {
fp2 = fp - 1;
if (fp2->fd_top + fp2->fd_len == fp->fd_top) {
@@ -2389,6 +2330,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
} else {
// Insert new fold. Careful: ga_data may be NULL and it
// may change!
+ int i;
if (gap->ga_len == 0) {
i = 0;
} else {
@@ -2429,17 +2371,13 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
}
if (lvl < level || flp->lnum > linecount) {
- /*
- * Found a line with a lower foldlevel, this fold ends just above
- * "flp->lnum".
- */
+ // Found a line with a lower foldlevel, this fold ends just above
+ // "flp->lnum".
break;
}
- /*
- * The fold includes the line "flp->lnum" and "flp->lnum_save".
- * Check "fp" for safety.
- */
+ // The fold includes the line "flp->lnum" and "flp->lnum_save".
+ // Check "fp" for safety.
if (lvl > level && fp != NULL) {
// There is a nested fold, handle it recursively.
// At least do one line (can happen when finish is true).
@@ -2451,7 +2389,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
// this fold.
flp->lnum = flp->lnum_save - fp->fd_top;
flp->off += fp->fd_top;
- i = (int)(fp - (fold_T *)gap->ga_data);
+ int i = (int)(fp - (fold_T *)gap->ga_data);
bot = foldUpdateIEMSRecurse(&fp->fd_nested, level + 1,
startlnum2 - fp->fd_top, flp, getlevel,
bot - fp->fd_top, fp->fd_flags);
@@ -2464,14 +2402,12 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
// This fold may end at the same line, don't incr. flp->lnum.
} else {
- /*
- * Get the level of the next line, then continue the loop to check
- * if it ends there.
- * Skip over undefined lines, to find the foldlevel after it.
- * For the last line in the file the foldlevel is always valid.
- */
+ // Get the level of the next line, then continue the loop to check
+ // if it ends there.
+ // Skip over undefined lines, to find the foldlevel after it.
+ // For the last line in the file the foldlevel is always valid.
flp->lnum = flp->lnum_save;
- ll = flp->lnum + 1;
+ int ll = flp->lnum + 1;
while (!got_int) {
// Make the previous level available to foldlevel().
prev_lnum = flp->lnum;
@@ -2502,11 +2438,9 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
return bot;
}
- /*
- * Get here when:
- * lvl < level: the folds ends just above "flp->lnum"
- * lvl >= level: fold continues below "bot"
- */
+ // Get here when:
+ // lvl < level: the folds ends just above "flp->lnum"
+ // lvl >= level: fold continues below "bot"
// Current fold at least extends until lnum.
if (fp->fd_len < flp->lnum - fp->fd_top) {
@@ -2538,7 +2472,7 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
} else {
// indent or expr method: split fold to create a new one
// below bot
- i = (int)(fp - (fold_T *)gap->ga_data);
+ int i = (int)(fp - (fold_T *)gap->ga_data);
foldSplit(flp->wp->w_buffer, gap, i, flp->lnum, bot);
fp = (fold_T *)gap->ga_data + i;
}
@@ -2590,11 +2524,9 @@ static linenr_T foldUpdateIEMSRecurse(garray_T *const gap, const int level,
/// Insert a new fold in "gap" at position "i".
static void foldInsert(garray_T *gap, int i)
{
- fold_T *fp;
-
ga_grow(gap, 1);
- fp = (fold_T *)gap->ga_data + i;
+ fold_T *fp = (fold_T *)gap->ga_data + i;
if (gap->ga_len > 0 && i < gap->ga_len) {
memmove(fp + 1, fp, sizeof(fold_T) * (size_t)(gap->ga_len - i));
}
@@ -2666,12 +2598,12 @@ static void foldSplit(buf_T *buf, garray_T *const gap, const int i, const linenr
/// 6: not changed
static void foldRemove(win_T *const wp, garray_T *gap, linenr_T top, linenr_T bot)
{
- fold_T *fp = NULL;
-
if (bot < top) {
return; // nothing to do
}
+ fold_T *fp = NULL;
+
while (gap->ga_len > 0) {
// Find fold that includes top or a following one.
if (foldFind(gap, top, &fp) && fp->fd_top < top) {
@@ -2881,7 +2813,6 @@ static void foldMerge(win_T *const wp, fold_T *fp1, garray_T *gap, fold_T *fp2)
{
fold_T *fp3;
fold_T *fp4;
- int idx;
garray_T *gap1 = &fp1->fd_nested;
garray_T *gap2 = &fp2->fd_nested;
@@ -2894,11 +2825,11 @@ static void foldMerge(win_T *const wp, fold_T *fp1, garray_T *gap, fold_T *fp2)
// Move nested folds in fp2 to the end of fp1.
if (!GA_EMPTY(gap2)) {
ga_grow(gap1, gap2->ga_len);
- for (idx = 0; idx < gap2->ga_len; ++idx) {
+ for (int idx = 0; idx < gap2->ga_len; idx++) {
((fold_T *)gap1->ga_data)[gap1->ga_len]
= ((fold_T *)gap2->ga_data)[idx];
((fold_T *)gap1->ga_data)[gap1->ga_len].fd_top += fp1->fd_len;
- ++gap1->ga_len;
+ gap1->ga_len++;
}
gap2->ga_len = 0;
}
@@ -2915,12 +2846,10 @@ static void foldMerge(win_T *const wp, fold_T *fp1, garray_T *gap, fold_T *fp2)
/// @return a level of -1 if the foldlevel depends on surrounding lines.
static void foldlevelIndent(fline_T *flp)
{
- char_u *s;
- buf_T *buf;
linenr_T lnum = flp->lnum + flp->off;
- buf = flp->wp->w_buffer;
- s = (char_u *)skipwhite((char *)ml_get_buf(buf, lnum, false));
+ buf_T *buf = flp->wp->w_buffer;
+ char_u *s = (char_u *)skipwhite((char *)ml_get_buf(buf, lnum, false));
// empty line or lines starting with a character in 'foldignore': level
// depends on surrounding lines
@@ -2958,11 +2887,9 @@ static void foldlevelDiff(fline_T *flp)
/// @return a level of -1 if the foldlevel depends on surrounding lines.
static void foldlevelExpr(fline_T *flp)
{
- win_T *win;
- int c;
linenr_T lnum = flp->lnum + flp->off;
- win = curwin;
+ win_T *win = curwin;
curwin = flp->wp;
curbuf = flp->wp->w_buffer;
set_vim_var_nr(VV_LNUM, (varnumber_T)lnum);
@@ -2977,6 +2904,8 @@ static void foldlevelExpr(fline_T *flp)
// KeyTyped may be reset to 0 when calling a function which invokes
// do_cmdline(). To make 'foldopen' work correctly restore KeyTyped.
const bool save_keytyped = KeyTyped;
+
+ int c;
const int n = eval_foldexpr((char *)flp->wp->w_p_fde, &c);
KeyTyped = save_keytyped;
@@ -3070,31 +2999,26 @@ static void parseMarker(win_T *wp)
/// Sets flp->start when a start marker was found.
static void foldlevelMarker(fline_T *flp)
{
- char_u *startmarker;
- int cstart;
- int cend;
int start_lvl = flp->lvl;
- char_u *s;
- int n;
// cache a few values for speed
- startmarker = flp->wp->w_p_fmr;
- cstart = *startmarker;
- ++startmarker;
- cend = *foldendmarker;
+ char_u *startmarker = flp->wp->w_p_fmr;
+ int cstart = *startmarker;
+ startmarker++;
+ int cend = *foldendmarker;
// Default: no start found, next level is same as current level
flp->start = 0;
flp->lvl_next = flp->lvl;
- s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
+ char_u *s = ml_get_buf(flp->wp->w_buffer, flp->lnum + flp->off, false);
while (*s) {
if (*s == cstart
&& STRNCMP(s + 1, startmarker, foldstartmarkerlen - 1) == 0) {
// found startmarker: set flp->lvl
s += foldstartmarkerlen;
if (ascii_isdigit(*s)) {
- n = atoi((char *)s);
+ int n = atoi((char *)s);
if (n > 0) {
flp->lvl = n;
flp->lvl_next = n;
@@ -3105,16 +3029,16 @@ static void foldlevelMarker(fline_T *flp)
}
}
} else {
- ++flp->lvl;
- ++flp->lvl_next;
- ++flp->start;
+ flp->lvl++;
+ flp->lvl_next++;
+ flp->start++;
}
} else if (*s == cend && STRNCMP(s + 1, foldendmarker + 1,
foldendmarkerlen - 1) == 0) {
// found endmarker: set flp->lvl_next
s += foldendmarkerlen;
if (ascii_isdigit(*s)) {
- n = atoi((char *)s);
+ int n = atoi((char *)s);
if (n > 0) {
flp->lvl = n;
flp->lvl_next = n - 1;
@@ -3143,13 +3067,12 @@ static void foldlevelMarker(fline_T *flp)
static void foldlevelSyntax(fline_T *flp)
{
linenr_T lnum = flp->lnum + flp->off;
- int n;
// Use the maximum fold level at the start of this line and the next.
flp->lvl = syn_get_foldlevel(flp->wp, lnum);
flp->start = 0;
if (lnum < flp->wp->w_buffer->b_ml.ml_line_count) {
- n = syn_get_foldlevel(flp->wp, lnum + 1);
+ int n = syn_get_foldlevel(flp->wp, lnum + 1);
if (n > flp->lvl) {
flp->start = n - flp->lvl; // fold(s) start here
flp->lvl = n;
@@ -3198,7 +3121,7 @@ static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off)
|| put_eol(fd) == FAIL) {
return FAIL;
}
- ++fp;
+ fp++;
}
return OK;
}
@@ -3209,8 +3132,6 @@ static int put_folds_recurse(FILE *fd, garray_T *gap, linenr_T off)
/// @return FAIL when writing failed.
static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off)
{
- int level;
-
fold_T *fp = (fold_T *)gap->ga_data;
for (int i = 0; i < gap->ga_len; i++) {
if (fp->fd_flags != FD_LEVEL) {
@@ -3236,7 +3157,7 @@ static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off
// Open or close the leaf according to the window foldlevel.
// Do not close a leaf that is already closed, as it will close
// the parent.
- level = foldLevelWin(wp, off + fp->fd_top);
+ int level = foldLevelWin(wp, off + fp->fd_top);
if ((fp->fd_flags == FD_CLOSED && wp->w_p_fdl >= level)
|| (fp->fd_flags != FD_CLOSED && wp->w_p_fdl < level)) {
if (put_fold_open_close(fd, fp, off) == FAIL) {
@@ -3245,7 +3166,7 @@ static int put_foldopen_recurse(FILE *fd, win_T *wp, garray_T *gap, linenr_T off
}
}
}
- ++fp;
+ fp++;
}
return OK;
diff --git a/src/nvim/globals.h b/src/nvim/globals.h
index d2f56c739b..5c1d6867ce 100644
--- a/src/nvim/globals.h
+++ b/src/nvim/globals.h
@@ -224,7 +224,7 @@ EXTERN dict_T vimvardict; // Dictionary with v: variables
EXTERN dict_T globvardict; // Dictionary with g: variables
/// g: value
#define globvarht globvardict.dv_hashtab
-EXTERN int did_emsg; // set by emsg() when the message
+EXTERN bool did_emsg; // set by emsg() when the message
// is displayed or thrown
EXTERN bool called_vim_beep; // set if vim_beep() is called
EXTERN bool did_emsg_syntax; // did_emsg set because of a
@@ -274,11 +274,11 @@ EXTERN except_T *current_exception;
/// Set when a throw that cannot be handled in do_cmdline() must be propagated
/// to the cstack of the previously called do_cmdline().
-EXTERN int need_rethrow INIT(= false);
+EXTERN bool need_rethrow INIT(= false);
/// Set when a ":finish" or ":return" that cannot be handled in do_cmdline()
/// must be propagated to the cstack of the previously called do_cmdline().
-EXTERN int check_cstack INIT(= false);
+EXTERN bool check_cstack INIT(= false);
/// Number of nested try conditionals (across function calls and ":source"
/// commands).
@@ -725,8 +725,7 @@ EXTERN bool need_highlight_changed INIT(= true);
EXTERN FILE *scriptout INIT(= NULL); ///< Stream to write script to.
// volatile because it is used in a signal handler.
-EXTERN volatile int got_int INIT(= false); // set to true when interrupt
- // signal occurred
+EXTERN bool got_int INIT(= false); // set to true when interrupt signal occurred
EXTERN bool bangredo INIT(= false); // set to true with ! command
EXTERN int searchcmdlen; // length of previous search cmd
EXTERN int reg_do_extmatch INIT(= 0); // Used when compiling regexp:
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 0cd323c234..7da8ccd0cb 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -652,7 +652,7 @@ static bool emsg_multiline(const char *s, bool multiline)
// interrupt message).
if (cause_errthrow(s, severe, &ignore)) {
if (!ignore) {
- did_emsg++;
+ did_emsg = true;
}
return true;
}
@@ -717,7 +717,7 @@ static bool emsg_multiline(const char *s, bool multiline)
} else {
flush_buffers(FLUSH_MINIMAL); // flush internal buffers
}
- did_emsg++; // flag for DoOneCmd()
+ did_emsg = true; // flag for DoOneCmd()
}
emsg_on_display = true; // remember there is an error message