A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/neovim/neovim/commit/6eca9b69c4a1f40f27a6b41961af787327259de8 below:

allow conceal to be defined in decorations · neovim/neovim@6eca9b6 · GitHub

File tree Expand file treeCollapse file tree 7 files changed

+100

-5

lines changed

Filter options

Expand file treeCollapse file tree 7 files changed

+100

-5

lines changed Original file line number Diff line number Diff line change

@@ -274,7 +274,8 @@ local function on_line_impl(self, buf, line)

274 274

{ end_line = end_row, end_col = end_col,

275 275

hl_group = hl,

276 276

ephemeral = true,

277 -

priority = tonumber(metadata.priority) or 100 -- Low but leaves room below

277 +

priority = tonumber(metadata.priority) or 100, -- Low but leaves room below

278 +

conceal = metadata.conceal,

278 279

})

279 280

end

280 281

if start_row > line then

Original file line number Diff line number Diff line change

@@ -467,6 +467,11 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e

467 467

/// as the mark and 'cursorline' is enabled.

468 468

/// Note: ranges are unsupported and decorations are only

469 469

/// applied to start_row

470 +

/// - conceal: string which should be either empty or a single

471 +

/// character. Enable concealing similar to |:syn-conceal|.

472 +

/// When a character is supplied it is used as |:syn-cchar|.

473 +

/// "hl_group" is used as highlight for the cchar if provided,

474 +

/// otherwise it defaults to |hl-Conceal|.

470 475

///

471 476

/// @param[out] err Error details, if any

472 477

/// @return Id of the created/updated extmark

@@ -563,6 +568,17 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer

563 568

}

564 569

}

565 570 571 +

if (opts->conceal.type == kObjectTypeString) {

572 +

String c = opts->conceal.data.string;

573 +

decor.conceal = true;

574 +

if (c.size) {

575 +

decor.conceal_char = utf_ptr2char((const char_u *)c.data);

576 +

}

577 +

} else if (HAS_KEY(opts->conceal)) {

578 +

api_set_error(err, kErrorTypeValidation, "conceal is not a String");

579 +

goto error;

580 +

}

581 + 566 582

if (opts->virt_text.type == kObjectTypeArray) {

567 583

decor.virt_text = parse_virt_text(opts->virt_text.data.array, err,

568 584

&decor.virt_text_width);

Original file line number Diff line number Diff line change

@@ -27,6 +27,7 @@ return {

27 27

"number_hl_group";

28 28

"line_hl_group";

29 29

"cursorline_hl_group";

30 +

"conceal";

30 31

};

31 32

keymap = {

32 33

"noremap";

Original file line number Diff line number Diff line change

@@ -312,6 +312,10 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *

312 312 313 313

int attr = 0;

314 314

size_t j = 0;

315 +

bool conceal = 0;

316 +

int conceal_char = 0;

317 +

int conceal_attr = 0;

318 + 315 319

for (size_t i = 0; i < kv_size(state->active); i++) {

316 320

DecorRange item = kv_A(state->active, i);

317 321

bool active = false, keep = true;

@@ -336,6 +340,14 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *

336 340

if (active && item.attr_id > 0) {

337 341

attr = hl_combine_attr(attr, item.attr_id);

338 342

}

343 +

if (active && item.decor.conceal) {

344 +

conceal = true;

345 +

if (item.start_row == state->row && item.start_col == col && item.decor.conceal_char) {

346 +

conceal_char = item.decor.conceal_char;

347 +

state->col_until = MIN(state->col_until, item.start_col);

348 +

conceal_attr = item.attr_id;

349 +

}

350 +

}

339 351

if ((item.start_row == state->row && item.start_col <= col)

340 352

&& kv_size(item.decor.virt_text)

341 353

&& item.decor.virt_text_pos == kVTOverlay && item.win_col == -1) {

@@ -349,6 +361,9 @@ int decor_redraw_col(buf_T *buf, int col, int win_col, bool hidden, DecorState *

349 361

}

350 362

kv_size(state->active) = j;

351 363

state->current = attr;

364 +

state->conceal = conceal;

365 +

state->conceal_char = conceal_char;

366 +

state->conceal_attr = conceal_attr;

352 367

return attr;

353 368

}

354 369 Original file line number Diff line number Diff line change

@@ -47,6 +47,7 @@ struct Decoration {

47 47

bool virt_text_hide;

48 48

bool hl_eol;

49 49

bool virt_lines_above;

50 +

bool conceal;

50 51

// TODO(bfredl): style, etc

51 52

DecorPriority priority;

52 53

int col; // fixed col value, like win_col

@@ -56,9 +57,13 @@ struct Decoration {

56 57

int number_hl_id;

57 58

int line_hl_id;

58 59

int cursorline_hl_id;

60 +

// TODO(bfredl): in principle this should be a schar_T, but we

61 +

// probably want some kind of glyph cache for that..

62 +

int conceal_char;

59 63

};

60 -

#define DECORATION_INIT { KV_INITIAL_VALUE, KV_INITIAL_VALUE, 0, kVTEndOfLine, kHlModeUnknown, \

61 -

false, false, false, DECOR_PRIORITY_BASE, 0, 0, NULL, 0, 0, 0, 0 }

64 +

#define DECORATION_INIT { KV_INITIAL_VALUE, KV_INITIAL_VALUE, 0, kVTEndOfLine, \

65 +

kHlModeUnknown, false, false, false, false, DECOR_PRIORITY_BASE, \

66 +

0, 0, NULL, 0, 0, 0, 0, 0 }

62 67 63 68

typedef struct {

64 69

int start_row;

@@ -80,6 +85,10 @@ typedef struct {

80 85

int col_until;

81 86

int current;

82 87

int eol_col;

88 + 89 +

bool conceal;

90 +

int conceal_char;

91 +

int conceal_attr;

83 92

} DecorState;

84 93 85 94

EXTERN DecorState decor_state INIT(= { 0 });

Original file line number Diff line number Diff line change

@@ -2682,6 +2682,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc

2682 2682

// Repeat for the whole displayed line.

2683 2683

for (;;) {

2684 2684

int has_match_conc = 0; ///< match wants to conceal

2685 +

int decor_conceal = 0;

2686 + 2685 2687

bool did_decrement_ptr = false;

2686 2688 2687 2689

// Skip this quickly when working on the text.

@@ -3506,6 +3508,11 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc

3506 3508

char_attr = hl_combine_attr(extmark_attr, char_attr);

3507 3509

}

3508 3510

}

3511 + 3512 +

decor_conceal = decor_state.conceal;

3513 +

if (decor_conceal && decor_state.conceal_char) {

3514 +

decor_conceal = 2; // really??

3515 +

}

3509 3516

}

3510 3517 3511 3518

// Found last space before word: check for line break.

@@ -3809,19 +3816,25 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc

3809 3816

if (wp->w_p_cole > 0

3810 3817

&& (wp != curwin || lnum != wp->w_cursor.lnum

3811 3818

|| conceal_cursor_line(wp))

3812 -

&& ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)

3819 +

&& ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0 || decor_conceal > 0)

