mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-25 09:39:52 +08:00
builtins type/functions: indent interactively-defined functions
This means that in case no editor is defined, "fish_indent" is now required to fix the indentation. Fixes #8603
This commit is contained in:
parent
222673f339
commit
611a0572b1
|
@ -106,6 +106,7 @@ Interactive improvements
|
|||
- ``read --help`` and friends no longer ignore redirections. This fixes a regression in version 3.1 (:issue:`10274`).
|
||||
- Command abbreviations (those with ``--position command`` or without a ``--position``) now also expand after decorators like ``command`` (:issue:`10396`).
|
||||
- Abbreviations now expand after process separators like ``;`` and ``|``. This fixes a regression in version 3.6 (:issue:`9730`).
|
||||
- When exporting interactively defined functions (using ``type``, ``functions`` or ``funcsave``) the function body is now indented, same as in the interactive command line editor (:issue:`8603`).
|
||||
|
||||
New or improved bindings
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
@ -47,16 +47,12 @@ function funced --description 'Edit function definition'
|
|||
|
||||
if test "$editor" = fish
|
||||
if functions -q -- $funcname
|
||||
command -q fish_indent
|
||||
and functions --no-details -- $funcname | fish_indent --no-indent | read -z init
|
||||
or functions --no-details -- $funcname | read -z init
|
||||
functions --no-details -- $funcname | fish_indent --only-unindent | 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
|
||||
command -q fish_indent
|
||||
and echo -n $cmd | fish_indent | read -lz cmd
|
||||
or echo -n $cmd | read -lz cmd
|
||||
echo -n $cmd | fish_indent --only-unindent | read -lz cmd
|
||||
eval "$cmd"
|
||||
end
|
||||
if set -q _flag_save
|
||||
|
|
|
@ -8,6 +8,8 @@ use crate::event::{self};
|
|||
use crate::function;
|
||||
use crate::highlight::colorize;
|
||||
use crate::highlight::highlight_shell;
|
||||
use crate::parse_util::apply_indents;
|
||||
use crate::parse_util::parse_util_compute_indents;
|
||||
use crate::parser_keywords::parser_keywords_is_reserved;
|
||||
use crate::termsize::termsize_last;
|
||||
|
||||
|
@ -407,6 +409,10 @@ pub fn functions(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -
|
|||
def = props.annotated_definition(arg);
|
||||
}
|
||||
|
||||
if props.definition_file().is_none() {
|
||||
def = apply_indents(&def, &parse_util_compute_indents(&def));
|
||||
}
|
||||
|
||||
if streams.out_is_terminal() {
|
||||
let mut colors = vec![];
|
||||
highlight_shell(&def, &mut colors, &parser.context(), false, None);
|
||||
|
|
|
@ -3,6 +3,7 @@ use crate::common::str2wcstring;
|
|||
use crate::function;
|
||||
use crate::highlight::{colorize, highlight_shell};
|
||||
|
||||
use crate::parse_util::{apply_indents, parse_util_compute_indents};
|
||||
use crate::path::{path_get_path, path_get_paths};
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -128,6 +129,9 @@ pub fn r#type(parser: &Parser, streams: &mut IoStreams, argv: &mut [&wstr]) -> O
|
|||
comment,
|
||||
props.annotated_definition(arg)
|
||||
));
|
||||
if props.definition_file().is_none() {
|
||||
def = apply_indents(&def, &parse_util_compute_indents(&def));
|
||||
}
|
||||
|
||||
if streams.out_is_terminal() {
|
||||
let mut color = vec![];
|
||||
|
|
Loading…
Reference in New Issue
Block a user