diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 166dfc1af..0812462e8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -51,6 +51,7 @@ Interactive improvements - Instead of flashing all the text to the left of the cursor, fish now flashes the matched token during history token search, the completed token during completion (:issue:`11050`), the autosuggestion when deleting it, and the full command line in all other cases. - Pasted commands are now stripped of any ``$`` prefix. - The :kbd:`alt-s` binding will now also use ``run0`` if available. +- ``funced`` will now edit copied functions directly, instead of the file where ``function --copy`` was invoked. (:issue:`11614`) New or improved bindings ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/share/functions/funced.fish b/share/functions/funced.fish index bcff40cc2..32e767ce1 100644 --- a/share/functions/funced.fish +++ b/share/functions/funced.fish @@ -71,6 +71,11 @@ function funced --description 'Edit function definition' if not functions -q -- $funcname echo $init >$tmpname + else if not string match --quiet --regex '^(?:n/a|not-autoloaded|autoloaded)$' -- (functions --details --verbose -- $funcname)[2] + # Pretend this copied function does not have a definition file. Editing the file which + # originally defined it would not update this copy, and the file which copied it + # would not have a function body to edit. (issue #11614) + functions -- $funcname >$tmpname else if functions --details -- $funcname | string match --invert --quiet --regex '^(?:-|stdin|embedded:.*)$' set writepath (functions --details -- $funcname) # Use cat here rather than cp to avoid copying permissions diff --git a/tests/checks/funced.fish b/tests/checks/funced.fish new file mode 100644 index 000000000..183b2b6b5 --- /dev/null +++ b/tests/checks/funced.fish @@ -0,0 +1,23 @@ +#RUN: %fish %s + +function my-src + echo hello +end + +echo "functions --copy my-src my-dst" >my-copy-function.fish +source my-copy-function.fish +rm my-copy-function.fish # Cleanup + +functions --details --verbose my-dst +# CHECK: my-copy-function.fish +# CHECK: {{.*}}tests/checks/funced.fish +# CHECK: 3 +# CHECK: scope-shadowing + +VISUAL=cat EDITOR=cat funced my-dst +# CHECK: # Defined in {{.*}}/tests/checks/funced.fish @ line 3, copied in my-copy-function.fish @ line 1 +# CHECK: function my-dst +# CHECK: echo hello +# CHECK: end +# CHECK: Editor exited but the function was not modified +# CHECK: If the editor is still running, check if it waits for completion, maybe a '--wait' option?