fix(buffer): do not filter help buffer

Problem: If a help buffer is opened without legacy syntax set (because
treesitter is enabled), Vim strips (some) markup. This means the syntax
engine fails to parse (some) syntax if treesitter highlighting is
disabled again.

Solution: Do not strip the help buffer of markup since (legacy or
treesitter) highlighting is always enabled in Nvim. Similarly, remove
redundant setting of filetype and give the function a more descriptive
name.
This commit is contained in:
Christian Clason 2023-12-19 23:39:33 +01:00
parent 99d1e7da28
commit 095bd8d0f8
2 changed files with 4 additions and 41 deletions

View File

@ -302,9 +302,9 @@ int open_buffer(bool read_stdin, exarg_T *eap, int flags_arg)
}
#endif
// Help buffer is filtered.
// Help buffer: populate *local-additions* in help.txt
if (bt_help(curbuf)) {
fix_help_buffer();
get_local_additions();
}
} else if (read_stdin) {
int save_bin = curbuf->b_p_bin;

View File

@ -642,46 +642,9 @@ void prepare_help_buffer(void)
set_buflisted(false);
}
/// After reading a help file: May cleanup a help buffer when syntax
/// highlighting is not used.
void fix_help_buffer(void)
/// After reading a help file: if help.txt, populate *local-additions*
void get_local_additions(void)
{
// Set filetype to "help".
if (strcmp(curbuf->b_p_ft, "help") != 0) {
curbuf->b_ro_locked++;
set_option_value_give_err(kOptFiletype, STATIC_CSTR_AS_OPTVAL("help"), OPT_LOCAL);
curbuf->b_ro_locked--;
}
if (!syntax_present(curwin)) {
bool in_example = false;
for (linenr_T lnum = 1; lnum <= curbuf->b_ml.ml_line_count; lnum++) {
char *line = ml_get_buf(curbuf, lnum);
const size_t len = strlen(line);
if (in_example && len > 0 && !ascii_iswhite(line[0])) {
// End of example: non-white or '<' in first column.
if (line[0] == '<') {
// blank-out a '<' in the first column
line = ml_get_buf_mut(curbuf, lnum);
line[0] = ' ';
}
in_example = false;
}
if (!in_example && len > 0) {
if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) {
// blank-out a '>' in the last column (start of example)
line = ml_get_buf_mut(curbuf, lnum);
line[len - 1] = ' ';
in_example = true;
} else if (line[len - 1] == '~') {
// blank-out a '~' at the end of line (header marker)
line = ml_get_buf_mut(curbuf, lnum);
line[len - 1] = ' ';
}
}
}
}
// In the "help.txt" and "help.abx" file, add the locally added help
// files. This uses the very first line in the help file.
char *const fname = path_tail(curbuf->b_fname);