3813 3820

&& !(lnum_in_visual_area

3814 3821

&& vim_strchr(wp->w_p_cocu, 'v') == NULL)) {

3815 3822

char_attr = conceal_attr;

3816 -

if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)

3823 +

if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1 || decor_conceal > 1)

3817 3824

&& (syn_get_sub_char() != NUL

3818 3825

|| (has_match_conc && match_conc)

3826 +

|| (decor_conceal && decor_state.conceal_char)

3819 3827

|| wp->w_p_cole == 1)

3820 3828

&& wp->w_p_cole != 3) {

3821 3829

// First time at this concealed item: display one

3822 3830

// character.

3823 3831

if (has_match_conc && match_conc) {

3824 3832

c = match_conc;

3833 +

} else if (decor_conceal && decor_state.conceal_char) {

3834 +

c = decor_state.conceal_char;

3835 +

if (decor_state.conceal_attr) {

3836 +

char_attr = decor_state.conceal_attr;

3837 +

}

3825 3838

} else if (syn_get_sub_char() != NUL) {

3826 3839

c = syn_get_sub_char();

3827 3840

} else if (wp->w_p_lcs_chars.conceal != NUL) {

Original file line number Diff line number Diff line change

@@ -672,6 +672,46 @@ describe('treesitter highlighting', function()

672 672

]]}

673 673

end)

674 674 675 +

it("supports conceal attribute", function()

676 +

if pending_c_parser(pending) then return end

677 +

insert(hl_text)

678 + 679 +

-- conceal can be empty or a single cchar.

680 +

exec_lua [=[

681 +

vim.opt.cole = 2

682 +

local parser = vim.treesitter.get_parser(0, "c")

683 +

test_hl = vim.treesitter.highlighter.new(parser, {queries = {c = [[

684 +

("static" @keyword

685 +

(set! conceal "R"))

686 + 687 +

((identifier) @Identifier

688 +

(set! conceal "")

689 +

(eq? @Identifier "lstate"))

690 +

]]}})

691 +

]=]

692 + 693 +

screen:expect{grid=[[

694 +

/// Schedule Lua callback on main loop's event queue |

695 +

{4:R} int nlua_schedule(lua_State *const ) |

696 +

{ |

697 +

if (lua_type(, 1) != LUA_TFUNCTION |

698 +

|| != ) { |

699 +

lua_pushliteral(, "vim.schedule: expected function"); |

700 +

return lua_error(); |

701 +

} |

702 +

|

703 +

LuaRef cb = nlua_ref(, 1); |

704 +

|

705 +

multiqueue_put(main_loop.events, nlua_schedule_event, |

706 +

1, (void *)(ptrdiff_t)cb); |

707 +

return 0; |

708 +

^} |

709 +

{1:~ }|

710 +

{1:~ }|

711 +

|

712 +

]]}

713 +

end)

714 + 675 715

it("hl_map has the correct fallback behavior", function()

676 716

exec_lua [[

677 717

local hl_map = vim.treesitter.highlighter.hl_map

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4