Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arguments for autofills? #118

Closed
Krutonium opened this issue Nov 13, 2019 · 10 comments
Closed

Arguments for autofills? #118

Krutonium opened this issue Nov 13, 2019 · 10 comments

Comments

@Krutonium
Copy link

For example, if I could do :wttrinberlin it would look up the weather in Berlin and return it to me, while :wttrintoronto would return the weather in Toronto, except that berlin and toronto are not hardcoded options - I would have a script that takes the string after :wttrin and returns the weather for that location.

Possible?

@federico-terzi
Copy link
Collaborator

Hi @Krutonium,
Thanks for the great feedback, I'll definitely add it to the roadmap.

Thank you for your help

@tiktuk
Copy link

tiktuk commented Dec 5, 2019

I came here to suggest something similar.

It could be great if one could pass arguments with triggers. Could work like this:

- trigger: ":greet/Tuk"
  replace: "Hi {{}},\n\nthanks for your message.."

{{}} would then be replaced with Tuk.

Keyword arguments could work like this:

- trigger: ":greet/name=Tuk"
  replace: "Hi {{ name }},\n\nthanks for your message.."

Lists of arguments would also be useful:

- trigger: ":greet/Tuk,mail"
  replace: "Hi {{}},\n\nthanks for your {{}}.."

Once again, thank you so much for Espanso!

@federico-terzi
Copy link
Collaborator

Hi @tiktuk,
Thanks for your suggestion, I'm still considering a good way to implement this feature and all the help is appreciated.

At the moment, the biggest problem is related to the termination character. Let's say I follow your suggestion with something like:

- trigger: ":greet/Tuk"
  replace: "Hi {{}},\n\nthanks for your message.."

At that point, to use it the user would type something like: :greet/Bob

which would get expanded into:

Hi Bob,

thanks for your message...

Let's say I want to use Jon Snow instead: I would type :greet/Jon Snow but this would get expanded into:

Hi Jon,

thanks for your message...

because of the space character. To solve this problem, we need a termination character to tell espanso where the arguments end, something like: :greet/Jon Snow/, which would work ok.

What if the variable has to include the / char? How to separate multiple arguments? What if the user changes it's mind and stop writing in the middle of a parameter?

Those questions need careful evaluation before implementing the feature. I'm welcome to every feedback.

Thanks for your help :)

@timorunge
Copy link
Contributor

What if the variable has to include the / char? How to separate multiple arguments? What if the user changes it's mind and stop writing in the middle of a parameter?

Another question is: Will this scale? What to do if you wanna implement the same with two variables? Personally I'd suggest some kind of a sed implementation which is more generic and where you have the possibility to replace more than just one variable.

echo 'First Second Third' | sed -e 's/First/Still first/;s/Second/2nd/;s/Third/RLY?/'

This could end up in something like:

- trigger: ":greet;s/$1/Jon Snow/;s/$2/today/"
  replace: "Hi {{$1}},\n\nthanks for your message from {{$2}}..."

@tiktuk
Copy link

tiktuk commented Dec 7, 2019

because of the space character. To solve this problem, we need a termination character to tell espanso where the arguments end, something like: :greet/Jon Snow/, which would work ok.

But that wouldn't work for multiple arguments, no? Espanso wouldn't know whether the argument or the trigger ended. (Eg. :greet/Jon Snow/mail/).

Arguments with spaces could require quotes: :greet/"Jon Snow". For multiple args: :greet/"Jon Snow",mail,today. Here comma is a special character as well of course.

What if the variable has to include the / char?

Escape with \ like in most string formatting? Actually we should then maybe use another character than / for denoting the beginning of arguments. \/ looks so confusing in regular expressions.. Maybe ? like in URLs?

How to separate multiple arguments?

With comma? Won't occur often in parameters I would think.

What if the user changes it's mind and stop writing in the middle of a parameter?

I guess Espanso can't know whether the termination character is coming at some point. Maybe have some max argument length?

Another approach would be to have a dialog with text inputs for each argument pop up. Would solve a few of the questions. But increase the amount of platform specific code. And it's also nice to be able to specify everything with text.

Thanks for your help :)

Thank you!

PS: @timorunge If some generel solution already exists, great! As long as it's easy to write.

@federico-terzi
Copy link
Collaborator

