Skip to main content

parse_chord_sequence

Function parse_chord_sequence 

Source
pub fn parse_chord_sequence(s: &str) -> Result<Vec<KeyChord>, ChordParseError>
Expand description

Parse a chord-sequence string into the canonical Vec<KeyChord> the keymap trie indexes by.

Examples:

  • "j" -> [char('j')]
  • "gg" -> [char('g'), char('g')]
  • "<C-w>j" -> [ctrl('w'), char('j')]
  • "dw" -> [char('d'), char('w')]
  • "<lt>" -> [char('<')]

Used by:

  • The keymap_entry! macro at startup to convert the catalog’s &'static str chord into the trie’s typed key.
  • :bind user / plugin invocations that take a chord-string at runtime.

<leader> is not understood here: it is substituted before parsing, at bind time, by the keymap layer.

§Errors

A ChordParseError naming the first bad token; the empty string is ChordParseError::Empty.

§Examples

use lattice_protocol::{KeyChord, parse_chord_sequence};

assert_eq!(
    parse_chord_sequence("gg").unwrap(),
    vec![KeyChord::char('g'), KeyChord::char('g')]
);
// Ctrl letters normalise to lowercase; `<lt>` is a literal `<`.
assert_eq!(parse_chord_sequence("<C-W>").unwrap(), vec![KeyChord::ctrl('w')]);
assert_eq!(parse_chord_sequence("<lt>").unwrap(), vec![KeyChord::char('<')]);
// An unmodified <Space> is the space character.
assert_eq!(parse_chord_sequence("<Space>f").unwrap()[0], KeyChord::char(' '));