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

Suggestions about edit:small-word-abbr behavior #1472

Closed
aca opened this issue Jan 12, 2022 · 6 comments · Fixed by #1549
Closed

Suggestions about edit:small-word-abbr behavior #1472

aca opened this issue Jan 12, 2022 · 6 comments · Fixed by #1549

Comments

@aca
Copy link
Contributor

aca commented Jan 12, 2022

Hi @krader1961
I'm trying to replace fish abbr with edit:small-word-abbr.

Current implementation seems to be

Skip an abbreviation if it begins with an alphanum and the previous
char in the insert buffer is also an alphanum or there is no
preceding char.
#980

But can we also skip an abbreviation if it begins with symbols like -, _ if it doesn't have matching abbr using it ?

If i set something like this.

set edit:small-word-abbr['k'] = 'kubectl'

ls -k<space> expands to ls -kubectl and it is obviously not intended.

@krader1961
Copy link
Contributor

FWIW, The edit:small-word-abbr behavior is based on, but not identical to, the Fish shell abbr behavior. It was a compromise between myself and the Elvish project owner; especially with regard to not treating pressing Enter the same as Space. Having said that, it does seem like the expansion should only occur if the prefix is whitespace (or start of line); not just the definition of a "small word". That would fix another annoyance I experience with this abbreviation:

set edit:small-word-abbr['l'] = 'less'

If I type ls -l then press Space the l is converted to less which is incredibly annoying and not how Fish handles that situation. I've just been living with that unwanted behavior. It's probably long past time to fix it.

@aca
Copy link
Contributor Author

aca commented Jan 12, 2022

expansion should only occur if the prefix is whitespace (or start of line)

I thought it was what edit:small-word-abbr intended to achieve (which was not with edit:abbr),

Fish abbr seems to expand only at "start of command" and it is quite nice. (Haven't looked at implementation details yet)

image

1, 3 expands 2 not.

@mredaelli
Copy link

If I type ls -l then press Space the l is converted to less which is incredibly annoying and not how Fish handles that situation. I've just been living with that unwanted behavior. It's probably long past time to fix it.

+1

Can we at least make it a configuration option? I wouldn't mind trying my hands at a PR if the solution would be accepted.

@krader1961
Copy link
Contributor

krader1961 commented May 18, 2022

From my comment in issue #1540 for anyone who stumbles upon this issue and wants to look at the implementation to understand why small word abbreviations behave like they do:

expanded upon typing a trigger character, which is currently a space or semicolon

Close, but not correct. See the implementation, but the short answer is that the trigger char simply has to be in a different category than the last character of the abbreviation; see the definition of CategorizeSmallWord. Consider this abbreviation: set edit:small-word-abbr['l'] = 'less'. If you type echo -l- the ell will be expanded to less because l is an alphanum and - is not.

@adamchristiansen
Copy link

I'm coming over from #1540, which does not seem like a great idea upon seeing the implementation (thanks @krader1961).

I see two potential changes/features in this thread:

If I type ls -l then press Space the l is converted to less which is incredibly annoying

Fish abbr seems to expand only at "start of command" and it is quite nice

As I see it there are really 3 options for a "fix":

  1. Introduce configuration options somewhere under $edit:... that allow these two behaviours.
  2. Change the behaviour of small-word abbreviations.
  3. Add a third type of abbreviation that behaves this way.

Option 3 in interesting as simple abbreviations and small-word abbreviations have a behaviour that is orthogonal to what we are describing here, which are really abbreviations that behave the same way as Fish abbreviations. We likely do not want 3 different kinds of abbreviations, so that may not be the best solution. I also agree with the following, which is a solution more like option 2:

If I type ls -l then press Space the l is converted to less which is incredibly annoying and not how Fish handles that situation. I've just been living with that unwanted behavior. It's probably long past time to fix it.

Is the intention of small-word abbreviations not to handle abbreviations in the same way as Fish? What is a use case for how Elvish handles small-word abbreviations where they are expanded like this?

@krader1961
Copy link
Contributor

krader1961 commented May 19, 2022

Is the intention of small-word abbreviations not to handle abbreviations in the same way as Fish?

No, it was meant to be more flexible by allowing expansion anywhere on the command line subject to the "small word" matching restriction. In contrast to the "simple" expansions created by edit:abbr which expand regardless of the preceding char and has no trigger char. The question is whether that flexibility is actually desirable.

Looking at my abbreviations I have only two "simple" abbreviations:

set edit:abbr['>dn'] = ' 2>/dev/null'
set edit:abbr['||'] = ' | less'

I have twenty small word abbreviations and every single one is only meant to be expanded in the command position; i.e., the Fish behavior. Which is why I'm sometimes annoyed when the expansion occurs at some other position of the command line.

I'm in favor of adding a third type of abbreviation that is only expanded in the command position; ala Fish. Perhaps named edit:command-abbr. There's probably no reason to remove the existing edit:small-word-abbr var even if, as I suspect, it would seldom be used given that most people would use edit:abbr or edit:command-abbr. Since we've already paid the cost of implementing small word abbreviations we might as well keep it just in case someone finds it useful.

krader1961 added a commit to krader1961/elvish that referenced this issue May 27, 2022
It turns out that the "small word" abbreviation mechanism I added isn't
really what I, or most users, want. What users really want, at least
most of the time, is the Fish shell abbreviation behavior of expanding
an abbreviation only in the command head position.

Resolves elves#1472
@xiaq xiaq closed this as completed in #1549 Jun 5, 2022
xiaq pushed a commit that referenced this issue Jun 5, 2022
It turns out that the "small word" abbreviation mechanism I added isn't
really what I, or most users, want. What users really want, at least
most of the time, is the Fish shell abbreviation behavior of expanding
an abbreviation only in the command head position.

Resolves #1472
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

Successfully merging a pull request may close this issue.

4 participants