Static matches are simple enough we could potentially define trigger and replace as simple key: value pairs.
- trigger: ":espanso"
replace: "Hi there!"
- ":espanso": 'Hi there!'
matches could interpret non-espanso keys as triggersAs long as the trigger is valid yaml & not an espanso key word, each key: value it could still go under matches:
matches:
- ":espanso": 'Hi there!'
or
simple_matches sectionsimple_matches:
- ":espanso": 'Hi there!'
I assume each items simple_matches could be formatted to trigger: {key} replace: {value} and extend the matches collection.
It could be possible to do both and leave organization up to the user.
If I had to pick one way though I'd probably do simple_matches - it seems easier to implement & explain.
Simple matches could be especially useful in combination with word triggers.
Each word trigger adds 1 line for word: true, and I imagine most word triggers are also static matches.
matches:
- trigger: "hey"
replace: 'Hey there!'
word: true
- trigger: "hello"
replace: 'Hello there!'
word: true
- trigger: "hej"
replace: 'Hall氓 d盲r!'
word: true
could become
word_matches:
- hey: 'Hey there!'
- hello: 'Hello there!'
- hej: 'Hall氓 d盲r!'
Hey @mrgnw,
Thank you for the feedback! Indeed, a shorthand to declare simple matches would be useful. Given this problem, we have 3 constraints:
Possibly, we would also like something elegant. While I like your proposed approach, I don't like the fact of having two additional word_matches or simple_matches keys. I feel matches should reside in the matches key, otherwise that might become confusing to the user. On the other hand, including the map-like syntax in the matches clauses could be problematic, as it could conflict with existing reserved keys.
Another possibility would be to use an array-like syntax:
matches:
- [:espanso, Hi there!]
- [hey, Hey there!, w]
- trigger: "hej"
replace: 'Hall氓 d盲r!'
word: true
The rationale would be to mix the standard syntax with an array-like one, in which the first argument is the trigger, the second one the replacement and, optionally, the third one for modifiers (word, propagate_case, ecc).
The upside of this one is that it's easier to implement, as the above is valid YAML and an array is easy to discriminate from an object. I don't think it's very elegant though.
We'll need to think carefully about this feature, hopefully getting some feedback from the community.
Let me know what you think :)
I like it!
Array-like syntax seems like the best combination of concise, easy to implement, and flexible with more options than just static matches.
As you said this all depends on community's use, so I'm trying to feel out the most concise way to write the most common use case (or two). I assume static matching is most common, followed by word matches. Word matches & other modifiers also seems more compressible, since each modifier adds a line per match.
Additional thoughts purely for the sake of brainstorming & conceptualization - I imagine these might not fit the constraints yet but maybe one could get close, or maybe they could helps us get to something else down the road.
matches:, with array-like syntax for modifiersmatches:
- ":espanso": "Hi there!"
- "hey": [Hey there!, w]
- "hej": [Hall氓 d盲r!, w]
(still have to account for keyword conflicts)
Or for whatever the most common / simple use cases are
matches:
- static:
- ":espanso": "Hi there!"
- ":x2": "Hi again!"
- word:
- hey: hey there!
- hej: Hall氓 d盲r!
- trigger: ":bye"
replace: "See you later!"
(no keyword conflicts, but adds 1-2 new keywords/features: word or static or both)
word: true and using a prefix cover the same core concern - not accidentally triggering matches.
For simple matches, would it be reasonable to assume:
matches:
- simple:
- ":espanso": "Hi there!"
- ":x2": "Hi again!"
- hey: hey there!
- hej: Hall氓 d盲r!
- trigger: ":bye"
replace: "See you later!"
(no keyword conflicts, but 1 new keyword/feature, with an assumption that prefixes & word matches work together for the same purpose)
@mrgnw Thank you for the ideas, those are indeed good points. I'll make sure to keep them in mind when evaluating the possibilities for the future :)
A possibility to simplify the way of writing the yaml file is just give the possibility to directly pass a list of pairs trigger: replace from the console, by example something like espanso yaml-file add trigger1: replace1, trigger2: replace2, ..., where yaml-file is the name and location of the yaml file where you want to add the pairs (and it would be nice that the program accept the location of the yaml file relative to the location of the default yaml file, independently where espanso is called).
The main advantage of this approach is that it makes faster to add a pair or list of pairs: you only need to open the console and do it, so you dont need to navigate to where the yaml file is located, neither need to open a text editor or follow the more strict syntax of a yaml file, and more important: the yaml file still will be a yaml file, you dont need to add a special configuration text file with a custom syntax.
However, there are drawbacks when you dont use a text editor to change something in a configuration file, by example you dont see if you did some mistake when adding a pair. For these drawbacks it could help a function espanso yaml-file delete trigger1, trigger2,... to delete something that is wrong.
@Masacroso Thank you for the feedback, indeed a command-line option could make this process quick enough for most cases
Most helpful comment
Hey @mrgnw,
Thank you for the feedback! Indeed, a shorthand to declare simple matches would be useful. Given this problem, we have 3 constraints:
Possibly, we would also like something elegant. While I like your proposed approach, I don't like the fact of having two additional
word_matchesorsimple_matcheskeys. I feel matches should reside in thematcheskey, otherwise that might become confusing to the user. On the other hand, including the map-like syntax in thematchesclauses could be problematic, as it could conflict with existing reserved keys.Another possibility would be to use an array-like syntax:
The rationale would be to mix the standard syntax with an array-like one, in which the first argument is the trigger, the second one the replacement and, optionally, the third one for modifiers (word, propagate_case, ecc).
The upside of this one is that it's easier to implement, as the above is valid YAML and an array is easy to discriminate from an object. I don't think it's very elegant though.
We'll need to think carefully about this feature, hopefully getting some feedback from the community.
Let me know what you think :)