refactor: format with uncrustify #15741

This commit is contained in:
dundargoc
2021-09-22 15:25:38 +02:00
committed by GitHub
parent fb6f27e86f
commit 48e67b2294
13 changed files with 2654 additions and 2393 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -8,20 +8,18 @@
// khash.h does not make its own copy of the key or value. // khash.h does not make its own copy of the key or value.
// //
#include <stdlib.h> #include <lauxlib.h>
#include <lua.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <lua.h> #include "nvim/api/private/dispatch.h"
#include <lauxlib.h> #include "nvim/lib/khash.h"
#include "nvim/map.h" #include "nvim/map.h"
#include "nvim/map_defs.h" #include "nvim/map_defs.h"
#include "nvim/vim.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/api/private/dispatch.h" #include "nvim/vim.h"
#include "nvim/lib/khash.h"
#define cstr_t_hash kh_str_hash_func #define cstr_t_hash kh_str_hash_func
#define cstr_t_eq kh_str_hash_equal #define cstr_t_eq kh_str_hash_equal
@@ -52,7 +50,7 @@
#define MAP_IMPL(T, U, ...) \ #define MAP_IMPL(T, U, ...) \
INITIALIZER_DECLARE(T, U, __VA_ARGS__); \ INITIALIZER_DECLARE(T, U, __VA_ARGS__); \
__KHASH_IMPL(T##_##U##_map,, T, U, 1, T##_hash, T##_eq) \ __KHASH_IMPL(T##_##U##_map, , T, U, 1, T##_hash, T##_eq) \
\ \
void map_##T##_##U##_destroy(Map(T, U) *map) \ void map_##T##_##U##_destroy(Map(T, U) *map) \
{ \ { \

File diff suppressed because it is too large Load Diff

View File

@@ -49,9 +49,9 @@
#include <assert.h> #include <assert.h>
#include "nvim/marktree.h"
#include "nvim/lib/kvec.h"
#include "nvim/garray.h" #include "nvim/garray.h"
#include "nvim/lib/kvec.h"
#include "nvim/marktree.h"
#define T MT_BRANCH_FACTOR #define T MT_BRANCH_FACTOR
#define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *)) #define ILEN (sizeof(mtnode_t)+(2 * T) * sizeof(void *))
@@ -137,7 +137,9 @@ static inline int marktree_getp_aux(const mtnode_t *x, mtkey_t k, int *r)
end = mid; end = mid;
} }
} }
if (begin == x->n) { *rr = 1; return x->n - 1; } if (begin == x->n) {
*rr = 1; return x->n - 1;
}
if ((*rr = key_cmp(k, x->key[begin])) < 0) { if ((*rr = key_cmp(k, x->key[begin])) < 0) {
begin--; begin--;
} }
@@ -232,9 +234,8 @@ uint64_t marktree_put(MarkTree *b, int row, int col, bool right_gravity)
return id; return id;
} }
uint64_t marktree_put_pair(MarkTree *b, uint64_t marktree_put_pair(MarkTree *b, int start_row, int start_col, bool start_right, int end_row,
int start_row, int start_col, bool start_right, int end_col, bool end_right)
int end_row, int end_col, bool end_right)
{ {
uint64_t id = (b->next_id+=ID_INCR)|PAIRED; uint64_t id = (b->next_id+=ID_INCR)|PAIRED;
uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0); uint64_t start_id = id|(start_right?RIGHT_GRAVITY:0);
@@ -594,8 +595,8 @@ bool marktree_itr_get(MarkTree *b, int row, int col, MarkTreeIter *itr)
itr, false, false, NULL); itr, false, false, NULL);
} }
bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool marktree_itr_get_ext(MarkTree *b, mtpos_t p, MarkTreeIter *itr, bool last, bool gravity,
bool last, bool gravity, mtpos_t *oldbase) mtpos_t *oldbase)
{ {
mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 }; mtkey_t k = { .pos = p, .id = gravity ? RIGHT_GRAVITY : 0 };
if (last && !gravity) { if (last && !gravity) {
@@ -695,8 +696,7 @@ bool marktree_itr_next(MarkTree *b, MarkTreeIter *itr)
return marktree_itr_next_skip(b, itr, false, NULL); return marktree_itr_next_skip(b, itr, false, NULL);
} }
static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, static bool marktree_itr_next_skip(MarkTree *b, MarkTreeIter *itr, bool skip, mtpos_t oldbase[])
mtpos_t oldbase[])
{ {
if (!itr->node) { if (!itr->node) {
return false; return false;
@@ -819,8 +819,8 @@ mtmark_t marktree_itr_current(MarkTreeIter *itr)
mtpos_t pos = marktree_itr_pos(itr); mtpos_t pos = marktree_itr_pos(itr);
mtmark_t mark = { .row = pos.row, mtmark_t mark = { .row = pos.row,
.col = pos.col, .col = pos.col,
.id = ANTIGRAVITY(keyid), .id = ANTIGRAVITY(keyid),
.right_gravity = keyid & RIGHT_GRAVITY }; .right_gravity = keyid & RIGHT_GRAVITY };
return mark; return mark;
} }
return (mtmark_t){ -1, -1, 0, false }; return (mtmark_t){ -1, -1, 0, false };
@@ -833,10 +833,8 @@ static void swap_id(uint64_t *id1, uint64_t *id2)
*id2 = temp; *id2 = temp;
} }
bool marktree_splice(MarkTree *b, bool marktree_splice(MarkTree *b, int start_line, int start_col, int old_extent_line,
int start_line, int start_col, int old_extent_col, int new_extent_line, int new_extent_col)
int old_extent_line, int old_extent_col,
int new_extent_line, int new_extent_col)
{ {
mtpos_t start = { start_line, start_col }; mtpos_t start = { start_line, start_col };
mtpos_t old_extent = { (int)old_extent_line, old_extent_col }; mtpos_t old_extent = { (int)old_extent_line, old_extent_col };
@@ -903,7 +901,7 @@ continue_same_node:
refkey(b, itr->node, itr->i); refkey(b, itr->node, itr->i);
refkey(b, enditr->node, enditr->i); refkey(b, enditr->node, enditr->i);
} else { } else {
past_right = true; // NOLINT past_right = true; // NOLINT
(void)past_right; (void)past_right;
break; break;
} }
@@ -994,10 +992,8 @@ past_continue_same_node:
return moved; return moved;
} }
void marktree_move_region(MarkTree *b, void marktree_move_region(MarkTree *b, int start_row, colnr_T start_col, int extent_row,
int start_row, colnr_T start_col, colnr_T extent_col, int new_row, colnr_T new_col)
int extent_row, colnr_T extent_col,
int new_row, colnr_T new_col)
{ {
mtpos_t start = { start_row, start_col }, size = { extent_row, extent_col }; mtpos_t start = { start_row, start_col }, size = { extent_row, extent_col };
mtpos_t end = size; mtpos_t end = size;
@@ -1114,8 +1110,7 @@ void marktree_check(MarkTree *b)
} }
#ifndef NDEBUG #ifndef NDEBUG
static size_t check_node(MarkTree *b, mtnode_t *x, static size_t check_node(MarkTree *b, mtnode_t *x, mtpos_t *last, bool *last_right)
mtpos_t *last, bool *last_right)
{ {
assert(x->n <= 2 * T - 1); assert(x->n <= 2 * T - 1);
// TODO(bfredl): too strict if checking "in repair" post-delete tree. // TODO(bfredl): too strict if checking "in repair" post-delete tree.

View File

@@ -2,6 +2,7 @@
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
#include <math.h> #include <math.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@@ -21,9 +22,12 @@ int xfpclassify(double d)
m = 0xfffffffffffffULL & m; m = 0xfffffffffffffULL & m;
switch (e) { switch (e) {
default: return FP_NORMAL; default:
case 0x000: return m ? FP_SUBNORMAL : FP_ZERO; return FP_NORMAL;
case 0x7ff: return m ? FP_NAN : FP_INFINITE; case 0x000:
return m ? FP_SUBNORMAL : FP_ZERO;
case 0x7ff:
return m ? FP_NAN : FP_INFINITE;
} }
} }
int xisinf(double d) int xisinf(double d)

View File

