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

feature request: Expand abbreviation when entering a closing parenthesis #6658

Closed
scooter-dangle opened this issue Feb 26, 2020 · 7 comments
Closed

Comments

@scooter-dangle
Copy link

scooter-dangle commented Feb 26, 2020

I didn't find this mentioned in any of the issue titles, but it's possible it was brought up tangentially in an issue around abbr.

Generally when I use an abbreviation in a command substitution, the closing ) unambiguously indicates that the token is complete, at which point it would be convenient if the abbreviation were expanded.

For example, I have the follow abbreviation defined for listing modified files:

abbr --add gsmod 'git ls-files --modified'

If I wanted to open all the modified files, I would run

vim (gsmod)

which works as intended, since the )<CR> combination triggers the expansion to

vim (git ls-files --modified)

However, if I wanted to pass any options to vim after the substitution, the following would not expand and would cause an error when entered

vim (gsmod) -O

since I have no function or commands named gsmod.

The workaround I use is to remember to add an extra space prior to the ) in cases where I know I'll be adding more to the command, which results in

vim (git ls-files --modified ) -O

Granted, there could be consequences of supporting additional expansion triggers that I haven't thought of.

@krobelus krobelus added this to the fish-future milestone Feb 27, 2020
@scooter-dangle scooter-dangle changed the title feature request: Expand abbrevation when entering a closing parenthesis feature request: Expand abbreviation when entering a closing parenthesis Feb 28, 2020
@faho
Copy link
Member

faho commented Mar 7, 2020

This is easy:

bind ')' self-insert expand-abbr

I'm gonna have to think some about whether it makes sense as a default.

@krobelus
Copy link
Member

krobelus commented Mar 7, 2020

A similar issue applies to the other statement terminators |, &, ; and \e\r as well as perhaps even < and >, let's see.

@faho
Copy link
Member

faho commented Mar 7, 2020

So good news is we only expand the abbreviation if the cursor is at the end of it.

That means if we bind ')' et al to expand them, this only applies if you type e.g.

something (smth)

and not

something (smth )

and \e\r as well as perhaps even < and >, let's see.

Tbh I always hated how execute expands abbrs, because that makes using abbrs with the same name as commands (like rm for rm -I) worse.

Tho now that we can bind ctrl-space it's possible to bind that to inserting space without expanding, so it's possibly not as bad.

@krobelus
Copy link
Member

krobelus commented Mar 7, 2020

I didn't mean \r / execute but the actual \e\r which is commandline -i \n.
I find the abbreviation logic a bit confusing, though it works really well in most cases.

Good point, I think execute should not always expand abbreviations, but only if the cursor is at the command token. I don't think that behavior would surprise anyone (if you have more tokens you likely already expanded the abbreviation with a space). This should be more discoverable thatn ctrl-space.

Edit: nevermind, we already do this.
Also if a command is valid, like rm, it is not expanded by execute.

@faho
Copy link
Member

faho commented Mar 7, 2020

I didn't mean \r / execute but the actual \e\r which is commandline -i \n.

Oh, sorry, missed that!

Also if a command is valid, like rm, it is not expanded by execute.

It is expanded? Unless there's been a super recent change, I've been running 3.1 for a bit now.

@krobelus
Copy link
Member

krobelus commented Mar 7, 2020

No, it will only be expanded in execute if the token left of the cursor is in command position.
Here it's a bit off but the example is contrived..

$ abbr -g echo echo 123
$ echo $version
       ^
123 3.1.0
$ echo $version
        ^
3.1.0

@faho faho closed this as completed in 8ddd512 Mar 21, 2020
@faho
Copy link
Member

faho commented Mar 21, 2020

Okay, so I made it so that ctrl-space enters a space without expanding abbreviations, and made ")" and alt-enter expand abbreviations.

@zanchey zanchey modified the milestones: fish-future, fish 3.2.0 Mar 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants