Injecting variables into nested matches #1753
-
Does anyone know a way to inject variables into nested matches? It would be nice to overwrite default fields in sub matches, because that way you could modularize and reuse more. Here's an example of what I mean: matches:
- trigger: ':default_fraction'
replace: '\frac{{{numerator}}}{{{denominator}}}'
label: 'A LaTeX fraction that is empty by default'
vars:
- name: numerator
type: echo
params:
echo: $|$
- name: denominator
type: echo
params:
echo: ''
- trigger: ':specific_fraction'
replace: '\left( {{fraction}} \right)'
label: 'A specific LaTeX fraction that re-uses the general fraction'
vars:
- name: numerator
type: echo
params:
echo: specific numerator
- name: denominator
type: echo
params:
echo: specific denominator
- name: fraction
type: match
depends_on: ['numerator', 'denominator']
params:
trigger: ':default_fraction'
# the following parameters should be injected into the :default_fraction vars
numerator: '{{numerator}}'
denominator: '{{denominator}}'
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
This snippet doesn't work, it's just to clarify the idea |
Beta Was this translation helpful? Give feedback.
-
Hi! Thanks for the question. I'm new to espanso and to the repo too! I read your post and thought that maybe you have to escape the triple |
Beta Was this translation helpful? Give feedback.
-
I've been playing around with how espanso nested matches work, and it seems that espanso doesn't pass the environment of the caller to the nested match. I've reworked the example so that typing matches:
- trigger: ':ta'
force_clipboard: true
replace: |
Inner env:
{{env}}
vars:
- name: env
type: shell
params:
cmd: 'env | grep -i espanso'
- name: var
type: shell
params:
cmd: 'echo ${ESPANSO_OUTER_VAR:-inner default}'
- trigger: ':tb'
force_clipboard: true
replace: |
Outer env:
{{outer_env}}
{{inner}}
vars:
- name: outer_var
type: shell
params:
cmd: echo a
- name: outer_env
type: shell
depends_on: ['outer_var']
params:
cmd: env | grep -i espanso
- name: inner
type: match
depends_on: ['outer_var']
params:
trigger: ':ta'
# the following parameters should be injected into the environment
var: '{{outer_var}}'
outer_var: '{{outer_var}}' This produces output like the following:
I think I could write stuff in some cache file, and get it from there, but that seems really miserable. Anyone got a better idea? |
Beta Was this translation helpful? Give feedback.
No worries, please make sure you don't burn out! I'll see if I find the time to take a look myself. And thanks for developing this!