mirror of
https://github.com/neovim/neovim.git
synced 2025-09-14 23:38:17 +00:00
bufhl: some style cleanup
This commit is contained in:
@@ -5150,7 +5150,8 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a
|
|||||||
/// @param line the linenumber to lookup
|
/// @param line the linenumber to lookup
|
||||||
/// @param put if true, put a new line when not found
|
/// @param put if true, put a new line when not found
|
||||||
/// if false, return NULL when not found
|
/// if false, return NULL when not found
|
||||||
BufhlLine *bufhl_tree_ref(kbtree_t(bufhl) *b, linenr_T line, bool put) {
|
BufhlLine *bufhl_tree_ref(BufhlInfo *b, linenr_T line, bool put)
|
||||||
|
{
|
||||||
BufhlLine t = BUFHLLINE_INIT(line);
|
BufhlLine t = BUFHLLINE_INIT(line);
|
||||||
|
|
||||||
// kp_put() only works if key is absent, try get first
|
// kp_put() only works if key is absent, try get first
|
||||||
@@ -5207,7 +5208,7 @@ int bufhl_add_hl(buf_T *buf,
|
|||||||
|
|
||||||
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, true);
|
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, true);
|
||||||
|
|
||||||
bufhl_hl_item_T *hlentry = kv_pushp(lineinfo->items);
|
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;
|
||||||
@@ -5279,16 +5280,16 @@ static BufhlLineStatus bufhl_clear_line(BufhlLine *lineinfo, int src_id,
|
|||||||
if (src_id < 0) {
|
if (src_id < 0) {
|
||||||
kv_size(lineinfo->items) = 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->items); i++) {
|
for (size_t i = 0; i < kv_size(lineinfo->items); i++) {
|
||||||
if (kv_A(lineinfo->items, i).src_id != src_id) {
|
if (kv_A(lineinfo->items, i).src_id != src_id) {
|
||||||
if (i != newind) {
|
if (i != newidx) {
|
||||||
kv_A(lineinfo->items, newind) = kv_A(lineinfo->items, i);
|
kv_A(lineinfo->items, newidx) = kv_A(lineinfo->items, i);
|
||||||
}
|
}
|
||||||
newind++;
|
newidx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
kv_size(lineinfo->items) = newind;
|
kv_size(lineinfo->items) = newidx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kv_size(lineinfo->items) == 0) {
|
if (kv_size(lineinfo->items) == 0) {
|
||||||
@@ -5349,7 +5350,7 @@ 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)
|
||||||
{
|
{
|
||||||
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, false);
|
BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, false);
|
||||||
if (!lineinfo) {
|
if (!lineinfo) {
|
||||||
@@ -5370,14 +5371,14 @@ 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);
|
||||||
|
@@ -760,7 +760,7 @@ 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
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -4,32 +4,31 @@
|
|||||||
#include "nvim/pos.h"
|
#include "nvim/pos.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
#include "nvim/lib/kbtree.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 {
|
||||||
linenr_T line;
|
linenr_T line;
|
||||||
bufhl_vec_T items;
|
BufhlItemVec items;
|
||||||
} BufhlLine;
|
} BufhlLine;
|
||||||
#define BUFHLLINE_INIT(l) { l, KV_INITIAL_VALUE }
|
#define BUFHLLINE_INIT(l) { l, KV_INITIAL_VALUE }
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bufhl_vec_T entries;
|
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)))
|
#define BUFHL_CMP(a, b) ((int)(((a)->line - (b)->line)))
|
||||||
KBTREE_INIT(bufhl, BufhlLine *, BUFHL_CMP, 10)
|
KBTREE_INIT(bufhl, BufhlLine *, BUFHL_CMP, 10)
|
||||||
typedef kbtree_t(bufhl) bufhl_info_T;
|
typedef kbtree_t(bufhl) BufhlInfo;
|
||||||
#endif // NVIM_BUFHL_DEFS_H
|
#endif // NVIM_BUFHL_DEFS_H
|
||||||
|
@@ -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 */
|
||||||
|
Reference in New Issue
Block a user