Crate duat_match_pairs

Crate duat_match_pairs 

Source
Expand description

A simple Plugin to match pairs of parentheses

§Installation

This is a default plugin, but you can add it manually in order to configure it:

cargo add duat-match-pairs@"*" --rename match-pairs

Or, if you are using a --git-deps version of duat, do this:

cargo add --git https://github.com/AhoyISki/duat-match-pairs --rename match-pairs

§Usage

In order to make use of it, just add the following to your setup function:

setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    plug(duat_match_pairs::MatchPairs::new());
}

In this plugin, there are two types of “pairs”, these are the normal pairs and the treesitter pairs. The normal pairs match based on the content of the text itself, so for example, in this situation:

let my_string = "(this is my string)";

There is a normal pair within the string of (,). However, there is no treesitter pair in there, because a treesitter pair only matches if the pairs are on the language’s syntax tree.

This distinction allows for some combination of pairings that can also be used as non pairs. For example, in Rust, <,> is a pair only on type arguments and things of the sort, in other cases, it is just a comparison operator. That’s where the treesitter pairs come in, as they can identify when it is an actual pair, or just the operator.

In order to change what counts as a normal pair and what counts as a treesitter pair, you can add the following to the setup function:

setup_duat!(setup);
use duat::prelude::*;

fn setup() {
    plug(
        duat_match_pairs::MatchPairs::new()
            .match_pairs([["\\(", "\\)"], ["\\{", "\\}"], ["\\[", "\\]"]])
            .match_ts_pairs([["<", ">"], ["|", "|"]]),
    );
}

Two things to note here:

  • For now, normal pairs only support one character regexes.
  • Also for now, normal pairs use regex, while treesitter pairs use strings.

Structs§

MatchPairs
highlight the match of delimiters under Selections