Advertisement
smeech

Autocomplete brackets

May 1st, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.84 KB | None | 0 0
  1. # Espanso trigger to autocomplete brackets etc. at the end of a string, on typing double-space.
  2. # It will fall over if there's a single-quote within the string, however.
  3.   - regex: '(?P<delim>[\[\(\{<"])(?P<string>.+)  '
  4.    replace: "{{output}}"
  5.    vars:
  6.      - name: output
  7.        type: script
  8.        params:
  9.          args:
  10.            - python
  11.            - -c
  12.            - |
  13.              closing_chars = { '[': ']',
  14.                                '{': '}',
  15.                                '(': ')',
  16.                                '<': '>',
  17.                                '"': '"',
  18.                                "'": "'" }
  19.              input_delim = '{{delim}}'
  20.              input_string = r'{{string}}'
  21.              closing_char = closing_chars.get(input_delim)
  22.              print(input_delim + input_string + closing_char)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement