aboutsummaryrefslogtreecommitdiffhomepage
path: root/share/functions/funced.fish
diff options
context:
space:
mode:
Diffstat (limited to 'share/functions/funced.fish')
-rw-r--r--share/functions/funced.fish30
1 files changed, 26 insertions, 4 deletions
diff --git a/share/functions/funced.fish b/share/functions/funced.fish
index ca2e2772..88688b13 100644
--- a/share/functions/funced.fish
+++ b/share/functions/funced.fish
@@ -51,7 +51,7 @@ function funced --description 'Edit function definition'
if test -n "$editor"
set -l editor_cmd
eval set editor_cmd $editor
- if not type -f "$editor_cmd[1]" >/dev/null
+ if not type -q -f "$editor_cmd[1]"
_ "funced: The value for \$EDITOR '$editor' could not be used because the command '$editor_cmd[1]' could not be found
"
set editor fish
@@ -88,9 +88,31 @@ function funced --description 'Edit function definition'
else
echo $init > $tmpname
end
- if eval $editor $tmpname
- . $tmpname
- end
+ # Repeatedly edit until it either parses successfully, or the user cancels
+ # If the editor command itself fails, we assume the user cancelled or the file
+ # could not be edited, and we do not try again
+ while true
+ if not eval $editor $tmpname
+ _ "Editing failed or was cancelled"
+ echo
+ else
+ if not source $tmpname
+ # Failed to source the function file. Prompt to try again.
+ echo # add a line between the parse error and the prompt
+ set -l repeat
+ set -l prompt (_ 'Edit the file again\? [Y/n]')
+ while test -z "$repeat"
+ read -p "echo $prompt\ " repeat
+ end
+ if not contains $repeat n N no NO No nO
+ continue
+ end
+ _ "Cancelled function editing"
+ echo
+ end
+ end
+ break
+ end
set -l stat $status
rm -f $tmpname >/dev/null
return $stat