aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-12-19 23:39:33 +0100
committerChristian Clason <c.clason@uni-graz.at>2023-12-20 17:44:31 +0100
commit095bd8d0f8340475319cfa13776d5ec386984859 (patch)
treec8434af0f6d0f59f88e31b926f3dd41371039c57
parent99d1e7da28061c2559c523f76b58b8bb113475ff (diff)
downloadrneovim-095bd8d0f8340475319cfa13776d5ec386984859.tar.gz
rneovim-095bd8d0f8340475319cfa13776d5ec386984859.tar.bz2
rneovim-095bd8d0f8340475319cfa13776d5ec386984859.zip
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.
-rw-r--r--src/nvim/buffer.c4
-rw-r--r--src/nvim/help.c41
2 files changed, 4 insertions, 41 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 7660093fc2..c9ae4c3ed3 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -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;
diff --git a/src/nvim/help.c b/src/nvim/help.c
index 28b95b2346..b1b53bc0c3 100644
--- a/src/nvim/help.c
+++ b/src/nvim/help.c
@@ -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);