8000 Run `fish_indent` on `funcsave` by kidonng · Pull Request #8603 · fish-shell/fish-shell · GitHub
[go: up one dir, main page]

Skip to content

Run fish_indent on funcsave#8603

Closed
kidonng wants to merge 2 commits intofish-shell:masterfrom
kidonng:patch-8
Closed

Run fish_indent on funcsave#8603
kidonng wants to merge 2 commits intofish-shell:masterfrom
kidonng:patch-8

Conversation

@kidonng
Copy link
Contributor
@kidonng kidonng commented Jan 2, 2022

Description

funced already run fish_indent when the editor is fish:

if test "$editor" = fish
if functions -q -- $funcname
functions --no-details -- $funcname | fish_indent --no-indent | read -z init
end
set -l prompt 'printf "%s%s%s> " (set_color green) '$funcname' (set_color normal)'
if read -p $prompt -c "$init" --shell cmd
echo -n $cmd | fish_indent | read -lz cmd
eval "$cmd"
end
if set -q _flag_save
funcsave $funcname
end
return 0
end

It makes sense to have funcsave run it as well.

Maybe we should also run fish_indent after funced finishes?

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@floam
Copy link
Member
floam commented Jan 3, 2022

I'm not sure about this one. If I enter a function a certain way interactively, can see it that way with 'functions', might I be a little surprised to find something different written to disk?

@kidonng
Copy link
Contributor Author
kidonng commented Jan 3, 2022

Interestingly, funcsave's manpage says:

This function will be automatically loaded by current and future fish sessions.

But the functions is clearly not autoloaded:

$ function t; end
$ functions -Dv t
stdin
n/a
0
scope-shadowing
n/a

Is the manpage wrong, or the function can be made autoloaded later via some magic I don't know? If the latter is true, then the function shown in functions will be formatted as well once fish autoloads it.

Ideally fish will automatically run fish_indent on interactively defined functions. But for this PR, there are some solutions I can think of:

  • Do nothing about the interactively defined function. I don't really think it's a problem, since fish_indent doesn't change anything except the format. We can mention in the manpage that if people really want to preserve the format for some reason, just run functions --no-details -- $funcname > $file themselves.
  • Only run fish_indent if given a -f/--format flag. Surely everything can be an option right?
  • source the just saved function file. This however changes the description of the function from Defined interactively to Defined in foo.fish @ line 1.
  • eval the formatted function and save it. That way the description of the function stays Defined interactively but eval is evil...

@kidonng kidonng changed the title Run fish_indent after funcsave Run fish_indent on funcsave Jan 4, 2022
@IlanCosman
Copy link
Contributor
IlanCosman commented Jan 5, 2022

But the functions is clearly not autoloaded:

I don't see where you ran funcsave t. You need to do so to have t be autoloaded. And it won't say autoloaded in the current shell, because it wasn't autoloaded, you defined it interactively. In future shells it will be autoloaded, and will say so correctly.

@faho
Copy link
Member
faho commented Feb 8, 2022

Okay, it seems we don't want to do this. Sorry!

@faho faho closed this Feb 8, 2022
@kidonng
Copy link
Contributor Author
kidonng commented Feb 9, 2022

Okay, it seems we don't want to do this. Sorry!

@faho would you be happy to accept a PR to add the functionality behind a flag (e.g. funcsave --indent), instead of doing it automatically (which may not be what the user expect), as mentioned above?

@floam
Copy link
Member
floam commented Feb 9, 2022

Something I was not aware of until just now: functions created interactively seem not to have tabs preserved at all:
Screen Shot 2022-02-08 at 7 08 27 PM

@kidonng
Copy link
Contributor Author
kidonng commented Feb 9, 2022

Something I was not aware of until just now: functions created interactively seem not to have tabs preserved at all:

Right, that's the initial motivation of this PR. I got tired of having to run fish_indent manually after funcsave, because the saved function is not indented all.

@krobelus
Copy link
Contributor
krobelus commented Feb 9, 2022 via email

@kidonng
Copy link
Contributor Author
kidonng 8000 commented Feb 9, 2022

As a workaround, how about teaching your editor to run fish_indent when you save a *.fish file?

Actually my main editor (VSCode) is already configured so (via https://marketplace.visualstudio.com/items?itemName=bmalehorn.vscode-fish), however I have the issue when defining it interactively (as demonstrated by @floam above).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2023
@krobelus krobelus added this to the fish next-3.x milestone Apr 12, 2024
krobelus added a commit to krobelus/fish-shell that referenced this pull request Apr 12, 2024
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes fish-shell#8603
krobelus added a commit to krobelus/fish-shell that referenced this pull request Apr 12, 2024
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes fish-shell#8603
@krobelus
Copy link
Contributor

this should be addressed by #10437 which makes functions foo and type foo output indented code

krobelus added a commit that referenced this pull request Apr 15, 2024
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes #8603
vertesians pushed a commit to vertesians/fish-shell that referenced this pull request Apr 17, 2024
This means that in case no editor is defined, "fish_indent" is now required
to fix the indentation.

Fixes fish-shell#8603
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.

5 participants

0