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

Passing the cursor position to edit_command_buffer #6138

rien333 opened this issue Sep 24, 2019 · 4 comments

Passing the cursor position to edit_command_buffer #6138

rien333 opened this issue Sep 24, 2019 · 4 comments


Copy link

rien333 commented Sep 24, 2019

The alt+e bind to edit_command_buffer - that is, opening the current command in $EDITOR - is very handy. However, often I only realize half way editing a command that using my $EDITOR would be more convenient. In such cases, it's pretty cumbersome and superfluous to navigate to where I had my cursor in the fish shell, before I started my $EDITOR session.

Fortunately, editors like emacs (and maybe also vim) can be told to open a file at a specific line and column:

emacsclient --help
Usage: emacsclient [OPTIONS] FILE...
Tell the Emacs server to visit the specified files.
Every FILE can be either just a FILENAME or *[+LINE[:COLUMN]]* FILENAME.

Therefore, it would be great if edit_command_buffer could be told about the current cursor column (and possibly line). Afaik, there is currently no good way to pass such information to edit_command_buffer. I'm also not sure if it's possible to get the cursor's current column, and then pass that as some kind of argument to edit_command_buffer.

Copy link

zanchey commented Sep 24, 2019

So, there's commandline --cursor, which prints the offset from the origin of the line, which would work fine for the singe-line case. You could probably hack that into a lines/column thing in script, though my version is not terribly elegant:

function coord
    set -l offset (math (commandline --cursor ) + 1)
    set -l col 1
    set -l line 1
    set -l IFS
    set -l currpos 1
    set -l cmdline (commandline)
    while test $currpos -le $offset
        set -l curr (string sub --start $currpos --length 1 -- $cmdline)
        if test "$curr" = \n
            set line (math $line + 1)
            set col 0
            set col (math $col + 1)
        set currpos (math $currpos + 1)
    echo $line:$col

Anyway, the output of the coord function can be passed along to emacsclient.

I don't think we're likely to change edit_command_buffer, because of the minimal support for the concept - happy to hear other ideas though.

Copy link

krobelus commented Nov 2, 2019

I think we can support passing the cursor position to some editors without breaking anyone. Most editors I can think of support some variation of +line:col file or file:line:col.

Copy link

rien333 commented Nov 2, 2019

Certainly terminal editors (even nano, apparently).

Copy link

zanchey commented Nov 3, 2019

Switching on $EDITOR seems reasonable, though will probably have a lot of false negatives.

ee, joe and vim seem to only support line number, not column. At least for vim you can use a -c argument to move the cursor after starting.

@zanchey zanchey added this to the fish-future milestone Nov 3, 2019
@krobelus krobelus modified the milestones: fish-future, fish 3.2.0 Mar 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

3 participants