8000 Pass indented commandline to editor on `alt-e` by krobelus · Pull Request #10437 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

Pass indented commandline to editor on alt-e#10437

Closed
krobelus wants to merge 3 commits intofish-shell:masterfrom
krobelus:indent-for-external-editor
Closed

Pass indented commandline to editor on alt-e#10437
krobelus wants to merge 3 commits intofish-shell:masterfrom
krobelus:indent-for-external-editor

Conversation

@krobelus
Copy link
Contributor

Indented multiline commandlines look ugly in an external editor. Also,
fish doesn't properly handle the case when the editor runs fish_indent.
Fix is by indenting when exporting the commandline and un-indenting when
importing the commandline again.

Unindent only if the file is properly indented (meaning at least by the
amount fish would use). Another complication is that we need to offset
cursor positions by the indentation.

This approach exposes "fish_indent --only-indent" and "--only-unindent"
though I don't imagine they are useful for others so I'm not sure if this
is the right place and whether we should even document it.

One alternative is to add "commandline --indented" to handle indentation
transparently.
So "commandline --indented" would print a indented lines,
and "commandline --indented 'if true' ' echo'" would remove the unecessary
indentation before replacing the commandline.
That would probably simplify the logic for the cursor position offset.


Last commit is a related fix:

builtins type/functions: indent interactively-defined functions

This means that in case no editor is defined, "fish_indent" is now required.

Fixes #8603

To be used in the following commits.
One tricky bit is that we need to unindent the resulting command line because
fish already indents. Do this only if the file is properly indented (meaning
at least by the amount fish would use).  Another complication is that we
need to offset cursor positions by the indentation.

This approach exposes "fish_indent --only-indent" and "--only-unindent"
though I don't imagine they are useful for others so I'm not sure if this
is the right place and whether we should even document it.

One alternative is to add "commandline --indented" to handle indentation
transparently.
So  "commandline --indented" would print a indented lines,
and "commandline --indented 'if true' '    echo'" would remove the unecessary
indentation before replacing the commandline.
That would probably simplify the logic for the cursor position offset.
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes fish-shell#8603
@krobelus krobelus mentioned this pull request Apr 12, 2024
3 tasks
@krobelus krobelus added this to the fish next-3.x milestone Apr 13, 2024
@krobelus krobelus closed this in a37629f Apr 15, 2024
vertesians pushed a commit to vertesians/fish-shell that referenced this pull request Apr 17, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0