Pass indented commandline to editor on alt-e#10437
Closed
krobelus wants to merge 3 commits intofish-shell:masterfrom
Closed
Pass indented commandline to editor on alt-e#10437krobelus wants to merge 3 commits intofish-shell:masterfrom
alt-e#10437krobelus wants to merge 3 commits intofish-shell:masterfrom
Conversation
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
vertesians
pushed a commit
to vertesians/fish-shell
that referenced
this pull request
Apr 17, 2024
See also the earlier commits. Closes fish-shell#10437
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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