Jump to content

Snippets mid-string expansion not working as expected


Recommended Posts

Maybe this is a German-language-only-problem, but snippet expansion does not work as expected when mid-string expansion is unflagged: If the string left of the snippet also is an expanded snippet, it won't be recognized as a string, so the second snippet expands.

 

Example:

I have a snippet "Wwi" for German "Organisation" (organization). I also have a snippet "ssy" for German "systemtheoretisch". Now, when I try to type German "Organisationssystem" (organizational system) by typing "Oor"+"system" the "Oor" expands and the mid-string "ssy"  is expanded.

Link to post

@miq Could you please give a clearer example? I'm not sure I understand exactly what you're typing in and in what order to result in the mid-string expansion you're describing.

 

Could you also please provide a screenshot of your snippet collection to help clarify your keywords and the pasted content?

 

Cheers,
Vero

Link to post

They're typing "Oor" which expands to "Organisation|", then they start typing "ssystem" to complete the word "Organisationssystem", whereby Alfred recognises the snippet keyword "ssy" and expands it (to "systemtheoretisch") even though "Expand snippets mid-string" is turned off.

 

Alfred appears not to notice if an expansion has left the cursor mid-string, so if you immediately type another snippet keyword, it will expand it even though the cursor is mid-string and mid-string expansion is turned off.

Edited by deanishe
Link to post

Meanwhile I have made up an English example that is not so realistic but hopefully is easier to follow. I post it here, even if the problem is probably already clear thanks to @deanishe (thanks!).

 

Say we have two snippets: 
- keyword 'hha' for snippet "hand|"
- keyword 'icr' for snippet "craftsman|".

 

1. We want to type the word "handicap":
Typing snippet 'hha' + rest of the word 'icap', we get: "handicap".

 

But:

2. We want to type "handicraft":
Typing snippet 'hha' + rest of the word 'icraft', as soon as we type 'hhaicr', Alfred recognizes 'hha' and 'icr' and expands both to "handicraftsman" even though 'icr' is mid-string.

 

As I said, this example might be a little constructed. In German though, we hava lots of long compound words…

Link to post

@miq Thanks for providing this example, and @deanishe for your input. In your example, "icr" isn't considered to be mid-string.

 

Once a snippet is expanded, the mid-string marker is reset, as the snippet is now done. As such, Alfred treats the next typed characters as a new word, and doesn't stop you from typing two snippets concurrently.

 

An example where a snippet keyword would be found mid-string is where you're typing the word "handicap" in a sentence, but you also have "ndi" as a snippet in one of your collections. Alfred won't treat "ndi" as a snippet keyword when mid-string expansion is disabled, as it isn't at the beginning of a string.

 

Hope this helps :)

 

Cheers,
Vero

Link to post

Thank you very much for your reply, @Vero!

I understand that this behaviour is intented. I think it might be worth considering to change Alfreds mid-string reset habits? As I said, in German we have many long compound words, but most commonly there are some letters in between, so that pure stringing together snippets is very rarely viable. Do you think it would be disadvantageous to reset the mid-string marker only after a subsequent space character? Or is this actually a feature that I'm missing?

Link to post

@miq It would be preferable for you to set keywords that won't accidentally be triggered. While I understand you want to keep the keywords as short and effortless as possible, it may be worth looking at prefixes, or using capitalisation to ensure that they're more unique.

 

Here are some examples of recommendations for reliable, easy keywords that are less likely to accidentally trigger:

https://www.alfredapp.com/help/features/snippets/#tips-expansion

 

Cheers,
Vero

Link to post
1 hour ago, Vero said:

Once a snippet is expanded, the mid-string marker is reset, as the snippet is now done. As such, Alfred treats the next typed characters as a new word, and doesn't stop you from typing two snippets concurrently.

 

Why does it do that? That sounds sub-optimal. I mean, what's the purpose of being able to turn off mid-string expansion if you still always have to use keywords that never occur anywhere in a word (and not just at the start)?

 

In @miq's case, there's no question that the cursor is in the middle of a word. It makes no difference to the text or the user whether Alfred inserted the first half of the word or they did. It seems to me, it would be better if it didn't matter to Alfred, either.

 

Edited by deanishe
Link to post
18 hours ago, deanishe said:

Why does it do that? That sounds sub-optimal.

 

Perhaps the option is poorly worded, but it's not related to the [corner] case outlined here.

 

There are very many times where I want to expand snippets sequentially, i.e. 3 snippet keywords in a row... however, I don't want snippets to expand mid typing a word. This option will prevent a snippet with keyword 'ana' from expanding when typing banana, however it won't stop me using keyword 'ana' directly after using another snippet, regardless of what that other snippet's content.

 

