Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be some way to highlight the inside of a region #2401

Open
Screwtapello opened this issue Sep 18, 2018 · 3 comments
Open

There should be some way to highlight the inside of a region #2401

Screwtapello opened this issue Sep 18, 2018 · 3 comments

Comments

@Screwtapello
Copy link
Contributor

The Markdown highlighter contains support for highlighting different languages in fenced code blocks, like this:

```rust
fn main() {
    println!("hello, world");
}
```

The actual Kakoune script it generates looks something like this (at least, after PR #2400 lands):

add-highlighter shared/markdown/rust region -match-capture ^(\h*)```\h*rust\\b   ^(\h*)``` regions
add-highlighter shared/markdown/rust/ default-region fill meta
add-highlighter shared/markdown/rust/inner region \A```[^\\n]*\K (?=```) ref rust

As I understand it, this means:

  • A Rust region starts from a line beginning with triple-backtick followed by rust, and ends with a line with the same indent containing a triple-quote.
  • That entire region, including the opening and closing markers, gets filled with the "meta" face.
  • The inner region, after the opening marker and before the closing marker, gets highlighted according to Rust rules.

There's just one problem: the inner region doesn't necessarily end before the closing marker, it ends before the first triple-backtick. So if I have a code-block like this:

```rust
fn main() {
    // some comment with ``` in it
    println!("hello, world");
}
```

...the Rust highlighting ends in the middle of the second line, instead of continuing until the end. The obvious solution is to change the region-end regex from (?=```) to (?=```\z) since we want to end the region when we hit the closing marker, not any old triple-backtick. Unfortunately, that solution produces an error:

'add-highlighter' regex parse error: Lookaround can only contain literals, any chars or character classes at (?=```\z)<<<HERE>>>

I know that Kakoune's non-backtracking regex-engine implies certain limitations about lookahead and lookbehind, but I vaguely recall the current implementation is overly restrictive. If this particular restriction is not entirely necessary, it would be great if it could be lifted.

Other alternatives that I can think of:

  • If there were some way to automatically apply a highlighter to the inside of a region (that is, between the text matched by the opening and closing regexes, without including them), that would be fine.
  • An opposite version of \K, that resets the end position of capture group 0 to the current position.
@pickfire
Copy link
Contributor

Is this related to adding rust highlighting in rust doc comments?

Also, is this markdown related?

> ```python
> print("Hello world")
> ```

```python
print("Hello world")

Currently, the quote part is not highlighted.

I believe the same goes for rust.

//! Hello world
//! ```
//! println!("hello world");
//! ```

@lenormf
Copy link
Contributor

lenormf commented May 31, 2020

Related to region highlighting issues: #3055 #3024 #3375 #3056 #1670
Dupe #3121

@pickfire
Copy link
Contributor

pickfire commented Nov 8, 2020

Rust doc blocks already work (I forgot when but quite some time ago), I ported a similar version from rust.vim. It even checks checks for the correct term, like edition2018,no_run and also support # for hiding code. But I didn't add support for other languages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants