mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #5266 from bfredl/kbtree
add kbtree_t and use it for bufhl
This commit is contained in:
commit
ca385db4d0
@ -2529,6 +2529,8 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error):
|
|||||||
r'(?<!\bklist_t)'
|
r'(?<!\bklist_t)'
|
||||||
r'(?<!\bkliter_t)'
|
r'(?<!\bkliter_t)'
|
||||||
r'(?<!\bkhash_t)'
|
r'(?<!\bkhash_t)'
|
||||||
|
r'(?<!\bkbtree_t)'
|
||||||
|
r'(?<!\bkbitr_t)'
|
||||||
r'\((?:const )?(?:struct )?[a-zA-Z_]\w*(?: *\*(?:const)?)*\)'
|
r'\((?:const )?(?:struct )?[a-zA-Z_]\w*(?: *\*(?:const)?)*\)'
|
||||||
r' +'
|
r' +'
|
||||||
r'-?(?:\*+|&)?(?:\w+|\+\+|--|\()', cast_line)
|
r'-?(?:\*+|&)?(?:\w+|\+\+|--|\()', cast_line)
|
||||||
|
@ -399,7 +399,7 @@ void nvim_buf_set_lines(uint64_t channel_id,
|
|||||||
// Only adjust marks if we managed to switch to a window that holds
|
// Only adjust marks if we managed to switch to a window that holds
|
||||||
// the buffer, otherwise line numbers will be invalid.
|
// the buffer, otherwise line numbers will be invalid.
|
||||||
if (save_curbuf.br_buf == NULL) {
|
if (save_curbuf.br_buf == NULL) {
|
||||||
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra);
|
mark_adjust((linenr_T)start, (linenr_T)(end - 1), MAXLNUM, extra, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
|
changed_lines((linenr_T)start, 0, (linenr_T)end, (long)extra);
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/api/private/defs.h"
|
#include "nvim/api/private/defs.h"
|
||||||
|
#include "nvim/api/private/dispatch.h"
|
||||||
#include "nvim/api/buffer.h"
|
#include "nvim/api/buffer.h"
|
||||||
#include "nvim/msgpack_rpc/channel.h"
|
#include "nvim/msgpack_rpc/channel.h"
|
||||||
#include "nvim/lua/executor.h"
|
#include "nvim/lua/executor.h"
|
||||||
|
@ -74,6 +74,12 @@
|
|||||||
#include "nvim/os/time.h"
|
#include "nvim/os/time.h"
|
||||||
#include "nvim/os/input.h"
|
#include "nvim/os/input.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
kBLSUnchanged = 0,
|
||||||
|
kBLSChanged = 1,
|
||||||
|
kBLSDeleted = 2,
|
||||||
|
} BufhlLineStatus;
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
# include "buffer.c.generated.h"
|
# include "buffer.c.generated.h"
|
||||||
#endif
|
#endif
|
||||||
@ -5138,6 +5144,30 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a
|
|||||||
|
|
||||||
// bufhl: plugin highlights associated with a buffer
|
// bufhl: plugin highlights associated with a buffer
|
||||||
|
|
||||||
|
/// Get reference to line in kbtree_t
|
||||||
|
///
|
||||||
|
/// @param b the three
|
||||||
|
/// @param line the linenumber to lookup
|
||||||
|
/// @param put if true, put a new line when not found
|
||||||
|
/// if false, return NULL when not found
|
||||||
|
BufhlLine *bufhl_tree_ref(BufhlInfo *b, linenr_T line, bool put)
|
||||||
|
{
|
||||||
|
BufhlLine t = BUFHLLINE_INIT(line);
|
||||||
|
|
||||||
|
// kp_put() only works if key is absent, try get first
|
||||||
|
BufhlLine **pp = kb_get(bufhl, b, &t);
|
||||||
|
if (pp) {
|
||||||
|
return *pp;
|
||||||
|
} else if (!put) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
BufhlLine *p = xmalloc(sizeof(*p));
|
||||||
|
*p = (BufhlLine)BUFHLLINE_INIT(line);
|
||||||
|
kb_put(bufhl, b, p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a highlight to buffer.
|
/// Adds a highlight to buffer.
|
||||||
///
|
///
|
||||||
/// Unlike matchaddpos() highlights follow changes to line numbering (as lines
|
/// Unlike matchaddpos() highlights follow changes to line numbering (as lines
|
||||||
@ -5175,13 +5205,10 @@ int bufhl_add_hl(buf_T *buf,
|
|||||||
// no highlight group or invalid line, just return src_id
|
// no highlight group or invalid line, just return src_id
|
||||||
return src_id;
|
return src_id;
|
||||||
}
|
}
|
||||||
if (!buf->b_bufhl_info) {
|
|
||||||
buf->b_bufhl_info = map_new(linenr_T, bufhl_vec_T)();
|
|
||||||
}
|
|
||||||
bufhl_vec_T* lineinfo = map_ref(linenr_T, bufhl_vec_T)(buf->b_bufhl_info,
|
|
||||||
lnum, true);
|
|
||||||
|
|
||||||
bufhl_hl_item_T *hlentry = kv_pushp(*lineinfo);
|
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, true);
|
||||||
|
|
||||||
|
BufhlItem *hlentry = kv_pushp(lineinfo->items);
|
||||||
hlentry->src_id = src_id;
|
hlentry->src_id = src_id;
|
||||||
hlentry->hl_id = hl_id;
|
hlentry->hl_id = hl_id;
|
||||||
hlentry->start = col_start;
|
hlentry->start = col_start;
|
||||||
@ -5203,20 +5230,24 @@ int bufhl_add_hl(buf_T *buf,
|
|||||||
void bufhl_clear_line_range(buf_T *buf,
|
void bufhl_clear_line_range(buf_T *buf,
|
||||||
int src_id,
|
int src_id,
|
||||||
linenr_T line_start,
|
linenr_T line_start,
|
||||||
linenr_T line_end) {
|
linenr_T line_end)
|
||||||
if (!buf->b_bufhl_info) {
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
linenr_T line;
|
|
||||||
linenr_T first_changed = MAXLNUM, last_changed = -1;
|
linenr_T first_changed = MAXLNUM, last_changed = -1;
|
||||||
// In the case line_start - line_end << bufhl_info->size
|
|
||||||
// it might be better to reverse this, i e loop over the lines
|
kbitr_t(bufhl) itr;
|
||||||
// to clear on.
|
BufhlLine *l, t = BUFHLLINE_INIT(line_start);
|
||||||
bufhl_vec_T unused;
|
if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) {
|
||||||
map_foreach(buf->b_bufhl_info, line, unused, {
|
kb_itr_next(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
(void)unused;
|
}
|
||||||
|
for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) {
|
||||||
|
l = kb_itr_key(&itr);
|
||||||
|
linenr_T line = l->line;
|
||||||
|
if (line > line_end) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (line_start <= line && line <= line_end) {
|
if (line_start <= line && line <= line_end) {
|
||||||
if (bufhl_clear_line(buf->b_bufhl_info, src_id, line)) {
|
BufhlLineStatus status = bufhl_clear_line(l, src_id, line);
|
||||||
|
if (status != kBLSUnchanged) {
|
||||||
if (line > last_changed) {
|
if (line > last_changed) {
|
||||||
last_changed = line;
|
last_changed = line;
|
||||||
}
|
}
|
||||||
@ -5224,8 +5255,12 @@ void bufhl_clear_line_range(buf_T *buf,
|
|||||||
first_changed = line;
|
first_changed = line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (status == kBLSDeleted) {
|
||||||
|
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
|
xfree(l);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
if (last_changed != -1) {
|
if (last_changed != -1) {
|
||||||
changed_lines_buf(buf, first_changed, last_changed+1, 0);
|
changed_lines_buf(buf, first_changed, last_changed+1, 0);
|
||||||
@ -5238,42 +5273,40 @@ void bufhl_clear_line_range(buf_T *buf,
|
|||||||
/// @param bufhl_info The highlight info for the buffer
|
/// @param bufhl_info The highlight info for the buffer
|
||||||
/// @param src_id Highlight source group to clear, or -1 to clear all groups.
|
/// @param src_id Highlight source group to clear, or -1 to clear all groups.
|
||||||
/// @param lnum Linenr where the highlight should be cleared
|
/// @param lnum Linenr where the highlight should be cleared
|
||||||
static bool bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id,
|
static BufhlLineStatus bufhl_clear_line(BufhlLine *lineinfo, int src_id,
|
||||||
linenr_T lnum)
|
linenr_T lnum)
|
||||||
{
|
{
|
||||||
bufhl_vec_T *lineinfo = map_ref(linenr_T, bufhl_vec_T)(bufhl_info,
|
size_t oldsize = kv_size(lineinfo->items);
|
||||||
lnum, false);
|
|
||||||
size_t oldsize = kv_size(*lineinfo);
|
|
||||||
if (src_id < 0) {
|
if (src_id < 0) {
|
||||||
kv_size(*lineinfo) = 0;
|
kv_size(lineinfo->items) = 0;
|
||||||
} else {
|
} else {
|
||||||
size_t newind = 0;
|
size_t newidx = 0;
|
||||||
for (size_t i = 0; i < kv_size(*lineinfo); i++) {
|
for (size_t i = 0; i < kv_size(lineinfo->items); i++) {
|
||||||
if (kv_A(*lineinfo, i).src_id != src_id) {
|
if (kv_A(lineinfo->items, i).src_id != src_id) {
|
||||||
if (i != newind) {
|
if (i != newidx) {
|
||||||
kv_A(*lineinfo, newind) = kv_A(*lineinfo, i);
|
kv_A(lineinfo->items, newidx) = kv_A(lineinfo->items, i);
|
||||||
}
|
}
|
||||||
newind++;
|
newidx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kv_size(*lineinfo) = newind;
|
kv_size(lineinfo->items) = newidx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kv_size(*lineinfo) == 0) {
|
if (kv_size(lineinfo->items) == 0) {
|
||||||
kv_destroy(*lineinfo);
|
kv_destroy(lineinfo->items);
|
||||||
map_del(linenr_T, bufhl_vec_T)(bufhl_info, lnum);
|
return kBLSDeleted;
|
||||||
}
|
}
|
||||||
return kv_size(*lineinfo) != oldsize;
|
return kv_size(lineinfo->items) != oldsize ? kBLSChanged : kBLSUnchanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all highlights and free the highlight data
|
/// Remove all highlights and free the highlight data
|
||||||
void bufhl_clear_all(buf_T* buf) {
|
void bufhl_clear_all(buf_T *buf)
|
||||||
if (!buf->b_bufhl_info) {
|
{
|
||||||
return;
|
|
||||||
}
|
|
||||||
bufhl_clear_line_range(buf, -1, 1, MAXLNUM);
|
bufhl_clear_line_range(buf, -1, 1, MAXLNUM);
|
||||||
map_free(linenr_T, bufhl_vec_T)(buf->b_bufhl_info);
|
kb_destroy(bufhl, (&buf->b_bufhl_info));
|
||||||
buf->b_bufhl_info = NULL;
|
kb_init(&buf->b_bufhl_info);
|
||||||
|
kv_destroy(buf->b_bufhl_move_space);
|
||||||
|
kv_init(buf->b_bufhl_move_space);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adjust a placed highlight for inserted/deleted lines.
|
/// Adjust a placed highlight for inserted/deleted lines.
|
||||||
@ -5281,29 +5314,49 @@ void bufhl_mark_adjust(buf_T* buf,
|
|||||||
linenr_T line1,
|
linenr_T line1,
|
||||||
linenr_T line2,
|
linenr_T line2,
|
||||||
long amount,
|
long amount,
|
||||||
long amount_after) {
|
long amount_after,
|
||||||
if (!buf->b_bufhl_info) {
|
bool end_temp)
|
||||||
|
{
|
||||||
|
kbitr_t(bufhl) itr;
|
||||||
|
BufhlLine *l, t = BUFHLLINE_INIT(line1);
|
||||||
|
if (end_temp && amount < 0) {
|
||||||
|
// Move all items from b_bufhl_move_space to the btree.
|
||||||
|
for (size_t i = 0; i < kv_size(buf->b_bufhl_move_space); i++) {
|
||||||
|
l = kv_A(buf->b_bufhl_move_space, i);
|
||||||
|
l->line += amount;
|
||||||
|
kb_put(bufhl, &buf->b_bufhl_info, l);
|
||||||
|
}
|
||||||
|
kv_size(buf->b_bufhl_move_space) = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bufhl_info_T *newmap = map_new(linenr_T, bufhl_vec_T)();
|
if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) {
|
||||||
linenr_T line;
|
kb_itr_next(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
bufhl_vec_T lineinfo;
|
}
|
||||||
map_foreach(buf->b_bufhl_info, line, lineinfo, {
|
for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) {
|
||||||
if (line >= line1 && line <= line2) {
|
l = kb_itr_key(&itr);
|
||||||
if (amount == MAXLNUM) {
|
if (l->line >= line1 && l->line <= line2) {
|
||||||
bufhl_clear_line(buf->b_bufhl_info, -1, line);
|
if (end_temp && amount > 0) {
|
||||||
continue;
|
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
} else {
|
kv_push(buf->b_bufhl_move_space, l);
|
||||||
line += amount;
|
|
||||||
}
|
}
|
||||||
} else if (line > line2) {
|
if (amount == MAXLNUM) {
|
||||||
line += amount_after;
|
if (bufhl_clear_line(l, -1, l->line) == kBLSDeleted) {
|
||||||
|
kb_del_itr(bufhl, &buf->b_bufhl_info, &itr);
|
||||||
|
xfree(l);
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
l->line += amount;
|
||||||
|
}
|
||||||
|
} else if (l->line > line2) {
|
||||||
|
if (amount_after == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
l->line += amount_after;
|
||||||
}
|
}
|
||||||
map_put(linenr_T, bufhl_vec_T)(newmap, line, lineinfo);
|
}
|
||||||
});
|
|
||||||
map_free(linenr_T, bufhl_vec_T)(buf->b_bufhl_info);
|
|
||||||
buf->b_bufhl_info = newmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -5313,13 +5366,14 @@ void bufhl_mark_adjust(buf_T* buf,
|
|||||||
/// @param lnum The line number
|
/// @param lnum The line number
|
||||||
/// @param[out] info The highligts for the line
|
/// @param[out] info The highligts for the line
|
||||||
/// @return true if there was highlights to display
|
/// @return true if there was highlights to display
|
||||||
bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) {
|
bool bufhl_start_line(buf_T *buf, linenr_T lnum, BufhlLineInfo *info)
|
||||||
if (!buf->b_bufhl_info) {
|
{
|
||||||
|
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, false);
|
||||||
|
if (!lineinfo) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
info->valid_to = -1;
|
info->valid_to = -1;
|
||||||
info->entries = map_get(linenr_T, bufhl_vec_T)(buf->b_bufhl_info, lnum);
|
info->entries = lineinfo->items;
|
||||||
return kv_size(info->entries) > 0;
|
return kv_size(info->entries) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5333,14 +5387,15 @@ bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) {
|
|||||||
/// @param info The info returned by bufhl_start_line
|
/// @param info The info returned by bufhl_start_line
|
||||||
/// @param col The column to get the attr for
|
/// @param col The column to get the attr for
|
||||||
/// @return The highilight attr to display at the column
|
/// @return The highilight attr to display at the column
|
||||||
int bufhl_get_attr(bufhl_lineinfo_T *info, colnr_T col) {
|
int bufhl_get_attr(BufhlLineInfo *info, colnr_T col)
|
||||||
|
{
|
||||||
if (col <= info->valid_to) {
|
if (col <= info->valid_to) {
|
||||||
return info->current;
|
return info->current;
|
||||||
}
|
}
|
||||||
int attr = 0;
|
int attr = 0;
|
||||||
info->valid_to = MAXCOL;
|
info->valid_to = MAXCOL;
|
||||||
for (size_t i = 0; i < kv_size(info->entries); i++) {
|
for (size_t i = 0; i < kv_size(info->entries); i++) {
|
||||||
bufhl_hl_item_T entry = kv_A(info->entries, i);
|
BufhlItem entry = kv_A(info->entries, i);
|
||||||
if (entry.start <= col && col <= entry.stop) {
|
if (entry.start <= col && col <= entry.stop) {
|
||||||
int entry_attr = syn_id2attr(entry.hl_id);
|
int entry_attr = syn_id2attr(entry.hl_id);
|
||||||
attr = hl_combine_attr(attr, entry_attr);
|
attr = hl_combine_attr(attr, entry_attr);
|
||||||
|
@ -106,8 +106,6 @@ typedef struct frame_S frame_T;
|
|||||||
// for bufhl_*_T
|
// for bufhl_*_T
|
||||||
#include "nvim/bufhl_defs.h"
|
#include "nvim/bufhl_defs.h"
|
||||||
|
|
||||||
typedef Map(linenr_T, bufhl_vec_T) bufhl_info_T;
|
|
||||||
|
|
||||||
#include "nvim/os/fs_defs.h" // for FileID
|
#include "nvim/os/fs_defs.h" // for FileID
|
||||||
#include "nvim/terminal.h" // for Terminal
|
#include "nvim/terminal.h" // for Terminal
|
||||||
|
|
||||||
@ -762,7 +760,9 @@ struct file_buffer {
|
|||||||
|
|
||||||
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
int b_mapped_ctrl_c; // modes where CTRL-C is mapped
|
||||||
|
|
||||||
bufhl_info_T *b_bufhl_info; // buffer stored highlights
|
BufhlInfo b_bufhl_info; // buffer stored highlights
|
||||||
|
|
||||||
|
kvec_t(BufhlLine *) b_bufhl_move_space; // temporary space for highlights
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -3,23 +3,32 @@
|
|||||||
|
|
||||||
#include "nvim/pos.h"
|
#include "nvim/pos.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
|
#include "nvim/lib/kbtree.h"
|
||||||
|
|
||||||
// bufhl: buffer specific highlighting
|
// bufhl: buffer specific highlighting
|
||||||
|
|
||||||
struct bufhl_hl_item
|
typedef struct {
|
||||||
{
|
|
||||||
int src_id;
|
int src_id;
|
||||||
int hl_id; // highlight group
|
int hl_id; // highlight group
|
||||||
colnr_T start; // first column to highlight
|
colnr_T start; // first column to highlight
|
||||||
colnr_T stop; // last column to highlight
|
colnr_T stop; // last column to highlight
|
||||||
};
|
} BufhlItem;
|
||||||
typedef struct bufhl_hl_item bufhl_hl_item_T;
|
|
||||||
|
|
||||||
typedef kvec_t(struct bufhl_hl_item) bufhl_vec_T;
|
typedef kvec_t(BufhlItem) BufhlItemVec;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bufhl_vec_T entries;
|
linenr_T line;
|
||||||
|
BufhlItemVec items;
|
||||||
|
} BufhlLine;
|
||||||
|
#define BUFHLLINE_INIT(l) { l, KV_INITIAL_VALUE }
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BufhlItemVec entries;
|
||||||
int current;
|
int current;
|
||||||
colnr_T valid_to;
|
colnr_T valid_to;
|
||||||
} bufhl_lineinfo_T;
|
} BufhlLineInfo;
|
||||||
|
|
||||||
|
#define BUFHL_CMP(a, b) ((int)(((a)->line - (b)->line)))
|
||||||
|
KBTREE_INIT(bufhl, BufhlLine *, BUFHL_CMP, 10)
|
||||||
|
typedef kbtree_t(bufhl) BufhlInfo;
|
||||||
#endif // NVIM_BUFHL_DEFS_H
|
#endif // NVIM_BUFHL_DEFS_H
|
||||||
|
@ -2311,7 +2311,7 @@ void ex_diffgetput(exarg_T *eap)
|
|||||||
|
|
||||||
// Adjust marks. This will change the following entries!
|
// Adjust marks. This will change the following entries!
|
||||||
if (added != 0) {
|
if (added != 0) {
|
||||||
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added);
|
mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added, false);
|
||||||
if (curwin->w_cursor.lnum >= lnum) {
|
if (curwin->w_cursor.lnum >= lnum) {
|
||||||
// Adjust the cursor position if it's in/after the changed
|
// Adjust the cursor position if it's in/after the changed
|
||||||
// lines.
|
// lines.
|
||||||
|
@ -597,9 +597,10 @@ void ex_sort(exarg_T *eap)
|
|||||||
// Adjust marks for deleted (or added) lines and prepare for displaying.
|
// Adjust marks for deleted (or added) lines and prepare for displaying.
|
||||||
deleted = (long)(count - (lnum - eap->line2));
|
deleted = (long)(count - (lnum - eap->line2));
|
||||||
if (deleted > 0) {
|
if (deleted > 0) {
|
||||||
mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted);
|
mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted,
|
||||||
|
false);
|
||||||
} else if (deleted < 0) {
|
} else if (deleted < 0) {
|
||||||
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L);
|
mark_adjust(eap->line2, MAXLNUM, -deleted, 0L, false);
|
||||||
}
|
}
|
||||||
changed_lines(eap->line1, 0, eap->line2 + 1, -deleted);
|
changed_lines(eap->line1, 0, eap->line2 + 1, -deleted);
|
||||||
|
|
||||||
@ -794,9 +795,9 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
* their final destination at the new text position -- webb
|
* their final destination at the new text position -- webb
|
||||||
*/
|
*/
|
||||||
last_line = curbuf->b_ml.ml_line_count;
|
last_line = curbuf->b_ml.ml_line_count;
|
||||||
mark_adjust_nofold(line1, line2, last_line - line2, 0L);
|
mark_adjust_nofold(line1, line2, last_line - line2, 0L, true);
|
||||||
if (dest >= line2) {
|
if (dest >= line2) {
|
||||||
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L);
|
mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L, false);
|
||||||
FOR_ALL_TAB_WINDOWS(tab, win) {
|
FOR_ALL_TAB_WINDOWS(tab, win) {
|
||||||
if (win->w_buffer == curbuf) {
|
if (win->w_buffer == curbuf) {
|
||||||
foldMoveRange(&win->w_folds, line1, line2, dest);
|
foldMoveRange(&win->w_folds, line1, line2, dest);
|
||||||
@ -805,7 +806,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
curbuf->b_op_start.lnum = dest - num_lines + 1;
|
curbuf->b_op_start.lnum = dest - num_lines + 1;
|
||||||
curbuf->b_op_end.lnum = dest;
|
curbuf->b_op_end.lnum = dest;
|
||||||
} else {
|
} else {
|
||||||
mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L);
|
mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L, false);
|
||||||
FOR_ALL_TAB_WINDOWS(tab, win) {
|
FOR_ALL_TAB_WINDOWS(tab, win) {
|
||||||
if (win->w_buffer == curbuf) {
|
if (win->w_buffer == curbuf) {
|
||||||
foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
|
foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2);
|
||||||
@ -816,7 +817,7 @@ int do_move(linenr_T line1, linenr_T line2, linenr_T dest)
|
|||||||
}
|
}
|
||||||
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
|
curbuf->b_op_start.col = curbuf->b_op_end.col = 0;
|
||||||
mark_adjust_nofold(last_line - num_lines + 1, last_line,
|
mark_adjust_nofold(last_line - num_lines + 1, last_line,
|
||||||
-(last_line - dest - extra), 0L);
|
-(last_line - dest - extra), 0L, true);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Now we delete the original text -- webb
|
* Now we delete the original text -- webb
|
||||||
@ -1212,15 +1213,14 @@ static void do_filter(
|
|||||||
|
|
||||||
if (do_in) {
|
if (do_in) {
|
||||||
if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) {
|
if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) {
|
||||||
if (read_linecount >= linecount)
|
if (read_linecount >= linecount) {
|
||||||
/* move all marks from old lines to new lines */
|
// move all marks from old lines to new lines
|
||||||
mark_adjust(line1, line2, linecount, 0L);
|
mark_adjust(line1, line2, linecount, 0L, false);
|
||||||
else {
|
} else {
|
||||||
/* move marks from old lines to new lines, delete marks
|
// move marks from old lines to new lines, delete marks
|
||||||
* that are in deleted lines */
|
// that are in deleted lines
|
||||||
mark_adjust(line1, line1 + read_linecount - 1,
|
mark_adjust(line1, line1 + read_linecount - 1, linecount, 0L, false);
|
||||||
linecount, 0L);
|
mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L, false);
|
||||||
mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3758,7 +3758,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout)
|
|||||||
*p1 = NUL; // truncate up to the CR
|
*p1 = NUL; // truncate up to the CR
|
||||||
ml_append(lnum - 1, new_start,
|
ml_append(lnum - 1, new_start,
|
||||||
(colnr_T)(p1 - new_start + 1), false);
|
(colnr_T)(p1 - new_start + 1), false);
|
||||||
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
|
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, false);
|
||||||
if (subflags.do_ask) {
|
if (subflags.do_ask) {
|
||||||
appended_lines(lnum - 1, 1L);
|
appended_lines(lnum - 1, 1L);
|
||||||
} else {
|
} else {
|
||||||
@ -3847,7 +3847,7 @@ skip:
|
|||||||
for (i = 0; i < nmatch_tl; ++i)
|
for (i = 0; i < nmatch_tl; ++i)
|
||||||
ml_delete(lnum, (int)FALSE);
|
ml_delete(lnum, (int)FALSE);
|
||||||
mark_adjust(lnum, lnum + nmatch_tl - 1,
|
mark_adjust(lnum, lnum + nmatch_tl - 1,
|
||||||
(long)MAXLNUM, -nmatch_tl);
|
(long)MAXLNUM, -nmatch_tl, false);
|
||||||
if (subflags.do_ask) {
|
if (subflags.do_ask) {
|
||||||
deleted_lines(lnum, nmatch_tl);
|
deleted_lines(lnum, nmatch_tl);
|
||||||
}
|
}
|
||||||
|
451
src/nvim/lib/kbtree.h
Normal file
451
src/nvim/lib/kbtree.h
Normal file
@ -0,0 +1,451 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright 1997-1999, 2001, John-Mark Gurney.
|
||||||
|
* 2008-2009, Attractive Chaos <attractor@live.co.uk>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||||
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||||
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||||
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||||
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
|
* SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NVIM_LIB_KBTREE_H
|
||||||
|
#define NVIM_LIB_KBTREE_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include "nvim/memory.h"
|
||||||
|
|
||||||
|
#define KB_MAX_DEPTH 64
|
||||||
|
|
||||||
|
#define __KB_KEY(type, x) (x->key)
|
||||||
|
#define __KB_PTR(btr, x) (x->ptr)
|
||||||
|
|
||||||
|
#define __KB_TREE_T(name,key_t,T) \
|
||||||
|
typedef struct kbnode_##name##_s kbnode_##name##_t; \
|
||||||
|
struct kbnode_##name##_s { \
|
||||||
|
int32_t n; \
|
||||||
|
bool is_internal; \
|
||||||
|
key_t key[2*T-1]; \
|
||||||
|
kbnode_##name##_t *ptr[]; \
|
||||||
|
} ; \
|
||||||
|
\
|
||||||
|
typedef struct { \
|
||||||
|
kbnode_##name##_t *root; \
|
||||||
|
int n_keys, n_nodes; \
|
||||||
|
} kbtree_##name##_t; \
|
||||||
|
\
|
||||||
|
typedef struct { \
|
||||||
|
kbnode_##name##_t *x; \
|
||||||
|
int i; \
|
||||||
|
} kbpos_##name##_t; \
|
||||||
|
typedef struct { \
|
||||||
|
kbpos_##name##_t stack[KB_MAX_DEPTH], *p; \
|
||||||
|
} kbitr_##name##_t; \
|
||||||
|
|
||||||
|
|
||||||
|
#define __kb_destroy(kbnode_t,b) do { \
|
||||||
|
int i; \
|
||||||
|
unsigned int max = 8; \
|
||||||
|
kbnode_t *x, **top, **stack = 0; \
|
||||||
|
if (b->root) { \
|
||||||
|
top = stack = (kbnode_t**)xcalloc(max, sizeof(kbnode_t*)); \
|
||||||
|
*top++ = (b)->root; \
|
||||||
|
while (top != stack) { \
|
||||||
|
x = *--top; \
|
||||||
|
if (x->is_internal == 0) { xfree(x); continue; } \
|
||||||
|
for (i = 0; i <= x->n; ++i) \
|
||||||
|
if (__KB_PTR(b, x)[i]) { \
|
||||||
|
if (top - stack == (int)max) { \
|
||||||
|
max <<= 1; \
|
||||||
|
stack = (kbnode_t**)xrealloc(stack, max * sizeof(kbnode_t*)); \
|
||||||
|
top = stack + (max>>1); \
|
||||||
|
} \
|
||||||
|
*top++ = __KB_PTR(b, x)[i]; \
|
||||||
|
} \
|
||||||
|
xfree(x); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
xfree(stack); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define __KB_GET_AUX1(name, key_t, kbnode_t, __cmp) \
|
||||||
|
static inline int __kb_getp_aux_##name(const kbnode_t * __restrict x, key_t * __restrict k, int *r) \
|
||||||
|
{ \
|
||||||
|
int tr, *rr, begin = 0, end = x->n; \
|
||||||
|
if (x->n == 0) return -1; \
|
||||||
|
rr = r? r : &tr; \
|
||||||
|
while (begin < end) { \
|
||||||
|
int mid = (begin + end) >> 1; \
|
||||||
|
if (__cmp(__KB_KEY(key_t, x)[mid], *k) < 0) begin = mid + 1; \
|
||||||
|
else end = mid; \
|
||||||
|
} \
|
||||||
|
if (begin == x->n) { *rr = 1; return x->n - 1; } \
|
||||||
|
if ((*rr = __cmp(*k, __KB_KEY(key_t, x)[begin])) < 0) --begin; \
|
||||||
|
return begin; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __KB_GET(name, key_t, kbnode_t) \
|
||||||
|
static key_t *kb_getp_##name(kbtree_##name##_t *b, key_t * __restrict k) \
|
||||||
|
{ \
|
||||||
|
if (!b->root) { \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
int i, r = 0; \
|
||||||
|
kbnode_t *x = b->root; \
|
||||||
|
while (x) { \
|
||||||
|
i = __kb_getp_aux_##name(x, k, &r); \
|
||||||
|
if (i >= 0 && r == 0) return &__KB_KEY(key_t, x)[i]; \
|
||||||
|
if (x->is_internal == 0) return 0; \
|
||||||
|
x = __KB_PTR(b, x)[i + 1]; \
|
||||||
|
} \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
static inline key_t *kb_get_##name(kbtree_##name##_t *b, key_t k) \
|
||||||
|
{ \
|
||||||
|
return kb_getp_##name(b, &k); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __KB_INTERVAL(name, key_t, kbnode_t) \
|
||||||
|
static inline void kb_intervalp_##name(kbtree_##name##_t *b, key_t * __restrict k, key_t **lower, key_t **upper) \
|
||||||
|
{ \
|
||||||
|
if (!b->root) { \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
int i, r = 0; \
|
||||||
|
kbnode_t *x = b->root; \
|
||||||
|
*lower = *upper = 0; \
|
||||||
|
while (x) { \
|
||||||
|
i = __kb_getp_aux_##name(x, k, &r); \
|
||||||
|
if (i >= 0 && r == 0) { \
|
||||||
|
*lower = *upper = &__KB_KEY(key_t, x)[i]; \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
if (i >= 0) *lower = &__KB_KEY(key_t, x)[i]; \
|
||||||
|
if (i < x->n - 1) *upper = &__KB_KEY(key_t, x)[i + 1]; \
|
||||||
|
if (x->is_internal == 0) return; \
|
||||||
|
x = __KB_PTR(b, x)[i + 1]; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static inline void kb_interval_##name(kbtree_##name##_t *b, key_t k, key_t **lower, key_t **upper) \
|
||||||
|
{ \
|
||||||
|
kb_intervalp_##name(b, &k, lower, upper); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __KB_PUT(name, key_t, kbnode_t, __cmp, T, ILEN) \
|
||||||
|
/* x must be an internal node */ \
|
||||||
|
static inline void __kb_split_##name(kbtree_##name##_t *b, kbnode_t *x, int i, kbnode_t *y) \
|
||||||
|
{ \
|
||||||
|
kbnode_t *z; \
|
||||||
|
z = (kbnode_t*)xcalloc(1, y->is_internal? ILEN : sizeof(kbnode_##name##_t)); \
|
||||||
|
++b->n_nodes; \
|
||||||
|
z->is_internal = y->is_internal; \
|
||||||
|
z->n = T - 1; \
|
||||||
|
memcpy(__KB_KEY(key_t, z), &__KB_KEY(key_t, y)[T], sizeof(key_t) * (T - 1)); \
|
||||||
|
if (y->is_internal) memcpy(__KB_PTR(b, z), &__KB_PTR(b, y)[T], sizeof(void*) * T); \
|
||||||
|
y->n = T - 1; \
|
||||||
|
memmove(&__KB_PTR(b, x)[i + 2], &__KB_PTR(b, x)[i + 1], sizeof(void*) * (unsigned int)(x->n - i)); \
|
||||||
|
__KB_PTR(b, x)[i + 1] = z; \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i + 1], &__KB_KEY(key_t, x)[i], sizeof(key_t) * (unsigned int)(x->n - i)); \
|
||||||
|
__KB_KEY(key_t, x)[i] = __KB_KEY(key_t, y)[T - 1]; \
|
||||||
|
++x->n; \
|
||||||
|
} \
|
||||||
|
static inline key_t *__kb_putp_aux_##name(kbtree_##name##_t *b, kbnode_t *x, key_t * __restrict k) \
|
||||||
|
{ \
|
||||||
|
int i = x->n - 1; \
|
||||||
|
key_t *ret; \
|
||||||
|
if (x->is_internal == 0) { \
|
||||||
|
i = __kb_getp_aux_##name(x, k, 0); \
|
||||||
|
if (i != x->n - 1) \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i + 2], &__KB_KEY(key_t, x)[i + 1], (unsigned int)(x->n - i - 1) * sizeof(key_t)); \
|
||||||
|
ret = &__KB_KEY(key_t, x)[i + 1]; \
|
||||||
|
*ret = *k; \
|
||||||
|
++x->n; \
|
||||||
|
} else { \
|
||||||
|
i = __kb_getp_aux_##name(x, k, 0) + 1; \
|
||||||
|
if (__KB_PTR(b, x)[i]->n == 2 * T - 1) { \
|
||||||
|
__kb_split_##name(b, x, i, __KB_PTR(b, x)[i]); \
|
||||||
|
if (__cmp(*k, __KB_KEY(key_t, x)[i]) > 0) ++i; \
|
||||||
|
} \
|
||||||
|
ret = __kb_putp_aux_##name(b, __KB_PTR(b, x)[i], k); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
static inline key_t *kb_putp_##name(kbtree_##name##_t *b, key_t * __restrict k) \
|
||||||
|
{ \
|
||||||
|
if (!b->root) { \
|
||||||
|
b->root = (kbnode_t*)xcalloc(1, ILEN); \
|
||||||
|
++b->n_nodes; \
|
||||||
|
} \
|
||||||
|
kbnode_t *r, *s; \
|
||||||
|
++b->n_keys; \
|
||||||
|
r = b->root; \
|
||||||
|
if (r->n == 2 * T - 1) { \
|
||||||
|
++b->n_nodes; \
|
||||||
|
s = (kbnode_t*)xcalloc(1, ILEN); \
|
||||||
|
b->root = s; s->is_internal = 1; s->n = 0; \
|
||||||
|
__KB_PTR(b, s)[0] = r; \
|
||||||
|
__kb_split_##name(b, s, 0, r); \
|
||||||
|
r = s; \
|
||||||
|
} \
|
||||||
|
return __kb_putp_aux_##name(b, r, k); \
|
||||||
|
} \
|
||||||
|
static inline void kb_put_##name(kbtree_##name##_t *b, key_t k) \
|
||||||
|
{ \
|
||||||
|
kb_putp_##name(b, &k); \
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#define __KB_DEL(name, key_t, kbnode_t, T) \
|
||||||
|
static inline key_t __kb_delp_aux_##name(kbtree_##name##_t *b, kbnode_t *x, key_t * __restrict k, int s) \
|
||||||
|
{ \
|
||||||
|
int yn, zn, i, r = 0; \
|
||||||
|
kbnode_t *xp, *y, *z; \
|
||||||
|
key_t kp; \
|
||||||
|
if (x == 0) return *k; \
|
||||||
|
if (s) { /* s can only be 0, 1 or 2 */ \
|
||||||
|
r = x->is_internal == 0? 0 : s == 1? 1 : -1; \
|
||||||
|
i = s == 1? x->n - 1 : -1; \
|
||||||
|
} else i = __kb_getp_aux_##name(x, k, &r); \
|
||||||
|
if (x->is_internal == 0) { \
|
||||||
|
if (s == 2) ++i; \
|
||||||
|
kp = __KB_KEY(key_t, x)[i]; \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i], &__KB_KEY(key_t, x)[i + 1], (unsigned int)(x->n - i - 1) * sizeof(key_t)); \
|
||||||
|
--x->n; \
|
||||||
|
return kp; \
|
||||||
|
} \
|
||||||
|
if (r == 0) { \
|
||||||
|
if ((yn = __KB_PTR(b, x)[i]->n) >= T) { \
|
||||||
|
xp = __KB_PTR(b, x)[i]; \
|
||||||
|
kp = __KB_KEY(key_t, x)[i]; \
|
||||||
|
__KB_KEY(key_t, x)[i] = __kb_delp_aux_##name(b, xp, 0, 1); \
|
||||||
|
return kp; \
|
||||||
|
} else if ((zn = __KB_PTR(b, x)[i + 1]->n) >= T) { \
|
||||||
|
xp = __KB_PTR(b, x)[i + 1]; \
|
||||||
|
kp = __KB_KEY(key_t, x)[i]; \
|
||||||
|
__KB_KEY(key_t, x)[i] = __kb_delp_aux_##name(b, xp, 0, 2); \
|
||||||
|
return kp; \
|
||||||
|
} else if (yn == T - 1 && zn == T - 1) { \
|
||||||
|
y = __KB_PTR(b, x)[i]; z = __KB_PTR(b, x)[i + 1]; \
|
||||||
|
__KB_KEY(key_t, y)[y->n++] = *k; \
|
||||||
|
memmove(&__KB_KEY(key_t, y)[y->n], __KB_KEY(key_t, z), (unsigned int)z->n * sizeof(key_t)); \
|
||||||
|
if (y->is_internal) memmove(&__KB_PTR(b, y)[y->n], __KB_PTR(b, z), (unsigned int)(z->n + 1) * sizeof(void*)); \
|
||||||
|
y->n += z->n; \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i], &__KB_KEY(key_t, x)[i + 1], (unsigned int)(x->n - i - 1) * sizeof(key_t)); \
|
||||||
|
memmove(&__KB_PTR(b, x)[i + 1], &__KB_PTR(b, x)[i + 2], (unsigned int)(x->n - i - 1) * sizeof(void*)); \
|
||||||
|
--x->n; \
|
||||||
|
xfree(z); \
|
||||||
|
return __kb_delp_aux_##name(b, y, k, s); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
++i; \
|
||||||
|
if ((xp = __KB_PTR(b, x)[i])->n == T - 1) { \
|
||||||
|
if (i > 0 && (y = __KB_PTR(b, x)[i - 1])->n >= T) { \
|
||||||
|
memmove(&__KB_KEY(key_t, xp)[1], __KB_KEY(key_t, xp), (unsigned int)xp->n * sizeof(key_t)); \
|
||||||
|
if (xp->is_internal) memmove(&__KB_PTR(b, xp)[1], __KB_PTR(b, xp), (unsigned int)(xp->n + 1) * sizeof(void*)); \
|
||||||
|
__KB_KEY(key_t, xp)[0] = __KB_KEY(key_t, x)[i - 1]; \
|
||||||
|
__KB_KEY(key_t, x)[i - 1] = __KB_KEY(key_t, y)[y->n - 1]; \
|
||||||
|
if (xp->is_internal) __KB_PTR(b, xp)[0] = __KB_PTR(b, y)[y->n]; \
|
||||||
|
--y->n; ++xp->n; \
|
||||||
|
} else if (i < x->n && (y = __KB_PTR(b, x)[i + 1])->n >= T) { \
|
||||||
|
__KB_KEY(key_t, xp)[xp->n++] = __KB_KEY(key_t, x)[i]; \
|
||||||
|
__KB_KEY(key_t, x)[i] = __KB_KEY(key_t, y)[0]; \
|
||||||
|
if (xp->is_internal) __KB_PTR(b, xp)[xp->n] = __KB_PTR(b, y)[0]; \
|
||||||
|
--y->n; \
|
||||||
|
memmove(__KB_KEY(key_t, y), &__KB_KEY(key_t, y)[1], (unsigned int)y->n * sizeof(key_t)); \
|
||||||
|
if (y->is_internal) memmove(__KB_PTR(b, y), &__KB_PTR(b, y)[1], (unsigned int)(y->n + 1) * sizeof(void*)); \
|
||||||
|
} else if (i > 0 && (y = __KB_PTR(b, x)[i - 1])->n == T - 1) { \
|
||||||
|
__KB_KEY(key_t, y)[y->n++] = __KB_KEY(key_t, x)[i - 1]; \
|
||||||
|
memmove(&__KB_KEY(key_t, y)[y->n], __KB_KEY(key_t, xp), (unsigned int)xp->n * sizeof(key_t)); \
|
||||||
|
if (y->is_internal) memmove(&__KB_PTR(b, y)[y->n], __KB_PTR(b, xp), (unsigned int)(xp->n + 1) * sizeof(void*)); \
|
||||||
|
y->n += xp->n; \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i - 1], &__KB_KEY(key_t, x)[i], (unsigned int)(x->n - i) * sizeof(key_t)); \
|
||||||
|
memmove(&__KB_PTR(b, x)[i], &__KB_PTR(b, x)[i + 1], (unsigned int)(x->n - i) * sizeof(void*)); \
|
||||||
|
--x->n; \
|
||||||
|
xfree(xp); \
|
||||||
|
xp = y; \
|
||||||
|
} else if (i < x->n && (y = __KB_PTR(b, x)[i + 1])->n == T - 1) { \
|
||||||
|
__KB_KEY(key_t, xp)[xp->n++] = __KB_KEY(key_t, x)[i]; \
|
||||||
|
memmove(&__KB_KEY(key_t, xp)[xp->n], __KB_KEY(key_t, y), (unsigned int)y->n * sizeof(key_t)); \
|
||||||
|
if (xp->is_internal) memmove(&__KB_PTR(b, xp)[xp->n], __KB_PTR(b, y), (unsigned int)(y->n + 1) * sizeof(void*)); \
|
||||||
|
xp->n += y->n; \
|
||||||
|
memmove(&__KB_KEY(key_t, x)[i], &__KB_KEY(key_t, x)[i + 1], (unsigned int)(x->n - i - 1) * sizeof(key_t)); \
|
||||||
|
memmove(&__KB_PTR(b, x)[i + 1], &__KB_PTR(b, x)[i + 2], (unsigned int)(x->n - i - 1) * sizeof(void*)); \
|
||||||
|
--x->n; \
|
||||||
|
xfree(y); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
return __kb_delp_aux_##name(b, xp, k, s); \
|
||||||
|
} \
|
||||||
|
static inline key_t kb_delp_##name(kbtree_##name##_t *b, key_t * __restrict k) \
|
||||||
|
{ \
|
||||||
|
kbnode_t *x; \
|
||||||
|
key_t ret; \
|
||||||
|
ret = __kb_delp_aux_##name(b, b->root, k, 0); \
|
||||||
|
--b->n_keys; \
|
||||||
|
if (b->root->n == 0 && b->root->is_internal) { \
|
||||||
|
--b->n_nodes; \
|
||||||
|
x = b->root; \
|
||||||
|
b->root = __KB_PTR(b, x)[0]; \
|
||||||
|
xfree(x); \
|
||||||
|
} \
|
||||||
|
return ret; \
|
||||||
|
} \
|
||||||
|
static inline key_t kb_del_##name(kbtree_##name##_t *b, key_t k) \
|
||||||
|
{ \
|
||||||
|
return kb_delp_##name(b, &k); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define __KB_ITR(name, key_t, kbnode_t) \
|
||||||
|
static inline void kb_itr_first_##name(kbtree_##name##_t *b, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
itr->p = 0; \
|
||||||
|
if (b->n_keys == 0) return; \
|
||||||
|
itr->p = itr->stack; \
|
||||||
|
itr->p->x = b->root; itr->p->i = 0; \
|
||||||
|
while (itr->p->x->is_internal && __KB_PTR(b, itr->p->x)[0] != 0) { \
|
||||||
|
kbnode_t *x = itr->p->x; \
|
||||||
|
++itr->p; \
|
||||||
|
itr->p->x = __KB_PTR(b, x)[0]; itr->p->i = 0; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static inline int kb_itr_next_##name(kbtree_##name##_t *b, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
if (itr->p < itr->stack) return 0; \
|
||||||
|
for (;;) { \
|
||||||
|
++itr->p->i; \
|
||||||
|
while (itr->p->x && itr->p->i <= itr->p->x->n) { \
|
||||||
|
itr->p[1].i = 0; \
|
||||||
|
itr->p[1].x = itr->p->x->is_internal? __KB_PTR(b, itr->p->x)[itr->p->i] : 0; \
|
||||||
|
++itr->p; \
|
||||||
|
} \
|
||||||
|
--itr->p; \
|
||||||
|
if (itr->p < itr->stack) return 0; \
|
||||||
|
if (itr->p->x && itr->p->i < itr->p->x->n) return 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static inline int kb_itr_prev_##name(kbtree_##name##_t *b, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
if (itr->p < itr->stack) return 0; \
|
||||||
|
for (;;) { \
|
||||||
|
while (itr->p->x && itr->p->i >= 0) { \
|
||||||
|
itr->p[1].x = itr->p->x->is_internal? __KB_PTR(b, itr->p->x)[itr->p->i] : 0; \
|
||||||
|
itr->p[1].i = itr->p[1].x ? itr->p[1].x->n : -1; \
|
||||||
|
++itr->p; \
|
||||||
|
} \
|
||||||
|
--itr->p; \
|
||||||
|
if (itr->p < itr->stack) return 0; \
|
||||||
|
--itr->p->i; \
|
||||||
|
if (itr->p->x && itr->p->i >= 0) return 1; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
static inline int kb_itr_getp_##name(kbtree_##name##_t *b, key_t * __restrict k, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
if (b->n_keys == 0) { \
|
||||||
|
itr->p = NULL; \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
int i, r = 0; \
|
||||||
|
itr->p = itr->stack; \
|
||||||
|
itr->p->x = b->root; \
|
||||||
|
while (itr->p->x) { \
|
||||||
|
i = __kb_getp_aux_##name(itr->p->x, k, &r); \
|
||||||
|
itr->p->i = i; \
|
||||||
|
if (i >= 0 && r == 0) return 1; \
|
||||||
|
++itr->p->i; \
|
||||||
|
itr->p[1].x = itr->p->x->is_internal? __KB_PTR(b, itr->p->x)[i + 1] : 0; \
|
||||||
|
++itr->p; \
|
||||||
|
} \
|
||||||
|
return 0; \
|
||||||
|
} \
|
||||||
|
static inline int kb_itr_get_##name(kbtree_##name##_t *b, key_t k, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
return kb_itr_getp_##name(b,&k,itr); \
|
||||||
|
} \
|
||||||
|
static inline void kb_del_itr_##name(kbtree_##name##_t *b, kbitr_##name##_t *itr) \
|
||||||
|
{ \
|
||||||
|
key_t k = kb_itr_key(itr); \
|
||||||
|
kb_delp_##name(b, &k); \
|
||||||
|
kb_itr_getp_##name(b, &k, itr); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define KBTREE_INIT(name, key_t, __cmp, T) \
|
||||||
|
KBTREE_INIT_IMPL(name, key_t, kbnode_##name##_t, __cmp, T, (sizeof(kbnode_##name##_t)+(2*T)*sizeof(void *)))
|
||||||
|
|
||||||
|
#if (!defined(__clang__) && !defined(__INTEL_COMPILER)) && (__GNUC__ > 4 )
|
||||||
|
|
||||||
|
// The index trickery shouldn't be UB anymore,
|
||||||
|
// still it is to much for gcc:s -Werror=array-bounds
|
||||||
|
# define __KB_PRAGMA_START \
|
||||||
|
_Pragma("GCC diagnostic push") \
|
||||||
|
_Pragma("GCC diagnostic ignored \"-Warray-bounds\"")
|
||||||
|
|
||||||
|
# define __KB_PRAGMA_END \
|
||||||
|
_Pragma("GCC diagnostic pop") \
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
# define __KB_PRAGMA_START
|
||||||
|
# define __KB_PRAGMA_END
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define KBTREE_INIT_IMPL(name, key_t, kbnode_t, __cmp, T, ILEN) \
|
||||||
|
__KB_PRAGMA_START \
|
||||||
|
__KB_TREE_T(name, key_t, T) \
|
||||||
|
__KB_GET_AUX1(name, key_t, kbnode_t, __cmp) \
|
||||||
|
__KB_GET(name, key_t, kbnode_t) \
|
||||||
|
__KB_INTERVAL(name, key_t, kbnode_t) \
|
||||||
|
__KB_PUT(name, key_t, kbnode_t, __cmp, T, ILEN) \
|
||||||
|
__KB_DEL(name, key_t, kbnode_t, T) \
|
||||||
|
__KB_ITR(name, key_t, kbnode_t) \
|
||||||
|
__KB_PRAGMA_END
|
||||||
|
|
||||||
|
#define KB_DEFAULT_SIZE 512
|
||||||
|
|
||||||
|
#define kbtree_t(name) kbtree_##name##_t
|
||||||
|
#define kbitr_t(name) kbitr_##name##_t
|
||||||
|
#define kb_init(b) ((b)->n_keys = (b)->n_nodes = 0, (b)->root = 0)
|
||||||
|
#define kb_destroy(name, b) __kb_destroy(kbnode_##name##_t, b)
|
||||||
|
#define kb_get(name, b, k) kb_get_##name(b, k)
|
||||||
|
#define kb_put(name, b, k) kb_put_##name(b, k)
|
||||||
|
#define kb_del(name, b, k) kb_del_##name(b, k)
|
||||||
|
#define kb_interval(name, b, k, l, u) kb_interval_##name(b, k, l, u)
|
||||||
|
#define kb_getp(name, b, k) kb_getp_##name(b, k)
|
||||||
|
#define kb_putp(name, b, k) kb_putp_##name(b, k)
|
||||||
|
#define kb_delp(name, b, k) kb_delp_##name(b, k)
|
||||||
|
#define kb_intervalp(name, b, k, l, u) kb_intervalp_##name(b, k, l, u)
|
||||||
|
|
||||||
|
#define kb_itr_first(name, b, i) kb_itr_first_##name(b, i)
|
||||||
|
#define kb_itr_get(name, b, k, i) kb_itr_get_##name(b, k, i)
|
||||||
|
#define kb_itr_getp(name, b, k, i) kb_itr_getp_##name(b, k, i)
|
||||||
|
#define kb_itr_next(name, b, i) kb_itr_next_##name(b, i)
|
||||||
|
#define kb_itr_prev(name, b, i) kb_itr_prev_##name(b, i)
|
||||||
|
#define kb_del_itr(name, b, i) kb_del_itr_##name(b, i)
|
||||||
|
#define kb_itr_key(itr) __KB_KEY(dummy, (itr)->p->x)[(itr)->p->i]
|
||||||
|
#define kb_itr_valid(itr) ((itr)->p >= (itr)->stack)
|
||||||
|
|
||||||
|
#define kb_size(b) ((b)->n_keys)
|
||||||
|
|
||||||
|
#define kb_generic_cmp(a, b) (((b) < (a)) - ((a) < (b)))
|
||||||
|
#define kb_str_cmp(a, b) strcmp(a, b)
|
||||||
|
|
||||||
|
#endif // NVIM_LIB_KBTREE_H
|
@ -149,4 +149,3 @@ MAP_IMPL(handle_T, ptr_t, DEFAULT_INITIALIZER)
|
|||||||
#define MSGPACK_HANDLER_INITIALIZER { .fn = NULL, .async = false }
|
#define MSGPACK_HANDLER_INITIALIZER { .fn = NULL, .async = false }
|
||||||
MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER)
|
MAP_IMPL(String, MsgpackRpcRequestHandler, MSGPACK_HANDLER_INITIALIZER)
|
||||||
#define KVEC_INITIALIZER { .size = 0, .capacity = 0, .items = NULL }
|
#define KVEC_INITIALIZER { .size = 0, .capacity = 0, .items = NULL }
|
||||||
MAP_IMPL(linenr_T, bufhl_vec_T, KVEC_INITIALIZER)
|
|
||||||
|
@ -30,7 +30,6 @@ MAP_DECLS(ptr_t, ptr_t)
|
|||||||
MAP_DECLS(uint64_t, ptr_t)
|
MAP_DECLS(uint64_t, ptr_t)
|
||||||
MAP_DECLS(handle_T, ptr_t)
|
MAP_DECLS(handle_T, ptr_t)
|
||||||
MAP_DECLS(String, MsgpackRpcRequestHandler)
|
MAP_DECLS(String, MsgpackRpcRequestHandler)
|
||||||
MAP_DECLS(linenr_T, bufhl_vec_T)
|
|
||||||
|
|
||||||
#define map_new(T, U) map_##T##_##U##_new
|
#define map_new(T, U) map_##T##_##U##_new
|
||||||
#define map_free(T, U) map_##T##_##U##_free
|
#define map_free(T, U) map_##T##_##U##_free
|
||||||
|
@ -888,9 +888,13 @@ void ex_changes(exarg_T *eap)
|
|||||||
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
|
* Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
|
||||||
* or: mark_adjust(56, 55, MAXLNUM, 2);
|
* or: mark_adjust(56, 55, MAXLNUM, 2);
|
||||||
*/
|
*/
|
||||||
void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
|
void mark_adjust(linenr_T line1,
|
||||||
|
linenr_T line2,
|
||||||
|
long amount,
|
||||||
|
long amount_after,
|
||||||
|
bool end_temp)
|
||||||
{
|
{
|
||||||
mark_adjust_internal(line1, line2, amount, amount_after, true);
|
mark_adjust_internal(line1, line2, amount, amount_after, true, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// mark_adjust_nofold() does the same as mark_adjust() but without adjusting
|
// mark_adjust_nofold() does the same as mark_adjust() but without adjusting
|
||||||
@ -899,13 +903,14 @@ void mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_after)
|
|||||||
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
|
// calling foldMarkAdjust() with arguments line1, line2, amount, amount_after,
|
||||||
// for an example of why this may be necessary, see do_move().
|
// for an example of why this may be necessary, see do_move().
|
||||||
void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
|
void mark_adjust_nofold(linenr_T line1, linenr_T line2, long amount,
|
||||||
long amount_after)
|
long amount_after, bool end_temp)
|
||||||
{
|
{
|
||||||
mark_adjust_internal(line1, line2, amount, amount_after, false);
|
mark_adjust_internal(line1, line2, amount, amount_after, false, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount,
|
static void mark_adjust_internal(linenr_T line1, linenr_T line2,
|
||||||
long amount_after, bool adjust_folds)
|
long amount, long amount_after,
|
||||||
|
bool adjust_folds, bool end_temp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int fnum = curbuf->b_fnum;
|
int fnum = curbuf->b_fnum;
|
||||||
@ -954,7 +959,7 @@ static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
sign_mark_adjust(line1, line2, amount, amount_after);
|
sign_mark_adjust(line1, line2, amount, amount_after);
|
||||||
bufhl_mark_adjust(curbuf, line1, line2, amount, amount_after);
|
bufhl_mark_adjust(curbuf, line1, line2, amount, amount_after, end_temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* previous context mark */
|
/* previous context mark */
|
||||||
|
@ -751,7 +751,7 @@ open_line (
|
|||||||
// Skip mark_adjust when adding a line after the last one, there can't
|
// Skip mark_adjust when adding a line after the last one, there can't
|
||||||
// be marks there.
|
// be marks there.
|
||||||
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) {
|
if (curwin->w_cursor.lnum + 1 < curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L);
|
mark_adjust(curwin->w_cursor.lnum + 1, (linenr_T)MAXLNUM, 1L, 0L, false);
|
||||||
}
|
}
|
||||||
did_append = true;
|
did_append = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1866,7 +1866,7 @@ void appended_lines_mark(linenr_T lnum, long count)
|
|||||||
// Skip mark_adjust when adding a line after the last one, there can't
|
// Skip mark_adjust when adding a line after the last one, there can't
|
||||||
// be marks there.
|
// be marks there.
|
||||||
if (lnum + count < curbuf->b_ml.ml_line_count) {
|
if (lnum + count < curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L);
|
mark_adjust(lnum + 1, (linenr_T)MAXLNUM, count, 0L, false);
|
||||||
}
|
}
|
||||||
changed_lines(lnum + 1, 0, lnum + 1, count);
|
changed_lines(lnum + 1, 0, lnum + 1, count);
|
||||||
}
|
}
|
||||||
@ -1888,7 +1888,7 @@ void deleted_lines(linenr_T lnum, long count)
|
|||||||
*/
|
*/
|
||||||
void deleted_lines_mark(linenr_T lnum, long count)
|
void deleted_lines_mark(linenr_T lnum, long count)
|
||||||
{
|
{
|
||||||
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count);
|
mark_adjust(lnum, (linenr_T)(lnum + count - 1), (long)MAXLNUM, -count, false);
|
||||||
changed_lines(lnum, 0, lnum + count, -count);
|
changed_lines(lnum, 0, lnum + count, -count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3182,7 +3182,7 @@ error:
|
|||||||
if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines
|
if (curbuf->b_op_start.lnum + (y_type == kMTCharWise) - 1 + nr_lines
|
||||||
< curbuf->b_ml.ml_line_count) {
|
< curbuf->b_ml.ml_line_count) {
|
||||||
mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
|
mark_adjust(curbuf->b_op_start.lnum + (y_type == kMTCharWise),
|
||||||
(linenr_T)MAXLNUM, nr_lines, 0L);
|
(linenr_T)MAXLNUM, nr_lines, 0L, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// note changed text for displaying and folding
|
// note changed text for displaying and folding
|
||||||
|
@ -2210,7 +2210,7 @@ win_line (
|
|||||||
bool search_attr_from_match = false; // if search_attr is from :match
|
bool search_attr_from_match = false; // if search_attr is from :match
|
||||||
bool has_bufhl = false; // this buffer has highlight matches
|
bool has_bufhl = false; // this buffer has highlight matches
|
||||||
int bufhl_attr = 0; // attributes desired by bufhl
|
int bufhl_attr = 0; // attributes desired by bufhl
|
||||||
bufhl_lineinfo_T bufhl_info; // bufhl data for this line
|
BufhlLineInfo bufhl_info; // bufhl data for this line
|
||||||
|
|
||||||
/* draw_state: items that are drawn in sequence: */
|
/* draw_state: items that are drawn in sequence: */
|
||||||
#define WL_START 0 /* nothing done yet */
|
#define WL_START 0 /* nothing done yet */
|
||||||
|
@ -2232,11 +2232,13 @@ static void u_undoredo(int undo)
|
|||||||
/* adjust marks */
|
/* adjust marks */
|
||||||
if (oldsize != newsize) {
|
if (oldsize != newsize) {
|
||||||
mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
|
mark_adjust(top + 1, top + oldsize, (long)MAXLNUM,
|
||||||
(long)newsize - (long)oldsize);
|
(long)newsize - (long)oldsize, false);
|
||||||
if (curbuf->b_op_start.lnum > top + oldsize)
|
if (curbuf->b_op_start.lnum > top + oldsize) {
|
||||||
curbuf->b_op_start.lnum += newsize - oldsize;
|
curbuf->b_op_start.lnum += newsize - oldsize;
|
||||||
if (curbuf->b_op_end.lnum > top + oldsize)
|
}
|
||||||
|
if (curbuf->b_op_end.lnum > top + oldsize) {
|
||||||
curbuf->b_op_end.lnum += newsize - oldsize;
|
curbuf->b_op_end.lnum += newsize - oldsize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changed_lines(top + 1, 0, bot, newsize - oldsize);
|
changed_lines(top + 1, 0, bot, newsize - oldsize);
|
||||||
|
Loading…
Reference in New Issue
Block a user