It's worth noting that all the keyword examples used in this thread actually go against the recommended keyword syntax to make the unique. For example, all of my actual snippet keywords are prefixed with the § character, which on UK keyboards is above the tab key as a single press... An otherwise useless key in my case has now become the 'about to type a snippet expansion keyword' key.

 

By picking a non alphanumeric keyword, the likelihood of this mid-string case ever even being an issue is fractional, making this option useful for its intended purpose.

Link to post
Posted (edited)

Thank you for your reply, @Andrew! Although I get your point, to me, this does not sound very consistent, either. 

 

First, I have about 200 snippets with keywords that go back almost 15 years now. Back then, I followed a recommendation by TextExpander to use double characters at the start. In Alfreds Tips For Better Snippet Expansion, the same recommendation is included: "Use double characters (e.g. ttime)". All my keywords follow this rule and in my first example, the problem results just from the keywords "Oor" and "ssy".

 

Second, when one uses password-like keywords as you suggest, the mid-string-option seems obsolete at all, as there are very few cases in which non alphanumeric combinations occur in the middle of a word. So to me it seems like the middle-string-option only makes sense for keywords like in your example "ana".

 

Third, I am not sure what the use case for sequential snippets might be. Perhaps for writing code? For natural languages other than English the case I described is problematic: often, words consist of parts that can be 'snippetized' but often do require extra letters between them. Sequential snippets without mid-string expansion do not appear to be designed for natural language text production.

 

Having a "snippet key" like "§" in your case sounds like a very good idea to me. For me though, after getting used to lots of keywords over the years, it is not really an attractive option.

 

Could an extra option "allow sequential snippets" be a solution for both scenarios?

Edited by miq
Link to post

@miq Double characters is suitable in some cases but it isn't a foolproof solution; Choosing that option requires some thought and sometimes - as with your example - some exceptions. You might want to add some out-of-order capitals, for example. 

 

Here's some insight into sequential snippets, using an example I use many times a day. We've created a huge snippet library of helpful support answers, links, code snippets, etc which we use to provide responses. I can then tailor the response, but it gives me a good starting foundation without typing til my fingers fall off.

 

For example, my response to someone who's emailed to recover their license:

 

Hi Andrew,

"plS4" which expands to "No problem, please find below your Alfred 4 Powerpack license code:"

[I paste their license code, which is already in my clipboard]

"yen4" which expands to the explanation of where to download Alfred 4

"cV" which expands to 
"Cheers,
Vero"

 

Aside from "Hi Andrew,", I can write the entire email in 10 typed characters, plus pasting the license code: plS4⌘vyen4cV   :D 

 

Each snippet takes care of including the necessary trailing new lines to ensure I'm at the right place for the next sequential snippet I'm pasting.  While my snippets are short, they won't be accidentally triggered as they don't use a normal combination of letters I'm likely to type in everyday phrases.

 

Andrew describes your scenario as a corner case as it's the first time this issue has been raised, throughout the years since we released this feature. We are always listening to the community, and read every thread and email. If many users were encountering this issue, we would certainly consider providing solutions. However, for the time being, this would just complicate the text expansion settings further.

 

Cheers,
Vero

Link to post
4 hours ago, Andrew said:

I don't want snippets to expand mid typing a word. This option will prevent a snippet with keyword 'ana' from expanding when typing banana, however it won't stop me using keyword 'ana' directly after using another snippet, regardless of what that other snippet's content.

 

I'm sorry. I don't follow your line of reasoning.

 

If Alfred will always expand snippets mid-word under certain circumstances, regardless of the mid-string expansion setting, then the only way to prevent unwanted expansion is to use unique keywords that will never occur organically, like you recommend.

 

But if unique keywords are required to get optimal behaviour, anyway, what's the benefit in turning off mid-string expansion?

 

4 hours ago, Andrew said:

It's worth noting that all the keyword examples used in this thread actually go against the recommended keyword syntax to make the unique.

 

I know. But for me – and I suspect for a lot of other users – the option to turn off mid-string expansion is the option to turn off weird keyword prefixes.

Edited by deanishe
Link to post
17 minutes ago, deanishe said:

I'm sorry. I don't follow your line of reasoning.

 

Regardless, this is the first time that this has been highlighted, so while I can see that there is the possibility of additional configuration, as always, it's unlikely that a change in behaviour, or a new option will be added unless this becomes a popular request.

 

Sequential snippet expansion is different to mid-string expansion.

 

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...