micro
micro copied to clipboard
[Bug] Bash's syntax highlighting mishandles `'` in comments
Description of the problem or steps to reproduce
Paste the following into a file and open it with micro:
#!/usr/bin/bash
echo "this example demonstrates the mishandling of \'" # by micro's syntax highlighting
echo "this part is highlighted incorrectly as of v2.0.10" # and now after another '
echo "back to normal"
Observe that the text between the first '
in the comments of line 3 and the next '
in the comments of line 5 is highlighted as if it's a big string.
Screenshot
Specifications
Version: 2.0.10 Commit hash: b9763856 OS: Manjaro Terminal: Alacritty
Problem is this line in the shell syntax definition: https://github.com/zyedidia/micro/blob/03ae049c0fe5862ca6010474dd775656bd6e5b86/runtime/syntax/sh.yaml#L61
The highlighter is not smart enough to handle (^|\\s)
-- it just checks if it can match the beginning of a line beginning when it sees ^
anywhere inside the token regexp, even though it is inside an optional group in this case.
To fix this on your end you can override the built-in broken syntax by copying the sh.yaml file to ~/.config/micro/syntax/sh.yaml
and making two different definitions for a comment like this:
- comment:
start: "^#"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME):?"
- comment:
start: "\\s#"
end: "$"
rules:
- todo: "(TODO|XXX|FIXME):?"