@@ -39,24 +39,24 @@
/// mf_fullname() make file name full path (use before first :cd) /// mf_fullname() make file name full path (use before first :cd)
#include <assert.h> #include <assert.h>
#include <fcntl.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h> #include <limits.h>
#include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <fcntl.h> #include <string.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/memfile.h" #include "nvim/assert.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/memfile.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/message.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/assert.h" #include "nvim/vim.h"
#include "nvim/os/os.h"
#include "nvim/os/input.h"
#define MEMFILE_PAGE_SIZE 4096 /// default page size #define MEMFILE_PAGE_SIZE 4096 /// default page size
@@ -168,7 +168,7 @@ void mf_close(memfile_T *mfp, bool del_file)
return; return;
} }
if (mfp->mf_fd >= 0 && close(mfp->mf_fd) < 0) { if (mfp->mf_fd >= 0 && close(mfp->mf_fd) < 0) {
EMSG(_(e_swapclose)); EMSG(_(e_swapclose));
} }
if (del_file && mfp->mf_fname != NULL) { if (del_file && mfp->mf_fname != NULL) {
os_remove((char *)mfp->mf_fname); os_remove((char *)mfp->mf_fname);
@@ -282,14 +282,16 @@ bhdr_T *mf_new(memfile_T *mfp, bool negative, unsigned page_count)
bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count) bhdr_T *mf_get(memfile_T *mfp, blocknr_T nr, unsigned page_count)
{ {
// check block number exists // check block number exists
if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) if (nr >= mfp->mf_blocknr_max || nr <= mfp->mf_blocknr_min) {
return NULL; return NULL;
}
// see if it is in the cache // see if it is in the cache
bhdr_T *hp = mf_find_hash(mfp, nr); bhdr_T *hp = mf_find_hash(mfp, nr);
if (hp == NULL) { // not in the hash list if (hp == NULL) { // not in the hash list
if (nr < 0 || nr >= mfp->mf_infile_count) // can't be in the file if (nr < 0 || nr >= mfp->mf_infile_count) { // can't be in the file
return NULL; return NULL;
}
// could check here if the block is in the free list // could check here if the block is in the free list
@@ -331,8 +333,9 @@ void mf_put(memfile_T *mfp, bhdr_T *hp, bool dirty, bool infile)
mfp->mf_dirty = true; mfp->mf_dirty = true;
} }
hp->bh_flags = flags; hp->bh_flags = flags;
if (infile) if (infile) {
mf_trans_add(mfp, hp); // may translate negative in positive nr mf_trans_add(mfp, hp); // may translate negative in positive nr
}
} }
/// Signal block as no longer used (may put it in the free list). /// Signal block as no longer used (may put it in the free list).
@@ -381,32 +384,38 @@ int mf_sync(memfile_T *mfp, int flags)
// fails then we give up. // fails then we give up.
int status = OK; int status = OK;
bhdr_T *hp; bhdr_T *hp;
for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) for (hp = mfp->mf_used_last; hp != NULL; hp = hp->bh_prev) {
if (((flags & MFS_ALL) || hp->bh_bnum >= 0) if (((flags & MFS_ALL) || hp->bh_bnum >= 0)
&& (hp->bh_flags & BH_DIRTY) && (hp->bh_flags & BH_DIRTY)
&& (status == OK || (hp->bh_bnum >= 0 && (status == OK || (hp->bh_bnum >= 0
&& hp->bh_bnum < mfp->mf_infile_count))) { && hp->bh_bnum < mfp->mf_infile_count))) {
if ((flags & MFS_ZERO) && hp->bh_bnum != 0) if ((flags & MFS_ZERO) && hp->bh_bnum != 0) {
continue; continue;
}
if (mf_write(mfp, hp) == FAIL) { if (mf_write(mfp, hp) == FAIL) {
if (status == FAIL) // double error: quit syncing if (status == FAIL) { // double error: quit syncing
break; break;
}
status = FAIL; status = FAIL;
} }
if (flags & MFS_STOP) { // Stop when char available now. if (flags & MFS_STOP) { // Stop when char available now.
if (os_char_avail()) if (os_char_avail()) {
break; break;
}
} else { } else {
os_breakcheck(); os_breakcheck();
} }
if (got_int) if (got_int) {
break; break;
}
} }
}
// If the whole list is flushed, the memfile is not dirty anymore. // If the whole list is flushed, the memfile is not dirty anymore.
// In case of an error, dirty flag is also set, to avoid trying all the time. // In case of an error, dirty flag is also set, to avoid trying all the time.
if (hp == NULL || status == FAIL) if (hp == NULL || status == FAIL) {
mfp->mf_dirty = false; mfp->mf_dirty = false;
}
if (flags & MFS_FLUSH) { if (flags & MFS_FLUSH) {
if (os_fsync(mfp->mf_fd)) { if (os_fsync(mfp->mf_fd)) {
@@ -465,15 +474,17 @@ static void mf_ins_used(memfile_T *mfp, bhdr_T *hp)
/// Remove block from memfile's used list. /// Remove block from memfile's used list.
static void mf_rem_used(memfile_T *mfp, bhdr_T *hp) static void mf_rem_used(memfile_T *mfp, bhdr_T *hp)
{ {
if (hp->bh_next == NULL) // last block in used list if (hp->bh_next == NULL) { // last block in used list
mfp->mf_used_last = hp->bh_prev; mfp->mf_used_last = hp->bh_prev;
else } else {
hp->bh_next->bh_prev = hp->bh_prev; hp->bh_next->bh_prev = hp->bh_prev;
}
if (hp->bh_prev == NULL) // first block in used list if (hp->bh_prev == NULL) { // first block in used list
mfp->mf_used_first = hp->bh_next; mfp->mf_used_first = hp->bh_next;
else } else {
hp->bh_prev->bh_next = hp->bh_next; hp->bh_prev->bh_next = hp->bh_next;
}
} }
/// Release as many blocks as possible. /// Release as many blocks as possible.
@@ -554,8 +565,9 @@ static bhdr_T *mf_rem_free(memfile_T *mfp)
/// - Error reading file. /// - Error reading file.
static int mf_read(memfile_T *mfp, bhdr_T *hp) static int mf_read(memfile_T *mfp, bhdr_T *hp)
{ {
if (mfp->mf_fd < 0) // there is no file, can't read if (mfp->mf_fd < 0) { // there is no file, can't read
return FAIL; return FAIL;
}
unsigned page_size = mfp->mf_page_size; unsigned page_size = mfp->mf_page_size;
// TODO(elmart): Check (page_size * hp->bh_bnum) within off_T bounds. // TODO(elmart): Check (page_size * hp->bh_bnum) within off_T bounds.
@@ -592,12 +604,15 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
unsigned page_count; // number of pages written unsigned page_count; // number of pages written
unsigned size; // number of bytes written unsigned size; // number of bytes written
if (mfp->mf_fd < 0) // there is no file, can't write if (mfp->mf_fd < 0) { // there is no file, can't write
return FAIL; return FAIL;
}
if (hp->bh_bnum < 0) // must assign file block number if (hp->bh_bnum < 0) { // must assign file block number
if (mf_trans_add(mfp, hp) == FAIL) if (mf_trans_add(mfp, hp) == FAIL) {
return FAIL; return FAIL;
}
}
page_size = mfp->mf_page_size; page_size = mfp->mf_page_size;
@@ -620,10 +635,11 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
PERROR(_("E296: Seek error in swap file write")); PERROR(_("E296: Seek error in swap file write"));
return FAIL; return FAIL;
} }
if (hp2 == NULL) // freed block, fill with dummy data if (hp2 == NULL) { // freed block, fill with dummy data
page_count = 1; page_count = 1;
else } else {
page_count = hp2->bh_page_count; page_count = hp2->bh_page_count;
}
size = page_size * page_count; size = page_size * page_count;
void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data; void *data = (hp2 == NULL) ? hp->bh_data : hp2->bh_data;
if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) { if ((unsigned)write_eintr(mfp->mf_fd, data, size) != size) {
@@ -631,18 +647,22 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// disk is full. We give the message again only after a successful /// disk is full. We give the message again only after a successful
/// write or when hitting a key. We keep on trying, in case some /// write or when hitting a key. We keep on trying, in case some
/// space becomes available. /// space becomes available.
if (!did_swapwrite_msg) if (!did_swapwrite_msg) {
EMSG(_("E297: Write error in swap file")); EMSG(_("E297: Write error in swap file"));
}
did_swapwrite_msg = true; did_swapwrite_msg = true;
return FAIL; return FAIL;
} }
did_swapwrite_msg = false; did_swapwrite_msg = false;
if (hp2 != NULL) // written a non-dummy block if (hp2 != NULL) { // written a non-dummy block
hp2->bh_flags &= ~BH_DIRTY; hp2->bh_flags &= ~BH_DIRTY;
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) // appended to file }
if (nr + (blocknr_T)page_count > mfp->mf_infile_count) { // appended to file
mfp->mf_infile_count = nr + page_count; mfp->mf_infile_count = nr + page_count;
if (nr == hp->bh_bnum) // written the desired block }
if (nr == hp->bh_bnum) { // written the desired block
break; break;
}
} }
return OK; return OK;
} }
@@ -653,8 +673,9 @@ static int mf_write(memfile_T *mfp, bhdr_T *hp)
/// FAIL On failure. /// FAIL On failure.
static int mf_trans_add(memfile_T *mfp, bhdr_T *hp) static int mf_trans_add(memfile_T *mfp, bhdr_T *hp)
{ {
if (hp->bh_bnum >= 0) // it's already positive if (hp->bh_bnum >= 0) { // it's already positive
return OK; return OK;
}
mf_blocknr_trans_item_T *np = xmalloc(sizeof(mf_blocknr_trans_item_T)); mf_blocknr_trans_item_T *np = xmalloc(sizeof(mf_blocknr_trans_item_T));
@@ -702,8 +723,9 @@ blocknr_T mf_trans_del(memfile_T *mfp, blocknr_T old_nr)
mf_blocknr_trans_item_T *np = mf_blocknr_trans_item_T *np =
(mf_blocknr_trans_item_T *)mf_hash_find(&mfp->mf_trans, old_nr); (mf_blocknr_trans_item_T *)mf_hash_find(&mfp->mf_trans, old_nr);
if (np == NULL) // not found if (np == NULL) { // not found
return old_nr; return old_nr;
}
mfp->mf_neg_count--; mfp->mf_neg_count--;
blocknr_T new_bnum = np->nt_new_bnum; blocknr_T new_bnum = np->nt_new_bnum;
@@ -834,8 +856,9 @@ static void mf_hash_free_all(mf_hashtab_T *mht)
static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key) static mf_hashitem_T *mf_hash_find(mf_hashtab_T *mht, blocknr_T key)
{ {
mf_hashitem_T *mhi = mht->mht_buckets[(size_t)key & mht->mht_mask]; mf_hashitem_T *mhi = mht->mht_buckets[(size_t)key & mht->mht_mask];
while (mhi != NULL && mhi->mhi_key != key) while (mhi != NULL && mhi->mhi_key != key) {
mhi = mhi->mhi_next; mhi = mhi->mhi_next;
}
return mhi; return mhi;
} }
@@ -845,8 +868,9 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
size_t idx = (size_t)mhi->mhi_key & mht->mht_mask; size_t idx = (size_t)mhi->mhi_key & mht->mht_mask;
mhi->mhi_next = mht->mht_buckets[idx]; mhi->mhi_next = mht->mht_buckets[idx];
mhi->mhi_prev = NULL; mhi->mhi_prev = NULL;
if (mhi->mhi_next != NULL) if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi; mhi->mhi_next->mhi_prev = mhi;
}
mht->mht_buckets[idx] = mhi; mht->mht_buckets[idx] = mhi;
mht->mht_count++; mht->mht_count++;
@@ -861,14 +885,16 @@ static void mf_hash_add_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
/// Remove item from hashtable. Item must be non NULL and within hashtable. /// Remove item from hashtable. Item must be non NULL and within hashtable.
static void mf_hash_rem_item(mf_hashtab_T *mht, mf_hashitem_T *mhi) static void mf_hash_rem_item(mf_hashtab_T *mht, mf_hashitem_T *mhi)
{ {
if (mhi->mhi_prev == NULL) if (mhi->mhi_prev == NULL) {
mht->mht_buckets[(size_t)mhi->mhi_key & mht->mht_mask] = mht->mht_buckets[(size_t)mhi->mhi_key & mht->mht_mask] =
mhi->mhi_next; mhi->mhi_next;
else } else {
mhi->mhi_prev->mhi_next = mhi->mhi_next; mhi->mhi_prev->mhi_next = mhi->mhi_next;
}
if (mhi->mhi_next != NULL) if (mhi->mhi_next != NULL) {
mhi->mhi_next->mhi_prev = mhi->mhi_prev; mhi->mhi_next->mhi_prev = mhi->mhi_prev;
}
mht->mht_count--; mht->mht_count--;
@@ -884,8 +910,9 @@ static void mf_hash_grow(mf_hashtab_T *mht)
mf_hashitem_T **buckets = xcalloc(1, size); mf_hashitem_T **buckets = xcalloc(1, size);
int shift = 0; int shift = 0;
while ((mht->mht_mask >> shift) != 0) while ((mht->mht_mask >> shift) != 0) {
shift++; shift++;
}
for (size_t i = 0; i <= mht->mht_mask; i++) { for (size_t i = 0; i <= mht->mht_mask; i++) {
/// Traverse the items in the i-th original bucket and move them into /// Traverse the items in the i-th original bucket and move them into
@@ -914,13 +941,16 @@ static void mf_hash_grow(mf_hashtab_T *mht)
} }
} }
for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++) for (size_t j = 0; j < MHT_GROWTH_FACTOR; j++) {
if (tails[j] != NULL) if (tails[j] != NULL) {
tails[j]->mhi_next = NULL; tails[j]->mhi_next = NULL;
}
}
} }
if (mht->mht_buckets != mht->mht_small_buckets) if (mht->mht_buckets != mht->mht_small_buckets) {
xfree(mht->mht_buckets); xfree(mht->mht_buckets);
}
mht->mht_buckets = buckets; mht->mht_buckets = buckets;
mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1; mht->mht_mask = (mht->mht_mask + 1) * MHT_GROWTH_FACTOR - 1;

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +1,26 @@
// This is an open source non-commercial project. Dear PVS-Studio, please check // This is an open source non-commercial project. Dear PVS-Studio, please check
// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
// Various routines dealing with allocation and deallocation of memory. // Various routines dealing with allocation and deallocation of memory.
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <string.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h>
#include "nvim/vim.h" #include "nvim/api/vim.h"
#include "nvim/context.h" #include "nvim/context.h"
#include "nvim/decoration.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/highlight.h" #include "nvim/highlight.h"
#include "nvim/lua/executor.h"
#include "nvim/memfile.h" #include "nvim/memfile.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/ui.h"
#include "nvim/sign.h" #include "nvim/sign.h"
#include "nvim/api/vim.h" #include "nvim/ui.h"
#include "nvim/lua/executor.h" #include "nvim/vim.h"
#include "nvim/decoration.h"
#ifdef UNIT_TESTING #ifdef UNIT_TESTING
# define malloc(size) mem_malloc(size) # define malloc(size) mem_malloc(size)
@@ -47,8 +47,9 @@ void try_to_free_memory(void)
{ {
static bool trying_to_free = false; static bool trying_to_free = false;
// avoid recursive calls // avoid recursive calls
if (trying_to_free) if (trying_to_free) {
return; return;
}
trying_to_free = true; trying_to_free = true;
// free any scrollback text // free any scrollback text
@@ -182,7 +183,7 @@ void *xmallocz(size_t size)
} }
void *ret = xmalloc(total_size); void *ret = xmalloc(total_size);
((char*)ret)[size] = 0; ((char *)ret)[size] = 0;
return ret; return ret;
} }
@@ -339,16 +340,16 @@ char *xstpcpy(char *restrict dst, const char *restrict src)
char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen) char *xstpncpy(char *restrict dst, const char *restrict src, size_t maxlen)
FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
const char *p = memchr(src, '\0', maxlen); const char *p = memchr(src, '\0', maxlen);
if (p) { if (p) {
size_t srclen = (size_t)(p - src); size_t srclen = (size_t)(p - src);
memcpy(dst, src, srclen); memcpy(dst, src, srclen);
memset(dst + srclen, 0, maxlen - srclen); memset(dst + srclen, 0, maxlen - srclen);
return dst + srclen; return dst + srclen;
} else { } else {
memcpy(dst, src, maxlen); memcpy(dst, src, maxlen);
return dst + maxlen; return dst + maxlen;
} }
} }
/// xstrlcpy - Copy a NUL-terminated string into a sized buffer /// xstrlcpy - Copy a NUL-terminated string into a sized buffer
@@ -447,7 +448,7 @@ void *xmemrchr(const void *src, uint8_t c, size_t len)
{ {
while (len--) { while (len--) {
if (((uint8_t *)src)[len] == c) { if (((uint8_t *)src)[len] == c) {
return (uint8_t *) src + len; return (uint8_t *)src + len;
} }
} }
return NULL; return NULL;
@@ -500,7 +501,7 @@ bool striequal(const char *a, const char *b)
void do_outofmem_msg(size_t size) void do_outofmem_msg(size_t size)
{ {
if (!did_outofmem_msg) { if (!did_outofmem_msg) {
/* Don't hide this message */ // Don't hide this message
emsg_silent = 0; emsg_silent = 0;
/* Must come first to avoid coming back here when printing the error /* Must come first to avoid coming back here when printing the error
@@ -523,14 +524,15 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#if defined(EXITFREE) #if defined(EXITFREE)
#include "nvim/file_search.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/file_search.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
@@ -538,8 +540,9 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/move.h" #include "nvim/move.h"
#include "nvim/option.h"
#include "nvim/ops.h" #include "nvim/ops.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/path.h" #include "nvim/path.h"
#include "nvim/quickfix.h" #include "nvim/quickfix.h"
@@ -550,8 +553,6 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/tag.h" #include "nvim/tag.h"
#include "nvim/window.h" #include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/eval/typval.h"
/* /*
* Free everything that we allocated. * Free everything that we allocated.
@@ -562,7 +563,7 @@ void time_to_bytes(time_t time_, uint8_t buf[8])
*/ */
void free_all_mem(void) void free_all_mem(void)
{ {
buf_T *buf, *nextbuf; buf_T *buf, *nextbuf;
// When we cause a crash here it is caught and Vim tries to exit cleanly. // When we cause a crash here it is caught and Vim tries to exit cleanly.
// Don't try freeing everything again. // Don't try freeing everything again.
@@ -574,10 +575,11 @@ void free_all_mem(void)
// Don't want to trigger autocommands from here on. // Don't want to trigger autocommands from here on.
block_autocmds(); block_autocmds();
/* Close all tabs and windows. Reset 'equalalways' to avoid redraws. */ // Close all tabs and windows. Reset 'equalalways' to avoid redraws.
p_ea = false; p_ea = false;
if (first_tabpage->tp_next != NULL) if (first_tabpage->tp_next != NULL) {
do_cmdline_cmd("tabonly!"); do_cmdline_cmd("tabonly!");
}
if (!ONE_WINDOW) { if (!ONE_WINDOW) {
// to keep things simple, don't perform this // to keep things simple, don't perform this
@@ -586,17 +588,17 @@ void free_all_mem(void)
do_cmdline_cmd("only!"); do_cmdline_cmd("only!");
} }
/* Free all spell info. */ // Free all spell info.
spell_free_all(); spell_free_all();
/* Clear user commands (before deleting buffers). */ // Clear user commands (before deleting buffers).
ex_comclear(NULL); ex_comclear(NULL);
/* Clear menus. */ // Clear menus.
do_cmdline_cmd("aunmenu *"); do_cmdline_cmd("aunmenu *");
do_cmdline_cmd("menutranslate clear"); do_cmdline_cmd("menutranslate clear");
/* Clear mappings, abbreviations, breakpoints. */ // Clear mappings, abbreviations, breakpoints.
do_cmdline_cmd("lmapclear"); do_cmdline_cmd("lmapclear");
do_cmdline_cmd("xmapclear"); do_cmdline_cmd("xmapclear");
do_cmdline_cmd("mapclear"); do_cmdline_cmd("mapclear");
@@ -609,7 +611,7 @@ void free_all_mem(void)
free_titles(); free_titles();
free_findfile(); free_findfile();
/* Obviously named calls. */ // Obviously named calls.
free_all_autocmds(); free_all_autocmds();
free_all_marks(); free_all_marks();
alist_clear(&global_alist); alist_clear(&global_alist);
@@ -627,25 +629,25 @@ void free_all_mem(void)
diff_clear(curtab); diff_clear(curtab);
clear_sb_text(true); // free any scrollback text clear_sb_text(true); // free any scrollback text
/* Free some global vars. */ // Free some global vars.
xfree(last_cmdline); xfree(last_cmdline);
xfree(new_last_cmdline); xfree(new_last_cmdline);
set_keep_msg(NULL, 0); set_keep_msg(NULL, 0);
/* Clear cmdline history. */ // Clear cmdline history.
p_hi = 0; p_hi = 0;
init_history(); init_history();
qf_free_all(NULL); qf_free_all(NULL);
/* Free all location lists */ // Free all location lists
FOR_ALL_TAB_WINDOWS(tab, win) { FOR_ALL_TAB_WINDOWS(tab, win) {
qf_free_all(win); qf_free_all(win);
} }
/* Close all script inputs. */ // Close all script inputs.
close_all_scripts(); close_all_scripts();
/* Destroy all windows. Must come before freeing buffers. */ // Destroy all windows. Must come before freeing buffers.
win_free_all(); win_free_all();
// Free all option values. Must come after closing windows. // Free all option values. Must come after closing windows.
@@ -653,13 +655,13 @@ void free_all_mem(void)
free_arshape_buf(); free_arshape_buf();
/* Clear registers. */ // Clear registers.
clear_registers(); clear_registers();
ResetRedobuff(); ResetRedobuff();
ResetRedobuff(); ResetRedobuff();
/* highlight info */ // highlight info
free_highlight(); free_highlight();
reset_last_sourcing(); reset_last_sourcing();
@@ -667,10 +669,12 @@ void free_all_mem(void)
free_tabpage(first_tabpage); free_tabpage(first_tabpage);
first_tabpage = NULL; first_tabpage = NULL;
/* message history */ // message history
for (;; ) for (;; ) {
if (delete_first_msg() == FAIL) if (delete_first_msg() == FAIL) {
break; break;
}
}
eval_clear(); eval_clear();
api_vim_free_all_mem(); api_vim_free_all_mem();

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -7,37 +7,43 @@
#include <assert.h> #include <assert.h>
#include <inttypes.h> #include <inttypes.h>
#include <limits.h>
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <limits.h>
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/misc1.h" #include "nvim/buffer.h"
#include "nvim/buffer_updates.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/edit.h" #include "nvim/edit.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/event/stream.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_docmd.h" #include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/fileio.h" #include "nvim/fileio.h"
#include "nvim/func_attr.h"
#include "nvim/fold.h" #include "nvim/fold.h"
#include "nvim/func_attr.h"
#include "nvim/garray.h"
#include "nvim/getchar.h" #include "nvim/getchar.h"
#include "nvim/indent.h" #include "nvim/indent.h"
#include "nvim/indent_c.h" #include "nvim/indent_c.h"
#include "nvim/buffer_updates.h"
#include "nvim/main.h" #include "nvim/main.h"
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/memory.h" #include "nvim/memory.h"
#include "nvim/message.h" #include "nvim/message.h"
#include "nvim/garray.h" #include "nvim/misc1.h"
#include "nvim/move.h"
#include "nvim/mouse.h" #include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/os/input.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h" #include "nvim/os_unix.h"
#include "nvim/quickfix.h" #include "nvim/quickfix.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"
@@ -48,14 +54,8 @@
#include "nvim/tag.h" #include "nvim/tag.h"
#include "nvim/ui.h" #include "nvim/ui.h"
#include "nvim/undo.h" #include "nvim/undo.h"
#include "nvim/vim.h"
#include "nvim/window.h" #include "nvim/window.h"
#include "nvim/os/os.h"
#include "nvim/os/shell.h"
#include "nvim/os/signal.h"
#include "nvim/os/input.h"
#include "nvim/os/time.h"
#include "nvim/event/stream.h"
#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "misc1.c.generated.h" # include "misc1.c.generated.h"
@@ -73,23 +73,23 @@ static garray_T ga_users = GA_EMPTY_INIT_VALUE;
* If "include_space" is set, include trailing whitespace while calculating the * If "include_space" is set, include trailing whitespace while calculating the
* length. * length.
*/ */
int get_leader_len(char_u *line, char_u **flags, int get_leader_len(char_u *line, char_u **flags, bool backward, bool include_space)
bool backward, bool include_space)
{ {
int i, j; int i, j;
int result; int result;
int got_com = FALSE; int got_com = FALSE;
int found_one; int found_one;
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ char_u part_buf[COM_MAX_LEN]; // buffer for one option part
char_u *string; /* pointer to comment string */ char_u *string; // pointer to comment string
char_u *list; char_u *list;
int middle_match_len = 0; int middle_match_len = 0;
char_u *prev_list; char_u *prev_list;
char_u *saved_flags = NULL; char_u *saved_flags = NULL;
result = i = 0; result = i = 0;
while (ascii_iswhite(line[i])) /* leading white space is ignored */ while (ascii_iswhite(line[i])) { // leading white space is ignored
++i; ++i;
}
/* /*
* Repeat to match several nested comment strings. * Repeat to match several nested comment strings.
@@ -102,51 +102,60 @@ int get_leader_len(char_u *line, char_u **flags,
for (list = curbuf->b_p_com; *list; ) { for (list = curbuf->b_p_com; *list; ) {
/* Get one option part into part_buf[]. Advance "list" to next /* Get one option part into part_buf[]. Advance "list" to next
* one. Put "string" at start of string. */ * one. Put "string" at start of string. */
if (!got_com && flags != NULL) if (!got_com && flags != NULL) {
*flags = list; /* remember where flags started */ *flags = list; // remember where flags started
}
prev_list = list; prev_list = list;
(void)copy_option_part(&list, part_buf, COM_MAX_LEN, ","); (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
string = vim_strchr(part_buf, ':'); string = vim_strchr(part_buf, ':');
if (string == NULL) /* missing ':', ignore this part */ if (string == NULL) { // missing ':', ignore this part
continue; continue;
*string++ = NUL; /* isolate flags from string */ }
*string++ = NUL; // isolate flags from string
/* If we found a middle match previously, use that match when this /* If we found a middle match previously, use that match when this
* is not a middle or end. */ * is not a middle or end. */
if (middle_match_len != 0 if (middle_match_len != 0
&& vim_strchr(part_buf, COM_MIDDLE) == NULL && vim_strchr(part_buf, COM_MIDDLE) == NULL
&& vim_strchr(part_buf, COM_END) == NULL) && vim_strchr(part_buf, COM_END) == NULL) {
break; break;
}
/* When we already found a nested comment, only accept further /* When we already found a nested comment, only accept further
* nested comments. */ * nested comments. */
if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) if (got_com && vim_strchr(part_buf, COM_NEST) == NULL) {
continue; continue;
}
/* When 'O' flag present and using "O" command skip this one. */ // When 'O' flag present and using "O" command skip this one.
if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL) {
continue; continue;
}
/* Line contents and string must match. /* Line contents and string must match.
* When string starts with white space, must have some white space * When string starts with white space, must have some white space
* (but the amount does not need to match, there might be a mix of * (but the amount does not need to match, there might be a mix of
* TABs and spaces). */ * TABs and spaces). */
if (ascii_iswhite(string[0])) { if (ascii_iswhite(string[0])) {
if (i == 0 || !ascii_iswhite(line[i - 1])) if (i == 0 || !ascii_iswhite(line[i - 1])) {
continue; /* missing white space */ continue; // missing white space
while (ascii_iswhite(string[0])) }
while (ascii_iswhite(string[0])) {
++string; ++string;
}
} }
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
; ;
if (string[j] != NUL) }
continue; /* string doesn't match */ if (string[j] != NUL) {
continue; // string doesn't match
}
/* When 'b' flag used, there must be white space or an /* When 'b' flag used, there must be white space or an
* end-of-line after the string in the line. */ * end-of-line after the string in the line. */
if (vim_strchr(part_buf, COM_BLANK) != NULL if (vim_strchr(part_buf, COM_BLANK) != NULL
&& !ascii_iswhite(line[i + j]) && line[i + j] != NUL) && !ascii_iswhite(line[i + j]) && line[i + j] != NUL) {
continue; continue;
}
/* We have found a match, stop searching unless this is a middle /* We have found a match, stop searching unless this is a middle
* comment. The middle comment can be a substring of the end * comment. The middle comment can be a substring of the end
@@ -160,13 +169,15 @@ int get_leader_len(char_u *line, char_u **flags,
} }
continue; continue;
} }
if (middle_match_len != 0 && j > middle_match_len) if (middle_match_len != 0 && j > middle_match_len) {
/* Use this match instead of the middle match, since it's a /* Use this match instead of the middle match, since it's a
* longer thus better match. */ * longer thus better match. */
middle_match_len = 0; middle_match_len = 0;
}
if (middle_match_len == 0) if (middle_match_len == 0) {
i += j; i += j;
}
found_one = TRUE; found_one = TRUE;
break; break;
} }
@@ -174,29 +185,34 @@ int get_leader_len(char_u *line, char_u **flags,
if (middle_match_len != 0) { if (middle_match_len != 0) {
/* Use the previously found middle match after failing to find a /* Use the previously found middle match after failing to find a
* match with an end. */ * match with an end. */
if (!got_com && flags != NULL) if (!got_com && flags != NULL) {
*flags = saved_flags; *flags = saved_flags;
}
i += middle_match_len; i += middle_match_len;
found_one = TRUE; found_one = TRUE;
} }
/* No match found, stop scanning. */ // No match found, stop scanning.
if (!found_one) if (!found_one) {
break; break;
}
result = i; result = i;
/* Include any trailing white space. */ // Include any trailing white space.
while (ascii_iswhite(line[i])) while (ascii_iswhite(line[i])) {
++i; ++i;
}
if (include_space) if (include_space) {
result = i; result = i;
}
/* If this comment doesn't nest, stop here. */ // If this comment doesn't nest, stop here.
got_com = TRUE; got_com = TRUE;
if (vim_strchr(part_buf, COM_NEST) == NULL) if (vim_strchr(part_buf, COM_NEST) == NULL) {
break; break;
}
} }
return result; return result;
} }
@@ -213,12 +229,12 @@ int get_last_leader_offset(char_u *line, char_u **flags)
int result = -1; int result = -1;
int i, j; int i, j;
int lower_check_bound = 0; int lower_check_bound = 0;
char_u *string; char_u *string;
char_u *com_leader; char_u *com_leader;
char_u *com_flags; char_u *com_flags;
char_u *list; char_u *list;
int found_one; int found_one;
char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */ char_u part_buf[COM_MAX_LEN]; // buffer for one option part
/* /*
* Repeat to match several nested comment strings. * Repeat to match several nested comment strings.
@@ -242,7 +258,7 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* happen. */ * happen. */
continue; continue;
} }
*string++ = NUL; /* Isolate flags from string. */ *string++ = NUL; // Isolate flags from string.
com_leader = string; com_leader = string;
/* /*
@@ -252,16 +268,19 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* TABs and spaces). * TABs and spaces).
*/ */
if (ascii_iswhite(string[0])) { if (ascii_iswhite(string[0])) {
if (i == 0 || !ascii_iswhite(line[i - 1])) if (i == 0 || !ascii_iswhite(line[i - 1])) {
continue; continue;
}
while (ascii_iswhite(*string)) { while (ascii_iswhite(*string)) {
string++; string++;
} }
} }
for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j) {
/* do nothing */; /* do nothing */;
if (string[j] != NUL) }
if (string[j] != NUL) {
continue; continue;
}
/* /*
* When 'b' flag used, there must be white space or an * When 'b' flag used, there must be white space or an
@@ -290,23 +309,25 @@ int get_last_leader_offset(char_u *line, char_u **flags)
*/ */
found_one = TRUE; found_one = TRUE;
if (flags) if (flags) {
*flags = flags_save; *flags = flags_save;
}
com_flags = flags_save; com_flags = flags_save;
break; break;
} }
if (found_one) { if (found_one) {
char_u part_buf2[COM_MAX_LEN]; /* buffer for one option part */ char_u part_buf2[COM_MAX_LEN]; // buffer for one option part
int len1, len2, off; int len1, len2, off;
result = i; result = i;
/* /*
* If this comment nests, continue searching. * If this comment nests, continue searching.
*/ */
if (vim_strchr(part_buf, COM_NEST) != NULL) if (vim_strchr(part_buf, COM_NEST) != NULL) {
continue; continue;
}
lower_check_bound = i; lower_check_bound = i;
@@ -316,31 +337,36 @@ int get_last_leader_offset(char_u *line, char_u **flags)
* the comment leader correctly. * the comment leader correctly.
*/ */
while (ascii_iswhite(*com_leader)) while (ascii_iswhite(*com_leader)) {
++com_leader; ++com_leader;
}
len1 = (int)STRLEN(com_leader); len1 = (int)STRLEN(com_leader);
for (list = curbuf->b_p_com; *list; ) { for (list = curbuf->b_p_com; *list; ) {
char_u *flags_save = list; char_u *flags_save = list;
(void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ","); (void)copy_option_part(&list, part_buf2, COM_MAX_LEN, ",");
if (flags_save == com_flags) if (flags_save == com_flags) {
continue; continue;
}
string = vim_strchr(part_buf2, ':'); string = vim_strchr(part_buf2, ':');
++string; ++string;
while (ascii_iswhite(*string)) while (ascii_iswhite(*string)) {
++string; ++string;
}
len2 = (int)STRLEN(string); len2 = (int)STRLEN(string);
if (len2 == 0) if (len2 == 0) {
continue; continue;
}
/* Now we have to verify whether string ends with a substring /* Now we have to verify whether string ends with a substring
* beginning the com_leader. */ * beginning the com_leader. */
for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2; ) { for (off = (len2 > i ? i : len2); off > 0 && off + len1 > len2; ) {
--off; --off;
if (!STRNCMP(string + off, com_leader, len2 - off)) { if (!STRNCMP(string + off, com_leader, len2 - off)) {
if (i - off < lower_check_bound) if (i - off < lower_check_bound) {
lower_check_bound = i - off; lower_check_bound = i - off;
}
} }
} }
} }
@@ -361,7 +387,7 @@ int gchar_pos(pos_T *pos)
/* /*
* check_status: called when the status bars for the buffer 'buf' * check_status: called when the status bars for the buffer 'buf'
* need to be updated * need to be updated
*/ */
void check_status(buf_T *buf) void check_status(buf_T *buf)
{ {
@@ -459,7 +485,7 @@ int is_mouse_key(int c)
*/ */
int get_keystroke(MultiQueue *events) int get_keystroke(MultiQueue *events)
{ {
char_u *buf = NULL; char_u *buf = NULL;
int buflen = 150; int buflen = 150;
int maxlen; int maxlen;
int len = 0; int len = 0;
@@ -493,9 +519,9 @@ int get_keystroke(MultiQueue *events)
n = fix_input_buffer(buf + len, n); n = fix_input_buffer(buf + len, n);
len += n; len += n;
waited = 0; waited = 0;
} else if (len > 0) } else if (len > 0) {
++waited; /* keep track of the waiting time */ ++waited; // keep track of the waiting time
}
if (n > 0) { // found a termcode: adjust length if (n > 0) { // found a termcode: adjust length
len = n; len = n;
} }
@@ -503,19 +529,20 @@ int get_keystroke(MultiQueue *events)
continue; continue;
} }
/* Handle modifier and/or special key code. */ // Handle modifier and/or special key code.
n = buf[0]; n = buf[0];
if (n == K_SPECIAL) { if (n == K_SPECIAL) {
n = TO_SPECIAL(buf[1], buf[2]); n = TO_SPECIAL(buf[1], buf[2]);
if (buf[1] == KS_MODIFIER if (buf[1] == KS_MODIFIER
|| n == K_IGNORE || n == K_IGNORE
|| (is_mouse_key(n) && n != K_LEFTMOUSE) || (is_mouse_key(n) && n != K_LEFTMOUSE)) {
) { if (buf[1] == KS_MODIFIER) {
if (buf[1] == KS_MODIFIER)
mod_mask = buf[2]; mod_mask = buf[2];
}
len -= 3; len -= 3;
if (len > 0) if (len > 0) {
memmove(buf, buf + 3, (size_t)len); memmove(buf, buf + 3, (size_t)len);
}
continue; continue;
} }
break; break;
@@ -534,27 +561,25 @@ int get_keystroke(MultiQueue *events)
return n; return n;
} }
/* /// Get a number from the user.
* Get a number from the user. /// When "mouse_used" is not NULL allow using the mouse.
* When "mouse_used" is not NULL allow using the mouse. ///
*/ /// @param colon allow colon to abort
int int get_number(int colon, int *mouse_used)
get_number (
int colon, /* allow colon to abort */
int *mouse_used
)
{ {
int n = 0; int n = 0;
int c; int c;
int typed = 0; int typed = 0;
if (mouse_used != NULL) if (mouse_used != NULL) {
*mouse_used = FALSE; *mouse_used = FALSE;
}
/* When not printing messages, the user won't know what to type, return a /* When not printing messages, the user won't know what to type, return a
* zero (as if CR was hit). */ * zero (as if CR was hit). */
if (msg_silent != 0) if (msg_silent != 0) {
return 0; return 0;
}
no_mapping++; no_mapping++;
for (;; ) { for (;; ) {
@@ -576,8 +601,9 @@ get_number (
break; break;
} else if (n == 0 && c == ':' && colon) { } else if (n == 0 && c == ':' && colon) {
stuffcharReadbuff(':'); stuffcharReadbuff(':');
if (!exmode_active) if (!exmode_active) {
cmdline_row = msg_row; cmdline_row = msg_row;
}
skip_redraw = true; // skip redraw once skip_redraw = true; // skip redraw once
do_redraw = false; do_redraw = false;
break; break;
@@ -643,34 +669,39 @@ void msgmore(long n)
{ {
long pn; long pn;
if (global_busy /* no messages now, wait until global is finished */ if (global_busy // no messages now, wait until global is finished
|| !messaging()) /* 'lazyredraw' set, don't do messages now */ || !messaging()) { // 'lazyredraw' set, don't do messages now
return; return;
}
/* We don't want to overwrite another important message, but do overwrite /* We don't want to overwrite another important message, but do overwrite
* a previous "more lines" or "fewer lines" message, so that "5dd" and * a previous "more lines" or "fewer lines" message, so that "5dd" and
* then "put" reports the last action. */ * then "put" reports the last action. */
if (keep_msg != NULL && !keep_msg_more) if (keep_msg != NULL && !keep_msg_more) {
return; return;
}
if (n > 0) if (n > 0) {
pn = n; pn = n;
else } else {
pn = -n; pn = -n;
}
if (pn > p_report) { if (pn > p_report) {
if (pn == 1) { if (pn == 1) {
if (n > 0) if (n > 0) {
STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN); STRLCPY(msg_buf, _("1 more line"), MSG_BUF_LEN);
else } else {
STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN); STRLCPY(msg_buf, _("1 line less"), MSG_BUF_LEN);
}
} else { } else {
if (n > 0) if (n > 0) {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN, vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
_("%" PRId64 " more lines"), (int64_t)pn); _("%" PRId64 " more lines"), (int64_t)pn);
else } else {
vim_snprintf((char *)msg_buf, MSG_BUF_LEN, vim_snprintf((char *)msg_buf, MSG_BUF_LEN,
_("%" PRId64 " fewer lines"), (int64_t)pn); _("%" PRId64 " fewer lines"), (int64_t)pn);
}
} }
if (got_int) { if (got_int) {
xstrlcat((char *)msg_buf, _(" (Interrupted)"), MSG_BUF_LEN); xstrlcat((char *)msg_buf, _(" (Interrupted)"), MSG_BUF_LEN);
@@ -762,8 +793,9 @@ static void init_users(void)
char_u *get_users(expand_T *xp, int idx) char_u *get_users(expand_T *xp, int idx)
{ {
init_users(); init_users();
if (idx < ga_users.ga_len) if (idx < ga_users.ga_len) {
return ((char_u **)ga_users.ga_data)[idx]; return ((char_u **)ga_users.ga_data)[idx];
}
return NULL; return NULL;
} }
@@ -780,10 +812,12 @@ int match_user(char_u *name)
init_users(); init_users();
for (int i = 0; i < ga_users.ga_len; i++) { for (int i = 0; i < ga_users.ga_len; i++) {
if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) if (STRCMP(((char_u **)ga_users.ga_data)[i], name) == 0) {
return 2; /* full match */ return 2; // full match
if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) }
result = 1; /* partial match */ if (STRNCMP(((char_u **)ga_users.ga_data)[i], name, n) == 0) {
result = 1; // partial match
}
} }
return result; return result;
} }
@@ -921,8 +955,7 @@ int call_shell(char_u *cmd, ShellOpts opts, char_u *extra_shell_arg)
/// @param ret_len length of the stdout /// @param ret_len length of the stdout
/// ///
/// @return an allocated string, or NULL for error. /// @return an allocated string, or NULL for error.
char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags, size_t *ret_len)
size_t *ret_len)
{ {
char_u *buffer = NULL; char_u *buffer = NULL;
@@ -970,12 +1003,14 @@ char_u *get_cmd_output(char_u *cmd, char_u *infile, ShellOpts flags,
EMSG2(_(e_notread), tempname); EMSG2(_(e_notread), tempname);
XFREE_CLEAR(buffer); XFREE_CLEAR(buffer);
} else if (ret_len == NULL) { } else if (ret_len == NULL) {
/* Change NUL into SOH, otherwise the string is truncated. */ // Change NUL into SOH, otherwise the string is truncated.
for (i = 0; i < len; ++i) for (i = 0; i < len; ++i) {
if (buffer[i] == NUL) if (buffer[i] == NUL) {
buffer[i] = 1; buffer[i] = 1;
}
}
buffer[len] = NUL; /* make sure the buffer is terminated */ buffer[len] = NUL; // make sure the buffer is terminated
} else { } else {
*ret_len = len; *ret_len = len;
} }
@@ -991,10 +1026,12 @@ done:
*/ */
void FreeWild(int count, char_u **files) void FreeWild(int count, char_u **files)
{ {
if (count <= 0 || files == NULL) if (count <= 0 || files == NULL) {
return; return;
while (count--) }
while (count--) {
xfree(files[count]); xfree(files[count]);
}
xfree(files); xfree(files);
} }

View File

@@ -3,26 +3,26 @@
#include <stdbool.h> #include <stdbool.h>
#include "nvim/mouse.h"
#include "nvim/vim.h"
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/window.h" #include "nvim/buffer_defs.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
#include "nvim/diff.h"
#include "nvim/fold.h"
#include "nvim/memline.h"
#include "nvim/misc1.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
#include "nvim/os_unix.h"
#include "nvim/plines.h"
#include "nvim/screen.h"
#include "nvim/state.h" #include "nvim/state.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/screen.h"
#include "nvim/syntax.h" #include "nvim/syntax.h"
#include "nvim/ui.h" #include "nvim/ui.h"
#include "nvim/ui_compositor.h" #include "nvim/ui_compositor.h"
#include "nvim/os_unix.h" #include "nvim/vim.h"
#include "nvim/fold.h" #include "nvim/window.h"
#include "nvim/diff.h"
#include "nvim/move.h"
#include "nvim/misc1.h"
#include "nvim/plines.h"
#include "nvim/cursor.h"
#include "nvim/buffer_defs.h"
#include "nvim/memline.h"
#include "nvim/charset.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
# include "mouse.c.generated.h" # include "mouse.c.generated.h"
@@ -31,33 +31,34 @@
static linenr_T orig_topline = 0; static linenr_T orig_topline = 0;
static int orig_topfill = 0; static int orig_topfill = 0;
// Move the cursor to the specified row and column on the screen. /// Move the cursor to the specified row and column on the screen.
// Change current window if necessary. Returns an integer with the /// Change current window if necessary. Returns an integer with the
// CURSOR_MOVED bit set if the cursor has moved or unset otherwise. /// CURSOR_MOVED bit set if the cursor has moved or unset otherwise.
// ///
// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column. /// The MOUSE_FOLD_CLOSE bit is set when clicked on the '-' in a fold column.
// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column. /// The MOUSE_FOLD_OPEN bit is set when clicked on the '+' in a fold column.
// ///
// If flags has MOUSE_FOCUS, then the current window will not be changed, and /// If flags has MOUSE_FOCUS, then the current window will not be changed, and
// if the mouse is outside the window then the text will scroll, or if the /// if the mouse is outside the window then the text will scroll, or if the
// mouse was previously on a status line, then the status line may be dragged. /// mouse was previously on a status line, then the status line may be dragged.
// ///
// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the /// If flags has MOUSE_MAY_VIS, then VIsual mode will be started before the
// cursor is moved unless the cursor was on a status line. /// cursor is moved unless the cursor was on a status line.
// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or /// This function returns one of IN_UNKNOWN, IN_BUFFER, IN_STATUS_LINE or
// IN_SEP_LINE depending on where the cursor was clicked. /// IN_SEP_LINE depending on where the cursor was clicked.
// ///
// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless /// If flags has MOUSE_MAY_STOP_VIS, then Visual mode will be stopped, unless
// the mouse is on the status line of the same window. /// the mouse is on the status line of the same window.
// ///
// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since /// If flags has MOUSE_DID_MOVE, nothing is done if the mouse didn't move since
// the last call. /// the last call.
// ///
// If flags has MOUSE_SETPOS, nothing is done, only the current position is /// If flags has MOUSE_SETPOS, nothing is done, only the current position is
// remembered. /// remembered.
int jump_to_mouse(int flags, ///
bool *inclusive, // used for inclusive operator, can be NULL /// @param inclusive used for inclusive operator, can be NULL
int which_button) // MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE /// @param which_button MOUSE_LEFT, MOUSE_RIGHT, MOUSE_MIDDLE
int jump_to_mouse(int flags, bool *inclusive, int which_button)
{ {
static int on_status_line = 0; // #lines below bottom of window static int on_status_line = 0; // #lines below bottom of window
static int on_sep_line = 0; // on separator right of window static int on_sep_line = 0; // on separator right of window
@@ -66,7 +67,7 @@ int jump_to_mouse(int flags,
static win_T *dragwin = NULL; // window being dragged static win_T *dragwin = NULL; // window being dragged
static int did_drag = false; // drag was noticed static int did_drag = false; // drag was noticed
win_T *wp, *old_curwin; win_T *wp, *old_curwin;
pos_T old_cursor; pos_T old_cursor;
int count; int count;
bool first; bool first;
@@ -81,8 +82,9 @@ int jump_to_mouse(int flags,
if (flags & MOUSE_RELEASED) { if (flags & MOUSE_RELEASED) {
// On button release we may change window focus if positioned on a // On button release we may change window focus if positioned on a
// status line and no dragging happened. // status line and no dragging happened.
if (dragwin != NULL && !did_drag) if (dragwin != NULL && !did_drag) {
flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE); flags &= ~(MOUSE_FOCUS | MOUSE_DID_MOVE);
}
dragwin = NULL; dragwin = NULL;
did_drag = false; did_drag = false;
} }
@@ -109,15 +111,16 @@ retnomove:
prev_row = mouse_row; prev_row = mouse_row;
prev_col = mouse_col; prev_col = mouse_col;
if (flags & MOUSE_SETPOS) if (flags & MOUSE_SETPOS) {
goto retnomove; // ugly goto... goto retnomove; // ugly goto...
}
old_curwin = curwin; old_curwin = curwin;
old_cursor = curwin->w_cursor; old_cursor = curwin->w_cursor;
if (!(flags & MOUSE_FOCUS)) { if (!(flags & MOUSE_FOCUS)) {
if (row < 0 || col < 0) // check if it makes sense if (row < 0 || col < 0) { // check if it makes sense
return IN_UNKNOWN; return IN_UNKNOWN;
}
// find the window where the row is in // find the window where the row is in
wp = mouse_find_win(&grid, &row, &col); wp = mouse_find_win(&grid, &row, &col);
@@ -151,10 +154,11 @@ retnomove:
// The rightmost character of the status line might be a vertical // The rightmost character of the status line might be a vertical
// separator character if there is no connecting window to the right. // separator character if there is no connecting window to the right.
if (on_status_line && on_sep_line) { if (on_status_line && on_sep_line) {
if (stl_connected(wp)) if (stl_connected(wp)) {
on_sep_line = 0; on_sep_line = 0;
else } else {
on_status_line = 0; on_status_line = 0;
}
} }
// Before jumping to another buffer, or moving the cursor for a left // Before jumping to another buffer, or moving the cursor for a left
@@ -181,28 +185,32 @@ retnomove:
// Only change window focus when not clicking on or dragging the // Only change window focus when not clicking on or dragging the
// status line. Do change focus when releasing the mouse button // status line. Do change focus when releasing the mouse button
// (MOUSE_FOCUS was set above if we dragged first). // (MOUSE_FOCUS was set above if we dragged first).
if (dragwin == NULL || (flags & MOUSE_RELEASED)) if (dragwin == NULL || (flags & MOUSE_RELEASED)) {
win_enter(wp, true); // can make wp invalid! win_enter(wp, true); // can make wp invalid!
}
// set topline, to be able to check for double click ourselves // set topline, to be able to check for double click ourselves
if (curwin != old_curwin) if (curwin != old_curwin) {
set_mouse_topline(curwin); set_mouse_topline(curwin);
}
if (on_status_line) { // In (or below) status line if (on_status_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window // Don't use start_arrow() if we're in the same window
if (curwin == old_curwin) if (curwin == old_curwin) {
return IN_STATUS_LINE; return IN_STATUS_LINE;
else } else {
return IN_STATUS_LINE | CURSOR_MOVED; return IN_STATUS_LINE | CURSOR_MOVED;
}
} }
if (on_sep_line) { // In (or below) status line if (on_sep_line) { // In (or below) status line
// Don't use start_arrow() if we're in the same window // Don't use start_arrow() if we're in the same window
if (curwin == old_curwin) if (curwin == old_curwin) {
return IN_SEP_LINE; return IN_SEP_LINE;
else } else {
return IN_SEP_LINE | CURSOR_MOVED; return IN_SEP_LINE | CURSOR_MOVED;
}
} }
curwin->w_cursor.lnum = curwin->w_topline; curwin->w_cursor.lnum = curwin->w_topline;
} else if (on_status_line && which_button == MOUSE_LEFT) { } else if (on_status_line && which_button == MOUSE_LEFT) {
if (dragwin != NULL) { if (dragwin != NULL) {
// Drag the status line // Drag the status line
count = row - dragwin->w_winrow - dragwin->w_height + 1 count = row - dragwin->w_winrow - dragwin->w_height + 1
@@ -211,7 +219,7 @@ retnomove:
did_drag |= count; did_drag |= count;
} }
return IN_STATUS_LINE; // Cursor didn't move return IN_STATUS_LINE; // Cursor didn't move
} else if (on_sep_line && which_button == MOUSE_LEFT) { } else if (on_sep_line && which_button == MOUSE_LEFT) {
if (dragwin != NULL) { if (dragwin != NULL) {
// Drag the separator column // Drag the separator column
count = col - dragwin->w_wincol - dragwin->w_width + 1 count = col - dragwin->w_wincol - dragwin->w_width + 1
@@ -255,7 +263,7 @@ retnomove:
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
redraw_later(curwin, VALID); redraw_later(curwin, VALID);
row = 0; row = 0;
} else if (row >= curwin->w_height_inner) { } else if (row >= curwin->w_height_inner) {
count = 0; count = 0;
for (first = true; curwin->w_topline < curbuf->b_ml.ml_line_count; ) { for (first = true; curwin->w_topline < curbuf->b_ml.ml_line_count; ) {
if (curwin->w_topfill > 0) { if (curwin->w_topfill > 0) {
@@ -287,7 +295,7 @@ retnomove:
curwin->w_valid &= curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
row = curwin->w_height_inner - 1; row = curwin->w_height_inner - 1;
} else if (row == 0) { } else if (row == 0) {
// When dragging the mouse, while the text has been scrolled up as // When dragging the mouse, while the text has been scrolled up as
// far as it goes, moving the mouse in the top line should scroll // far as it goes, moving the mouse in the top line should scroll
// the text down (done later when recomputing w_topline). // the text down (done later when recomputing w_topline).
@@ -394,8 +402,9 @@ bool mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump)
if (!retval) { if (!retval) {
// Compute the column without wrapping. // Compute the column without wrapping.
off = win_col_off(win) - win_col_off2(win); off = win_col_off(win) - win_col_off2(win);
if (col < off) if (col < off) {
col = off; col = off;
}
col += row * (win->w_width_inner - off); col += row * (win->w_width_inner - off);
// add skip column (for long wrapping line) // add skip column (for long wrapping line)
col += win->w_skipcol; col += win->w_skipcol;
@@ -431,23 +440,26 @@ win_T *mouse_find_win(int *gridp, int *rowp, int *colp)
} }
frame_T *fp; frame_T *fp;
fp = topframe; fp = topframe;
*rowp -= firstwin->w_winrow; *rowp -= firstwin->w_winrow;
for (;; ) { for (;; ) {
if (fp->fr_layout == FR_LEAF) if (fp->fr_layout == FR_LEAF) {
break; break;
}
if (fp->fr_layout == FR_ROW) { if (fp->fr_layout == FR_ROW) {
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
if (*colp < fp->fr_width) if (*colp < fp->fr_width) {
break; break;
}
*colp -= fp->fr_width; *colp -= fp->fr_width;
} }
} else { // fr_layout == FR_COL } else { // fr_layout == FR_COL
for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) { for (fp = fp->fr_child; fp->fr_next != NULL; fp = fp->fr_next) {
if (*rowp < fp->fr_height) if (*rowp < fp->fr_height) {
break; break;
}
*rowp -= fp->fr_height; *rowp -= fp->fr_height;
} }
} }
@@ -574,21 +586,21 @@ static linenr_T find_longest_lnum(void)
bool mouse_scroll_horiz(int dir) bool mouse_scroll_horiz(int dir)
{ {
if (curwin->w_p_wrap) { if (curwin->w_p_wrap) {
return false; return false;
} }
int step = 6; int step = 6;
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) { if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
step = curwin->w_width_inner; step = curwin->w_width_inner;
} }
int leftcol = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : +step); int leftcol = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : +step);
if (leftcol < 0) { if (leftcol < 0) {
leftcol = 0; leftcol = 0;
} }
if (curwin->w_leftcol == leftcol) { if (curwin->w_leftcol == leftcol) {
return false; return false;
} }
curwin->w_leftcol = (colnr_T)leftcol; curwin->w_leftcol = (colnr_T)leftcol;
@@ -597,8 +609,8 @@ bool mouse_scroll_horiz(int dir)
// longest visible line. // longest visible line.
if (!virtual_active() if (!virtual_active()
&& (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) { && (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) {
curwin->w_cursor.lnum = find_longest_lnum(); curwin->w_cursor.lnum = find_longest_lnum();
curwin->w_cursor.col = 0; curwin->w_cursor.col = 0;
} }
return leftcol_changed(); return leftcol_changed();

View File

@@ -18,7 +18,6 @@
#include "nvim/ascii.h" #include "nvim/ascii.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/move.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/diff.h" #include "nvim/diff.h"
@@ -27,17 +26,18 @@
#include "nvim/mbyte.h" #include "nvim/mbyte.h"
#include "nvim/memline.h" #include "nvim/memline.h"
#include "nvim/misc1.h" #include "nvim/misc1.h"
#include "nvim/plines.h" #include "nvim/move.h"
#include "nvim/option.h" #include "nvim/option.h"
#include "nvim/plines.h"
#include "nvim/popupmnu.h" #include "nvim/popupmnu.h"
#include "nvim/screen.h" #include "nvim/screen.h"
#include "nvim/strings.h" #include "nvim/strings.h"
#include "nvim/window.h" #include "nvim/window.h"
typedef struct { typedef struct {
linenr_T lnum; /* line number */ linenr_T lnum; // line number
int fill; /* filler lines */ int fill; // filler lines
int height; /* height of added line */ int height; // height of added line
} lineoff_T; } lineoff_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS #ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -85,7 +85,7 @@ static void comp_botline(win_T *wp)
lnum = last; lnum = last;
} }
/* wp->w_botline is the line that is just below the window */ // wp->w_botline is the line that is just below the window
wp->w_botline = lnum; wp->w_botline = lnum;
wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
wp->w_viewport_invalid = true; wp->w_viewport_invalid = true;
@@ -274,8 +274,7 @@ void update_topline(win_T *wp)
n += wp->w_filler_rows; n += wp->w_filler_rows;
loff.height = 0; loff.height = 0;
while (loff.lnum < wp->w_botline while (loff.lnum < wp->w_botline
&& (loff.lnum + 1 < wp->w_botline || loff.fill == 0) && (loff.lnum + 1 < wp->w_botline || loff.fill == 0)) {
) {
n += loff.height; n += loff.height;
if (n >= *so_ptr) { if (n >= *so_ptr) {
break; break;
@@ -287,7 +286,7 @@ void update_topline(win_T *wp)
check_botline = false; check_botline = false;
} }
} else { } else {
/* sufficient context, no need to scroll */ // sufficient context, no need to scroll
check_botline = false; check_botline = false;
} }
} }
@@ -325,8 +324,7 @@ void update_topline(win_T *wp)
* Need to redraw when topline changed. * Need to redraw when topline changed.
*/ */
if (wp->w_topline != old_topline if (wp->w_topline != old_topline
|| wp->w_topfill != old_topfill || wp->w_topfill != old_topfill) {
) {
dollar_vcol = -1; dollar_vcol = -1;
if (wp->w_skipcol != 0) { if (wp->w_skipcol != 0) {
wp->w_skipcol = 0; wp->w_skipcol = 0;
@@ -346,7 +344,7 @@ void update_topline(win_T *wp)
/* /*
* Update win->w_topline to move the cursor onto the screen. * Update win->w_topline to move the cursor onto the screen.
*/ */
void update_topline_win(win_T* win) void update_topline_win(win_T * win)
{ {
win_T *save_curwin; win_T *save_curwin;
switch_win(&save_curwin, NULL, win, NULL, true); switch_win(&save_curwin, NULL, win, NULL, true);
@@ -374,8 +372,7 @@ static bool check_top_offset(void)
{ {
long so = get_scrolloff_value(curwin); long so = get_scrolloff_value(curwin);
if (curwin->w_cursor.lnum < curwin->w_topline + so if (curwin->w_cursor.lnum < curwin->w_topline + so
|| hasAnyFolding(curwin) || hasAnyFolding(curwin)) {
) {
lineoff_T loff; lineoff_T loff;
loff.lnum = curwin->w_cursor.lnum; loff.lnum = curwin->w_cursor.lnum;
loff.fill = 0; loff.fill = 0;
@@ -385,8 +382,8 @@ static bool check_top_offset(void)
topline_back(curwin, &loff); topline_back(curwin, &loff);
// Stop when included a line above the window. // Stop when included a line above the window.
if (loff.lnum < curwin->w_topline if (loff.lnum < curwin->w_topline
|| (loff.lnum == curwin->w_topline && loff.fill > 0) || (loff.lnum == curwin->w_topline &&
) { loff.fill > 0)) {
break; break;
} }
n += loff.height; n += loff.height;
@@ -420,8 +417,8 @@ void check_cursor_moved(win_T *wp)
wp->w_viewport_invalid = true; wp->w_viewport_invalid = true;
} else if (wp->w_cursor.col != wp->w_valid_cursor.col } else if (wp->w_cursor.col != wp->w_valid_cursor.col
|| wp->w_leftcol != wp->w_valid_leftcol || wp->w_leftcol != wp->w_valid_leftcol
|| wp->w_cursor.coladd != wp->w_valid_cursor.coladd || wp->w_cursor.coladd !=
) { wp->w_valid_cursor.coladd) {
wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL);
wp->w_valid_cursor.col = wp->w_cursor.col; wp->w_valid_cursor.col = wp->w_cursor.col;
wp->w_valid_leftcol = wp->w_leftcol; wp->w_valid_leftcol = wp->w_leftcol;
@@ -560,7 +557,7 @@ void validate_cursor(void)
*/ */
static void curs_rows(win_T *wp) static void curs_rows(win_T *wp)
{ {
/* Check if wp->w_lines[].wl_size is invalid */ // Check if wp->w_lines[].wl_size is invalid
int all_invalid = (!redrawing() int all_invalid = (!redrawing()
|| wp->w_lines_valid == 0 || wp->w_lines_valid == 0
|| wp->w_lines[0].wl_lnum > wp->w_topline); || wp->w_lines[0].wl_lnum > wp->w_topline);
@@ -569,27 +566,29 @@ static void curs_rows(win_T *wp)
for (linenr_T lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) { for (linenr_T lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) {
bool valid = false; bool valid = false;
if (!all_invalid && i < wp->w_lines_valid) { if (!all_invalid && i < wp->w_lines_valid) {
if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) {
continue; /* skip changed or deleted lines */ continue; // skip changed or deleted lines
}
if (wp->w_lines[i].wl_lnum == lnum) { if (wp->w_lines[i].wl_lnum == lnum) {
/* Check for newly inserted lines below this row, in which /* Check for newly inserted lines below this row, in which
* case we need to check for folded lines. */ * case we need to check for folded lines. */
if (!wp->w_buffer->b_mod_set if (!wp->w_buffer->b_mod_set
|| wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum || wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum
|| wp->w_buffer->b_mod_top || wp->w_buffer->b_mod_top
> wp->w_lines[i].wl_lastlnum + 1) > wp->w_lines[i].wl_lastlnum + 1) {
valid = true; valid = true;
}
} else if (wp->w_lines[i].wl_lnum > lnum) { } else if (wp->w_lines[i].wl_lnum > lnum) {
--i; /* hold at inserted lines */ --i; // hold at inserted lines
} }
} }
if (valid if (valid
&& (lnum != wp->w_topline || !wp->w_p_diff) && (lnum != wp->w_topline || !wp->w_p_diff)) {
) {
lnum = wp->w_lines[i].wl_lastlnum + 1; lnum = wp->w_lines[i].wl_lastlnum + 1;
/* Cursor inside folded lines, don't count this row */ // Cursor inside folded lines, don't count this row
if (lnum > wp->w_cursor.lnum) if (lnum > wp->w_cursor.lnum) {
break; break;
}
wp->w_cline_row += wp->w_lines[i].wl_size; wp->w_cline_row += wp->w_lines[i].wl_size;
} else { } else {
linenr_T last = lnum; linenr_T last = lnum;
@@ -613,7 +612,7 @@ static void curs_rows(win_T *wp)
wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum, NULL, wp->w_cline_height = plines_win_full(wp, wp->w_cursor.lnum, NULL,
&wp->w_cline_folded, true); &wp->w_cline_folded, true);
} else if (i > wp->w_lines_valid) { } else if (i > wp->w_lines_valid) {
/* a line that is too long to fit on the last screen line */ // a line that is too long to fit on the last screen line
wp->w_cline_height = 0; wp->w_cline_height = 0;
wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL, wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, NULL,
NULL, true, NULL); NULL, true, NULL);
@@ -645,9 +644,9 @@ void validate_virtcol_win(win_T *wp)
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
wp->w_valid |= VALID_VIRTCOL; wp->w_valid |= VALID_VIRTCOL;
if (wp->w_p_cuc if (wp->w_p_cuc
&& !pum_visible() && !pum_visible()) {
)
redraw_later(wp, SOME_VALID); redraw_later(wp, SOME_VALID);
}
} }
} }
@@ -718,8 +717,9 @@ int curwin_col_off(void)
*/ */
int win_col_off2(win_T *wp) int win_col_off2(win_T *wp)
{ {
if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) {
return number_width(wp) + 1; return number_width(wp) + 1;
}
return 0; return 0;
} }
@@ -732,10 +732,7 @@ int curwin_col_off2(void)
// Also updates curwin->w_wrow and curwin->w_cline_row. // Also updates curwin->w_wrow and curwin->w_cline_row.
// Also updates curwin->w_leftcol. // Also updates curwin->w_leftcol.
// @param may_scroll when true, may scroll horizontally // @param may_scroll when true, may scroll horizontally
void curs_columns( void curs_columns(win_T *wp, int may_scroll)
win_T *wp,
int may_scroll
)
{ {
int n; int n;
int width = 0; int width = 0;
@@ -765,9 +762,10 @@ void curs_columns(
getvvcol(wp, &wp->w_cursor, &startcol, &(wp->w_virtcol), &endcol); getvvcol(wp, &wp->w_cursor, &startcol, &(wp->w_virtcol), &endcol);
} }
/* remove '$' from change command when cursor moves onto it */ // remove '$' from change command when cursor moves onto it
if (startcol > dollar_vcol) if (startcol > dollar_vcol) {
dollar_vcol = -1; dollar_vcol = -1;
}
int extra = win_col_off(wp); int extra = win_col_off(wp);
wp->w_wcol = wp->w_virtcol + extra; wp->w_wcol = wp->w_virtcol + extra;
@@ -782,8 +780,7 @@ void curs_columns(
wp->w_wcol = wp->w_width_inner - 1; wp->w_wcol = wp->w_width_inner - 1;
wp->w_wrow = wp->w_height_inner - 1; wp->w_wrow = wp->w_height_inner - 1;
} else if (wp->w_p_wrap } else if (wp->w_p_wrap
&& wp->w_width_inner != 0 && wp->w_width_inner != 0) {
) {
width = textwidth + win_col_off2(wp); width = textwidth + win_col_off2(wp);
// long line wrapping, adjust wp->w_wrow // long line wrapping, adjust wp->w_wrow
@@ -803,8 +800,7 @@ void curs_columns(
} }
} }
} else if (may_scroll } else if (may_scroll
&& !wp->w_cline_folded && !wp->w_cline_folded) {
) {
// No line wrapping: compute wp->w_leftcol if scrolling is on and line // No line wrapping: compute wp->w_leftcol if scrolling is on and line
// is not folded. // is not folded.
// If scrolling is off, wp->w_leftcol is assumed to be 0 // If scrolling is off, wp->w_leftcol is assumed to be 0
@@ -816,7 +812,7 @@ void curs_columns(
assert(siso <= INT_MAX); assert(siso <= INT_MAX);
int off_left = startcol - wp->w_leftcol - (int)siso; int off_left = startcol - wp->w_leftcol - (int)siso;
int off_right = int off_right =
endcol - wp->w_leftcol - wp->w_width_inner + (int)siso + 1; endcol - wp->w_leftcol - wp->w_width_inner + (int)siso + 1;
if (off_left < 0 || off_right > 0) { if (off_left < 0 || off_right > 0) {
int diff = (off_left < 0) ? -off_left: off_right; int diff = (off_left < 0) ? -off_left: off_right;
@@ -836,8 +832,9 @@ void curs_columns(
new_leftcol = wp->w_leftcol + diff; new_leftcol = wp->w_leftcol + diff;
} }
} }
if (new_leftcol < 0) if (new_leftcol < 0) {
new_leftcol = 0; new_leftcol = 0;
}
if (new_leftcol != (int)wp->w_leftcol) { if (new_leftcol != (int)wp->w_leftcol) {
wp->w_leftcol = new_leftcol; wp->w_leftcol = new_leftcol;
win_check_anchored_floats(wp); win_check_anchored_floats(wp);
@@ -867,13 +864,12 @@ void curs_columns(
|| ((prev_skipcol > 0 || ((prev_skipcol > 0
|| wp->w_wrow + so >= wp->w_height_inner) || wp->w_wrow + so >= wp->w_height_inner)
&& (plines = && (plines =
plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1 plines_win_nofill(wp, wp->w_cursor.lnum, false)) - 1
>= wp->w_height_inner)) >= wp->w_height_inner))
&& wp->w_height_inner != 0 && wp->w_height_inner != 0
&& wp->w_cursor.lnum == wp->w_topline && wp->w_cursor.lnum == wp->w_topline
&& width > 0 && width > 0
&& wp->w_width_inner != 0 && wp->w_width_inner != 0) {
) {
/* Cursor past end of screen. Happens with a single line that does /* Cursor past end of screen. Happens with a single line that does
* not fit on screen. Find a skipcol to show the text around the * not fit on screen. Find a skipcol to show the text around the
* cursor. Avoid scrolling all the time. compute value of "extra": * cursor. Avoid scrolling all the time. compute value of "extra":
@@ -972,8 +968,8 @@ void curs_columns(
/// @param[out] scolp start screen column /// @param[out] scolp start screen column
/// @param[out] ccolp cursor screen column /// @param[out] ccolp cursor screen column
/// @param[out] ecolp end screen column /// @param[out] ecolp end screen column
void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, void textpos2screenpos(win_T *wp, pos_T *pos, int *rowp, int *scolp, int *ccolp, int *ecolp,
int *ccolp, int *ecolp, bool local) bool local)
{ {
colnr_T scol = 0, ccol = 0, ecol = 0; colnr_T scol = 0, ccol = 0, ecol = 0;
int row = 0; int row = 0;
@@ -1041,39 +1037,42 @@ bool scrolldown(long line_count, int byfold)
{ {
int done = 0; // total # of physical lines done int done = 0; // total # of physical lines done
/* Make sure w_topline is at the first of a sequence of folded lines. */ // Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
validate_cursor(); /* w_wrow needs to be valid */ validate_cursor(); // w_wrow needs to be valid
while (line_count-- > 0) { while (line_count-- > 0) {
if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) if (curwin->w_topfill < diff_check(curwin, curwin->w_topline)
&& curwin->w_topfill < curwin->w_height_inner - 1) { && curwin->w_topfill < curwin->w_height_inner - 1) {
curwin->w_topfill++; curwin->w_topfill++;
done++; done++;
} else { } else {
if (curwin->w_topline == 1) if (curwin->w_topline == 1) {
break; break;
}
--curwin->w_topline; --curwin->w_topline;
curwin->w_topfill = 0; curwin->w_topfill = 0;
/* A sequence of folded lines only counts for one logical line */ // A sequence of folded lines only counts for one logical line
linenr_T first; linenr_T first;
if (hasFolding(curwin->w_topline, &first, NULL)) { if (hasFolding(curwin->w_topline, &first, NULL)) {
++done; ++done;
if (!byfold) if (!byfold) {
line_count -= curwin->w_topline - first - 1; line_count -= curwin->w_topline - first - 1;
}
curwin->w_botline -= curwin->w_topline - first; curwin->w_botline -= curwin->w_topline - first;
curwin->w_topline = first; curwin->w_topline = first;
} else { } else {
done += plines_win_nofill(curwin, curwin->w_topline, true); done += plines_win_nofill(curwin, curwin->w_topline, true);
} }
} }
--curwin->w_botline; /* approximate w_botline */ --curwin->w_botline; // approximate w_botline
invalidate_botline(); invalidate_botline();
} }
curwin->w_wrow += done; /* keep w_wrow updated */ curwin->w_wrow += done; // keep w_wrow updated
curwin->w_cline_row += done; /* keep w_cline_row updated */ curwin->w_cline_row += done; // keep w_cline_row updated
if (curwin->w_cursor.lnum == curwin->w_topline) if (curwin->w_cursor.lnum == curwin->w_topline) {
curwin->w_cline_row = 0; curwin->w_cline_row = 0;
}
check_topfill(curwin, true); check_topfill(curwin, true);
/* /*
@@ -1082,8 +1081,7 @@ bool scrolldown(long line_count, int byfold)
*/ */
int wrow = curwin->w_wrow; int wrow = curwin->w_wrow;
if (curwin->w_p_wrap if (curwin->w_p_wrap
&& curwin->w_width_inner != 0 && curwin->w_width_inner != 0) {
) {
validate_virtcol(); validate_virtcol();
validate_cheight(); validate_cheight();
wrow += curwin->w_cline_height - 1 - wrow += curwin->w_cline_height - 1 -
@@ -1094,10 +1092,11 @@ bool scrolldown(long line_count, int byfold)
linenr_T first; linenr_T first;
if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) { if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) {
--wrow; --wrow;
if (first == 1) if (first == 1) {
curwin->w_cursor.lnum = 1; curwin->w_cursor.lnum = 1;
else } else {
curwin->w_cursor.lnum = first - 1; curwin->w_cursor.lnum = first - 1;
}
} else { } else {
wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true); wrow -= plines_win(curwin, curwin->w_cursor.lnum--, true);
} }
@@ -1106,7 +1105,7 @@ bool scrolldown(long line_count, int byfold)
moved = true; moved = true;
} }
if (moved) { if (moved) {
/* Move cursor to first line of closed fold. */ // Move cursor to first line of closed fold.
foldAdjustCursor(); foldAdjustCursor();
coladvance(curwin->w_curswant); coladvance(curwin->w_curswant);
} }
@@ -1127,35 +1126,40 @@ bool scrollup(long line_count, int byfold)
// count each sequence of folded lines as one logical line // count each sequence of folded lines as one logical line
linenr_T lnum = curwin->w_topline; linenr_T lnum = curwin->w_topline;
while (line_count--) { while (line_count--) {
if (curwin->w_topfill > 0) if (curwin->w_topfill > 0) {
--curwin->w_topfill; --curwin->w_topfill;
else { } else {
if (byfold) if (byfold) {
(void)hasFolding(lnum, NULL, &lnum); (void)hasFolding(lnum, NULL, &lnum);
if (lnum >= curbuf->b_ml.ml_line_count) }
if (lnum >= curbuf->b_ml.ml_line_count) {
break; break;
}
++lnum; ++lnum;
curwin->w_topfill = diff_check_fill(curwin, lnum); curwin->w_topfill = diff_check_fill(curwin, lnum);
} }
} }
/* approximate w_botline */ // approximate w_botline
curwin->w_botline += lnum - curwin->w_topline; curwin->w_botline += lnum - curwin->w_topline;
curwin->w_topline = lnum; curwin->w_topline = lnum;
} else { } else {
curwin->w_topline += line_count; curwin->w_topline += line_count;
curwin->w_botline += line_count; /* approximate w_botline */ curwin->w_botline += line_count; // approximate w_botline
} }
if (curwin->w_topline > curbuf->b_ml.ml_line_count) if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count; curwin->w_topline = curbuf->b_ml.ml_line_count;
if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) }
if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) {
curwin->w_botline = curbuf->b_ml.ml_line_count + 1; curwin->w_botline = curbuf->b_ml.ml_line_count + 1;
}
check_topfill(curwin, false); check_topfill(curwin, false);
if (hasAnyFolding(curwin)) if (hasAnyFolding(curwin)) {
/* Make sure w_topline is at the first of a sequence of folded lines. */ // Make sure w_topline is at the first of a sequence of folded lines.
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
}
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
if (curwin->w_cursor.lnum < curwin->w_topline) { if (curwin->w_cursor.lnum < curwin->w_topline) {
@@ -1166,19 +1170,15 @@ bool scrollup(long line_count, int byfold)
} }
bool moved = topline != curwin->w_topline bool moved = topline != curwin->w_topline
|| botline != curwin->w_botline; || botline != curwin->w_botline;
return moved; return moved;
} }
/* /// Don't end up with too many filler lines in the window.
* Don't end up with too many filler lines in the window. ///
*/ /// @param down when true scroll down when not enough space
void void check_topfill(win_T *wp, bool down)
check_topfill (
win_T *wp,
bool down /* when true scroll down when not enough space */
)
{ {
if (wp->w_topfill > 0) { if (wp->w_topfill > 0) {
int n = plines_win_nofill(wp, wp->w_topline, true); int n = plines_win_nofill(wp, wp->w_topline, true);
@@ -1224,11 +1224,11 @@ void scrolldown_clamp(void)
< diff_check_fill(curwin, curwin->w_topline)); < diff_check_fill(curwin, curwin->w_topline));
if (curwin->w_topline <= 1 if (curwin->w_topline <= 1
&& !can_fill && !can_fill) {
)
return; return;
}
validate_cursor(); /* w_wrow needs to be valid */ validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the last row of the cursor line // Compute the row number of the last row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor // and make sure it doesn't go off the screen. Make sure the cursor
@@ -1254,7 +1254,7 @@ void scrolldown_clamp(void)
curwin->w_topfill = 0; curwin->w_topfill = 0;
} }
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
--curwin->w_botline; /* approximate w_botline */ --curwin->w_botline; // approximate w_botline
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
} }
} }
@@ -1266,11 +1266,11 @@ void scrolldown_clamp(void)
void scrollup_clamp(void) void scrollup_clamp(void)
{ {
if (curwin->w_topline == curbuf->b_ml.ml_line_count if (curwin->w_topline == curbuf->b_ml.ml_line_count
&& curwin->w_topfill == 0 && curwin->w_topfill == 0) {
)
return; return;
}
validate_cursor(); /* w_wrow needs to be valid */ validate_cursor(); // w_wrow needs to be valid
// Compute the row number of the first row of the cursor line // Compute the row number of the first row of the cursor line
// and make sure it doesn't go off the screen. Make sure the cursor // and make sure it doesn't go off the screen. Make sure the cursor
@@ -1381,15 +1381,16 @@ static void topline_botline(lineoff_T *lp)
void scroll_cursor_top(int min_scroll, int always) void scroll_cursor_top(int min_scroll, int always)
{ {
int scrolled = 0; int scrolled = 0;
linenr_T top; /* just above displayed lines */ linenr_T top; // just above displayed lines
linenr_T bot; /* just below displayed lines */ linenr_T bot; // just below displayed lines
linenr_T old_topline = curwin->w_topline; linenr_T old_topline = curwin->w_topline;
linenr_T old_topfill = curwin->w_topfill; linenr_T old_topfill = curwin->w_topfill;
linenr_T new_topline; linenr_T new_topline;
int off = (int)get_scrolloff_value(curwin); int off = (int)get_scrolloff_value(curwin);
if (mouse_dragging > 0) if (mouse_dragging > 0) {
off = mouse_dragging - 1; off = mouse_dragging - 1;
}
/* /*
* Decrease topline until: * Decrease topline until:
@@ -1446,8 +1447,9 @@ void scroll_cursor_top(int min_scroll, int always)
* If scrolling is needed, scroll at least 'sj' lines. * If scrolling is needed, scroll at least 'sj' lines.
*/ */
if ((new_topline >= curwin->w_topline || scrolled > min_scroll) if ((new_topline >= curwin->w_topline || scrolled > min_scroll)
&& extra >= off) && extra >= off) {
break; break;
}
extra += i; extra += i;
new_topline = top; new_topline = top;
@@ -1467,22 +1469,25 @@ void scroll_cursor_top(int min_scroll, int always)
* If "always" is false, only adjust topline to a lower value, higher * If "always" is false, only adjust topline to a lower value, higher
* value may happen with wrapping lines * value may happen with wrapping lines
*/ */
if (new_topline < curwin->w_topline || always) if (new_topline < curwin->w_topline || always) {
curwin->w_topline = new_topline; curwin->w_topline = new_topline;
if (curwin->w_topline > curwin->w_cursor.lnum) }
if (curwin->w_topline > curwin->w_cursor.lnum) {
curwin->w_topline = curwin->w_cursor.lnum; curwin->w_topline = curwin->w_cursor.lnum;
}
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
if (curwin->w_topfill > 0 && extra > off) { if (curwin->w_topfill > 0 && extra > off) {
curwin->w_topfill -= extra - off; curwin->w_topfill -= extra - off;
if (curwin->w_topfill < 0) if (curwin->w_topfill < 0) {
curwin->w_topfill = 0; curwin->w_topfill = 0;
}
} }
check_topfill(curwin, false); check_topfill(curwin, false);
if (curwin->w_topline != old_topline if (curwin->w_topline != old_topline
|| curwin->w_topfill != old_topfill || curwin->w_topfill != old_topfill) {
)
curwin->w_valid &= curwin->w_valid &=
~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
}
curwin->w_valid |= VALID_TOPLINE; curwin->w_valid |= VALID_TOPLINE;
curwin->w_viewport_invalid = true; curwin->w_viewport_invalid = true;
} }
@@ -1501,9 +1506,9 @@ void set_empty_rows(win_T *wp, int used)
wp->w_empty_rows = wp->w_height_inner - used; wp->w_empty_rows = wp->w_height_inner - used;
if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) { if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) {
wp->w_filler_rows = diff_check_fill(wp, wp->w_botline); wp->w_filler_rows = diff_check_fill(wp, wp->w_botline);
if (wp->w_empty_rows > wp->w_filler_rows) if (wp->w_empty_rows > wp->w_filler_rows) {
wp->w_empty_rows -= wp->w_filler_rows; wp->w_empty_rows -= wp->w_filler_rows;
else { } else {
wp->w_filler_rows = wp->w_empty_rows; wp->w_filler_rows = wp->w_empty_rows;
wp->w_empty_rows = 0; wp->w_empty_rows = 0;
} }
@@ -1552,9 +1557,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
set_empty_rows(curwin, used); set_empty_rows(curwin, used);
curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP;
if (curwin->w_topline != old_topline if (curwin->w_topline != old_topline
|| curwin->w_topfill != old_topfill || curwin->w_topfill != old_topfill) {
)
curwin->w_valid &= ~(VALID_WROW|VALID_CROW); curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
}
} else { } else {
validate_botline(curwin); validate_botline(curwin);
} }
@@ -1567,8 +1572,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
// botline. // botline.
if (cln >= curwin->w_botline) { if (cln >= curwin->w_botline) {
scrolled = used; scrolled = used;
if (cln == curwin->w_botline) if (cln == curwin->w_botline) {
scrolled -= curwin->w_empty_rows; scrolled -= curwin->w_empty_rows;
}
} }
/* /*
@@ -1595,8 +1601,7 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
|| boff.lnum + 1 > curbuf->b_ml.ml_line_count) || boff.lnum + 1 > curbuf->b_ml.ml_line_count)
&& loff.lnum <= curwin->w_botline && loff.lnum <= curwin->w_botline
&& (loff.lnum < curwin->w_botline && (loff.lnum < curwin->w_botline
|| loff.fill >= fill_below_window) || loff.fill >= fill_below_window)) {
) {
break; break;
} }
@@ -1612,9 +1617,8 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
} }
if (loff.lnum >= curwin->w_botline if (loff.lnum >= curwin->w_botline
&& (loff.lnum > curwin->w_botline && (loff.lnum > curwin->w_botline
|| loff.fill <= fill_below_window) || loff.fill <= fill_below_window)) {
) { // Count screen lines that are below the window.
/* Count screen lines that are below the window. */
scrolled += loff.height; scrolled += loff.height;
if (loff.lnum == curwin->w_botline if (loff.lnum == curwin->w_botline
&& loff.fill == 0) { && loff.fill == 0) {
@@ -1634,14 +1638,13 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
extra += boff.height; extra += boff.height;
if (boff.lnum >= curwin->w_botline if (boff.lnum >= curwin->w_botline
|| (boff.lnum + 1 == curwin->w_botline || (boff.lnum + 1 == curwin->w_botline
&& boff.fill > curwin->w_filler_rows) && boff.fill > curwin->w_filler_rows)) {
) { // Count screen lines that are below the window.
/* Count screen lines that are below the window. */
scrolled += boff.height; scrolled += boff.height;
if (boff.lnum == curwin->w_botline if (boff.lnum == curwin->w_botline
&& boff.fill == 0 && boff.fill == 0) {
)
scrolled -= curwin->w_empty_rows; scrolled -= curwin->w_empty_rows;
}
} }
} }
} }
@@ -1651,10 +1654,10 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
// curwin->w_empty_rows is larger, no need to scroll // curwin->w_empty_rows is larger, no need to scroll
if (scrolled <= 0) { if (scrolled <= 0) {
line_count = 0; line_count = 0;
// more than a screenfull, don't scroll but redraw // more than a screenfull, don't scroll but redraw
} else if (used > curwin->w_height_inner) { } else if (used > curwin->w_height_inner) {
line_count = used; line_count = used;
// scroll minimal number of lines // scroll minimal number of lines
} else { } else {
line_count = 0; line_count = 0;
boff.fill = curwin->w_topfill; boff.fill = curwin->w_topfill;
@@ -1665,8 +1668,9 @@ void scroll_cursor_bot(int min_scroll, int set_topbot)
i += boff.height; i += boff.height;
++line_count; ++line_count;
} }
if (i < scrolled) /* below curwin->w_botline, don't scroll */ if (i < scrolled) { // below curwin->w_botline, don't scroll
line_count = 9999; line_count = 9999;
}
} }
/* /*
@@ -1713,7 +1717,7 @@ void scroll_cursor_halfway(int atend)
boff.fill = 0; boff.fill = 0;
linenr_T topline = loff.lnum; linenr_T topline = loff.lnum;
while (topline > 1) { while (topline > 1) {
if (below <= above) { /* add a line below the cursor first */ if (below <= above) { // add a line below the cursor first
if (boff.lnum < curbuf->b_ml.ml_line_count) { if (boff.lnum < curbuf->b_ml.ml_line_count) {
botline_forw(curwin, &boff); botline_forw(curwin, &boff);
used += boff.height; used += boff.height;
@@ -1722,9 +1726,10 @@ void scroll_cursor_halfway(int atend)
} }
below += boff.height; below += boff.height;
} else { } else {
++below; /* count a "~" line */ ++below; // count a "~" line
if (atend) if (atend) {
++used; ++used;
}
} }
} }
@@ -1743,8 +1748,9 @@ void scroll_cursor_halfway(int atend)
topfill = loff.fill; topfill = loff.fill;
} }
} }
if (!hasFolding(topline, &curwin->w_topline, NULL)) if (!hasFolding(topline, &curwin->w_topline, NULL)) {
curwin->w_topline = topline; curwin->w_topline = topline;
}
curwin->w_topfill = topfill; curwin->w_topfill = topfill;
if (old_topline > curwin->w_topline + curwin->w_height_inner) { if (old_topline > curwin->w_topline + curwin->w_height_inner) {
curwin->w_botfill = false; curwin->w_botfill = false;
@@ -1793,12 +1799,12 @@ void cursor_correct(void)
* If there are sufficient file-lines above and below the cursor, we can * If there are sufficient file-lines above and below the cursor, we can
* return now. * return now.
*/ */
linenr_T cln = curwin->w_cursor.lnum; /* Cursor Line Number */ linenr_T cln = curwin->w_cursor.lnum; // Cursor Line Number
if (cln >= curwin->w_topline + above_wanted if (cln >= curwin->w_topline + above_wanted
&& cln < curwin->w_botline - below_wanted && cln < curwin->w_botline - below_wanted
&& !hasAnyFolding(curwin) && !hasAnyFolding(curwin)) {
)
return; return;
}
/* /*
* Narrow down the area where the cursor can be put by taking lines from * Narrow down the area where the cursor can be put by taking lines from
@@ -1808,9 +1814,9 @@ void cursor_correct(void)
*/ */
linenr_T topline = curwin->w_topline; linenr_T topline = curwin->w_topline;
linenr_T botline = curwin->w_botline - 1; linenr_T botline = curwin->w_botline - 1;
/* count filler lines as context */ // count filler lines as context
int above = curwin->w_topfill; /* screen lines above topline */ int above = curwin->w_topfill; // screen lines above topline
int below = curwin->w_filler_rows; /* screen lines below botline */ int below = curwin->w_filler_rows; // screen lines below botline
while ((above < above_wanted || below < below_wanted) && topline < botline) { while ((above < above_wanted || below < below_wanted) && topline < botline) {
if (below < below_wanted && (below <= above || above >= above_wanted)) { if (below < below_wanted && (below <= above || above >= above_wanted)) {
if (hasFolding(botline, &botline, NULL)) { if (hasFolding(botline, &botline, NULL)) {
@@ -1827,17 +1833,18 @@ void cursor_correct(void)
above += plines_win_nofill(curwin, topline, true); above += plines_win_nofill(curwin, topline, true);
} }
/* Count filler lines below this line as context. */ // Count filler lines below this line as context.
if (topline < botline) if (topline < botline) {
above += diff_check_fill(curwin, topline + 1); above += diff_check_fill(curwin, topline + 1);
}
++topline; ++topline;
} }
} }
if (topline == botline || botline == 0) if (topline == botline || botline == 0) {
curwin->w_cursor.lnum = topline; curwin->w_cursor.lnum = topline;
else if (topline > botline) } else if (topline > botline) {
curwin->w_cursor.lnum = botline; curwin->w_cursor.lnum = botline;
else { } else {
if (cln < topline && curwin->w_topline > 1) { if (cln < topline && curwin->w_topline > 1) {
curwin->w_cursor.lnum = topline; curwin->w_cursor.lnum = topline;
curwin->w_valid &= curwin->w_valid &=
@@ -1867,7 +1874,7 @@ int onepage(Direction dir, long count)
linenr_T old_topline = curwin->w_topline; linenr_T old_topline = curwin->w_topline;
long so = get_scrolloff_value(curwin); long so = get_scrolloff_value(curwin);
if (curbuf->b_ml.ml_line_count == 1) { /* nothing to do */ if (curbuf->b_ml.ml_line_count == 1) { // nothing to do
beep_flush(); beep_flush();
return FAIL; return FAIL;
} }
@@ -1893,16 +1900,18 @@ int onepage(Direction dir, long count)
loff.fill = 0; loff.fill = 0;
if (dir == FORWARD) { if (dir == FORWARD) {
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) { if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
/* Vi compatible scrolling */ // Vi compatible scrolling
if (p_window <= 2) if (p_window <= 2) {
++curwin->w_topline; ++curwin->w_topline;
else } else {
curwin->w_topline += p_window - 2; curwin->w_topline += p_window - 2;
if (curwin->w_topline > curbuf->b_ml.ml_line_count) }
if (curwin->w_topline > curbuf->b_ml.ml_line_count) {
curwin->w_topline = curbuf->b_ml.ml_line_count; curwin->w_topline = curbuf->b_ml.ml_line_count;
}
curwin->w_cursor.lnum = curwin->w_topline; curwin->w_cursor.lnum = curwin->w_topline;
} else if (curwin->w_botline > curbuf->b_ml.ml_line_count) { } else if (curwin->w_botline > curbuf->b_ml.ml_line_count) {
/* at end of file */ // at end of file
curwin->w_topline = curbuf->b_ml.ml_line_count; curwin->w_topline = curbuf->b_ml.ml_line_count;
curwin->w_topfill = 0; curwin->w_topfill = 0;
curwin->w_valid &= ~(VALID_WROW|VALID_CROW); curwin->w_valid &= ~(VALID_WROW|VALID_CROW);
@@ -1920,23 +1929,26 @@ int onepage(Direction dir, long count)
curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|
VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP);
} }
} else { /* dir == BACKWARDS */ } else { // dir == BACKWARDS
if (curwin->w_topline == 1) { if (curwin->w_topline == 1) {
/* Include max number of filler lines */ // Include max number of filler lines
max_topfill(); max_topfill();
continue; continue;
} }
if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) { if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) {
/* Vi compatible scrolling (sort of) */ // Vi compatible scrolling (sort of)
if (p_window <= 2) if (p_window <= 2) {
--curwin->w_topline; --curwin->w_topline;
else } else {
curwin->w_topline -= p_window - 2; curwin->w_topline -= p_window - 2;
if (curwin->w_topline < 1) }
if (curwin->w_topline < 1) {
curwin->w_topline = 1; curwin->w_topline = 1;
}
curwin->w_cursor.lnum = curwin->w_topline + p_window - 1; curwin->w_cursor.lnum = curwin->w_topline + p_window - 1;
if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) {
curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
}
continue; continue;
} }
@@ -1967,12 +1979,12 @@ int onepage(Direction dir, long count)
n += loff.height; n += loff.height;
} }
} }
if (loff.lnum < 1) { /* at begin of file */ if (loff.lnum < 1) { // at begin of file
curwin->w_topline = 1; curwin->w_topline = 1;
max_topfill(); max_topfill();
curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE);
} else { } else {
/* Go two lines forward again. */ // Go two lines forward again.
topline_botline(&loff); topline_botline(&loff);
botline_forw(curwin, &loff); botline_forw(curwin, &loff);
botline_forw(curwin, &loff); botline_forw(curwin, &loff);
@@ -1984,14 +1996,14 @@ int onepage(Direction dir, long count)
* very long lines. */ * very long lines. */
if (loff.lnum >= curwin->w_topline if (loff.lnum >= curwin->w_topline
&& (loff.lnum > curwin->w_topline && (loff.lnum > curwin->w_topline
|| loff.fill >= curwin->w_topfill) || loff.fill >= curwin->w_topfill)) {
) {
/* First try using the maximum number of filler lines. If /* First try using the maximum number of filler lines. If
* that's not enough, backup one line. */ * that's not enough, backup one line. */
loff.fill = curwin->w_topfill; loff.fill = curwin->w_topfill;
if (curwin->w_topfill < diff_check_fill(curwin, if (curwin->w_topfill < diff_check_fill(curwin,
curwin->w_topline)) curwin->w_topline)) {
max_topfill(); max_topfill();
}
if (curwin->w_topfill == loff.fill) { if (curwin->w_topfill == loff.fill) {
--curwin->w_topline; --curwin->w_topline;
curwin->w_topfill = 0; curwin->w_topfill = 0;
@@ -2042,12 +2054,12 @@ int onepage(Direction dir, long count)
* This is symmetric, so that doing both keeps the same lines displayed. * This is symmetric, so that doing both keeps the same lines displayed.
* Three lines are examined: * Three lines are examined:
* *
* before CTRL-F after CTRL-F / before CTRL-B * before CTRL-F after CTRL-F / before CTRL-B
* etc. l1 * etc. l1
* l1 last but one line ------------ * l1 last but one line ------------
* l2 last text line l2 top text line * l2 last text line l2 top text line
* ------------- l3 second text line * ------------- l3 second text line
* l3 etc. * l3 etc.
*/ */
static void get_scroll_overlap(lineoff_T *lp, int dir) static void get_scroll_overlap(lineoff_T *lp, int dir)
{ {
@@ -2059,9 +2071,9 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
lp->height = plines_win_nofill(curwin, lp->lnum, true); lp->height = plines_win_nofill(curwin, lp->lnum, true);
} }
int h1 = lp->height; int h1 = lp->height;
if (h1 > min_height) if (h1 > min_height) {
return; /* no overlap */ return; // no overlap
}
lineoff_T loff0 = *lp; lineoff_T loff0 = *lp;
if (dir > 0) { if (dir > 0) {
botline_forw(curwin, lp); botline_forw(curwin, lp);
@@ -2070,7 +2082,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
} }
int h2 = lp->height; int h2 = lp->height;
if (h2 == MAXCOL || h2 + h1 > min_height) { if (h2 == MAXCOL || h2 + h1 > min_height) {
*lp = loff0; /* no overlap */ *lp = loff0; // no overlap
return; return;
} }
@@ -2082,7 +2094,7 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
} }
int h3 = lp->height; int h3 = lp->height;
if (h3 == MAXCOL || h3 + h2 > min_height) { if (h3 == MAXCOL || h3 + h2 > min_height) {
*lp = loff0; /* no overlap */ *lp = loff0; // no overlap
return; return;
} }
@@ -2093,10 +2105,11 @@ static void get_scroll_overlap(lineoff_T *lp, int dir)
topline_back(curwin, lp); topline_back(curwin, lp);
} }
int h4 = lp->height; int h4 = lp->height;
if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) {
*lp = loff1; /* 1 line overlap */ *lp = loff1; // 1 line overlap
else } else {
*lp = loff2; /* 2 lines overlap */ *lp = loff2; // 2 lines overlap
}
return; return;
} }
@@ -2108,11 +2121,11 @@ void halfpage(bool flag, linenr_T Prenum)
if (Prenum) { if (Prenum) {
curwin->w_p_scr = (Prenum > curwin->w_height_inner) ? curwin->w_height_inner curwin->w_p_scr = (Prenum > curwin->w_height_inner) ? curwin->w_height_inner
: Prenum; : Prenum;
} }
assert(curwin->w_p_scr <= INT_MAX); assert(curwin->w_p_scr <= INT_MAX);
int n = curwin->w_p_scr <= curwin->w_height_inner ? (int)curwin->w_p_scr int n = curwin->w_p_scr <= curwin->w_height_inner ? (int)curwin->w_p_scr
: curwin->w_height_inner; : curwin->w_height_inner;
update_topline(curwin); update_topline(curwin);
validate_botline(curwin); validate_botline(curwin);
@@ -2129,8 +2142,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else { } else {
i = plines_win_nofill(curwin, curwin->w_topline, true); i = plines_win_nofill(curwin, curwin->w_topline, true);
n -= i; n -= i;
if (n < 0 && scrolled > 0) if (n < 0 && scrolled > 0) {
break; break;
}
(void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline);
++curwin->w_topline; ++curwin->w_topline;
curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline);
@@ -2148,9 +2162,9 @@ void halfpage(bool flag, linenr_T Prenum)
* Correct w_botline for changed w_topline. * Correct w_botline for changed w_topline.
* Won't work when there are filler lines. * Won't work when there are filler lines.
*/ */
if (curwin->w_p_diff) if (curwin->w_p_diff) {
curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP);
else { } else {
room += i; room += i;
do { do {
i = plines_win(curwin, curwin->w_botline, true); i = plines_win(curwin, curwin->w_botline, true);
@@ -2170,11 +2184,12 @@ void halfpage(bool flag, linenr_T Prenum)
while (--n >= 0 while (--n >= 0
&& curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) { && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) {
(void)hasFolding(curwin->w_cursor.lnum, NULL, (void)hasFolding(curwin->w_cursor.lnum, NULL,
&curwin->w_cursor.lnum); &curwin->w_cursor.lnum);
++curwin->w_cursor.lnum; ++curwin->w_cursor.lnum;
} }
} else } else {
curwin->w_cursor.lnum += n; curwin->w_cursor.lnum += n;
}
check_cursor_lnum(); check_cursor_lnum();
} }
} else { } else {
@@ -2189,8 +2204,9 @@ void halfpage(bool flag, linenr_T Prenum)
} else { } else {
i = plines_win_nofill(curwin, curwin->w_topline - 1, true); i = plines_win_nofill(curwin, curwin->w_topline - 1, true);
n -= i; n -= i;
if (n < 0 && scrolled > 0) if (n < 0 && scrolled > 0) {
break; break;
}
--curwin->w_topline; --curwin->w_topline;
(void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL);
curwin->w_topfill = 0; curwin->w_topfill = 0;
@@ -2206,19 +2222,20 @@ void halfpage(bool flag, linenr_T Prenum)
// When hit top of the file: move cursor up. // When hit top of the file: move cursor up.
if (n > 0) { if (n > 0) {
if (curwin->w_cursor.lnum <= (linenr_T)n) if (curwin->w_cursor.lnum <= (linenr_T)n) {
curwin->w_cursor.lnum = 1; curwin->w_cursor.lnum = 1;
else if (hasAnyFolding(curwin)) { } else if (hasAnyFolding(curwin)) {
while (--n >= 0 && curwin->w_cursor.lnum > 1) { while (--n >= 0 && curwin->w_cursor.lnum > 1) {
--curwin->w_cursor.lnum; --curwin->w_cursor.lnum;
(void)hasFolding(curwin->w_cursor.lnum, (void)hasFolding(curwin->w_cursor.lnum,
&curwin->w_cursor.lnum, NULL); &curwin->w_cursor.lnum, NULL);
} }
} else } else {
curwin->w_cursor.lnum -= n; curwin->w_cursor.lnum -= n;
}
} }
} }
/* Move cursor to first line of closed fold. */ // Move cursor to first line of closed fold.
foldAdjustCursor(); foldAdjustCursor();
check_topfill(curwin, !flag); check_topfill(curwin, !flag);
cursor_correct(); cursor_correct();
@@ -2245,7 +2262,7 @@ void do_check_cursorbind(void)
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
curwin = wp; curwin = wp;
curbuf = curwin->w_buffer; curbuf = curwin->w_buffer;
/* skip original window and windows with 'noscrollbind' */ // skip original window and windows with 'noscrollbind'
if (curwin != old_curwin && curwin->w_p_crb) { if (curwin != old_curwin && curwin->w_p_crb) {
if (curwin->w_p_diff) { if (curwin->w_p_diff) {
curwin->w_cursor.lnum = curwin->w_cursor.lnum =