Hey guys,

To answer @timorunge:

Another question is: Will this scale? What to do if you wanna implement the same with two variables? Personally I'd suggest some kind of a sed implementation which is more generic and where you have the possibility to replace more than just one variable.

echo 'First Second Third' | sed -e 's/First/Still first/;s/Second/2nd/;s/Third/RLY?/'

This could end up in something like:

- trigger: ":greet;s/$1/Jon Snow/;s/$2/today/"
  replace: "Hi {{$1}},\n\nthanks for your message from {{$2}}..."

I see your point. The only thing that concerns me about your solution is the number of characters a user would need to type, as this long syntax would make those expansions potentially slower to use than typing the output directly.

I mean, if the user had to type: :greet;s/$1/Jon Snow/;s/$2/today/ then probably he's better off typing the output directly. If, on the other hand, the user had to type: :greet/Jon Snow/today/ then it could be easier. I hope to have understood your point correctly, but perhaps I didn't.

To answer @tiktuk

But that wouldn't work for multiple arguments, no? Espanso wouldn't know whether the argument or the trigger ended. (Eg. :greet/Jon Snow/mail/).

Arguments with spaces could require quotes: :greet/"Jon Snow". For multiple args: :greet/"Jon Snow",mail,today. Here comma is a special character as well of course.

Quotes are surely a possible solution but they might make espanso less useful due to the increased verbosity. My main concern is usability here.

What if the variable has to include the / char?

Escape with \ like in most string formatting? Actually we should then maybe use another character than / for denoting the beginning of arguments. \/ looks so confusing in regular expressions.. Maybe ? like in URLs?

Sure, escaping would be the way to go. A good point in favor of \ is that is widely spread in many programming languages, so it would be easier to understand for most users.

How to separate multiple arguments?

With comma? Won't occur often in parameters I would think.

What if the user changes it's mind and stop writing in the middle of a parameter?

I guess Espanso can't know whether the termination character is coming at some point. Maybe have some max argument length?

The maximum length can possibly mitigate this problem, though it wouldn't be a definitive solution as many things could go wrong in the meanwhile.

Another approach would be to have a dialog with text inputs for each argument pop up. Would solve a few of the questions. But increase the amount of platform specific code. And it's also nice to be able to specify everything with text.

This could be definitely useful for many purposes, but the complexity here is quite high, especially considering the number of different platforms espanso has to support.

I've been thinking about this problem for a while. Although it could be possible to include this feature in the current mode operation of espanso, it has many problematic areas that might become very buggy in many situations. I think it could be much better if integrated with the passive mode proposed in #62, as in this case espanso would have a global view of the text to expand and we could employ more powerful parsing techniques.

In particular, the user would type something along:

:greet/Jon Snow/second/

More text...

:date

then he would select it with CTRL+A and then double click on CTRL+CTRL (or something else). At this point, espanso would be able to copy the text, analyze it in its entirety, replace it with more sophisticated parsing techniques and then paste the expanded text back in the field.
What do you think?

Thanks for your help guys

@tiktuk
Copy link

tiktuk commented Dec 12, 2019

That last approach sounds great, @federico-terzi ☺️ !

@david-fischer
Copy link

What do you think about an regex-approach?
Then one could specify the arguments by the regex-syntax and everyone can define their own seperator-char, which gives the flexibility to handle variables including a "/".

(sorry if the rust-regex-syntax differs slightly)

  • trigger: ":greet/([^/])/([^\s])\s"
    replace: "Hi {{\1}},\n\nthanks for your message from {{\2}}..."

Should give the deserved result for
:greet/Jon Snow/today (ending with a whitespace)

Also, the user can specify the max. length of the arguments via regex-syntax if deserved.

Thanks and keep up the great work!

@federico-terzi
Copy link
Collaborator

Hey @Davidf4,

Thank you very much for the great feedback. I don't know why but I didn't receive a notification for this message, otherwise, I would have replied earlier.
Yes, this approach is probably the most flexible one and probably the one that will get implemented. That said, it will only be available in passive mode #62 due to the many difficulties of regexes in "realtime" mode.

Thanks for your help :)

@federico-terzi
Copy link
Collaborator

Hey,
I'm closing this issue as the feature has been implemented in version 0.5.0 of espanso.

Cheers :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants