From 24836f96525bd359aea08198462193017c8aaf7c Mon Sep 17 00:00:00 2001 From: Fabian Boehm Date: Tue, 10 Jan 2023 18:27:15 +0100 Subject: [PATCH] Use set --no-event in the key binding functions This is how we can use it in a backwards-compatible way. Eventually we would remove the compatibility guff. --- .../functions/fish_default_key_bindings.fish | 25 +++++++++++++------ share/functions/fish_vi_key_bindings.fish | 24 +++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/share/functions/fish_default_key_bindings.fish b/share/functions/fish_default_key_bindings.fish index ea186f26d..c6378ba6b 100644 --- a/share/functions/fish_default_key_bindings.fish +++ b/share/functions/fish_default_key_bindings.fish @@ -10,15 +10,24 @@ function fish_default_key_bindings -d "emacs-like key binds" bind --erase --all --preset # clear earlier bindings, if any if test "$fish_key_bindings" != fish_default_key_bindings # Allow the user to set the variable universally + set -l scope set -q fish_key_bindings - or set -g fish_key_bindings - # This triggers the handler, which calls us again and ensures the user_key_bindings - # are executed. - set fish_key_bindings fish_default_key_bindings - # unless the handler somehow doesn't exist, which would leave us without bindings. - # this happens in no-config mode. - functions -q __fish_reload_key_bindings - and return + or set scope -g + true + # We try to use `set --no-event`, but to avoid leaving the user without bindings + # if they run this with an older version we fall back on setting the variable + # with an event. + if ! set --no-event $scope fish_key_bindings fish_default_key_bindings 2>/dev/null + # This triggers the handler, which calls us again + set $scope fish_key_bindings fish_default_key_bindings + # unless the handler somehow doesn't exist, which would leave us without bindings. + # this happens in no-config mode. + functions -q __fish_reload_key_bindings + and return + else + # (we need to set the bind mode to default) + set --no-event fish_bind_mode default + end end end diff --git a/share/functions/fish_vi_key_bindings.fish b/share/functions/fish_vi_key_bindings.fish index 844376637..8188bba13 100644 --- a/share/functions/fish_vi_key_bindings.fish +++ b/share/functions/fish_vi_key_bindings.fish @@ -23,16 +23,22 @@ function fish_vi_key_bindings --description 'vi-like key bindings for fish' # and without this would then have subtly broken bindings. if test "$fish_key_bindings" != fish_vi_key_bindings and test "$rebind" = true - # Allow the user to set the variable universally. + # Allow the user to set the variable universally + set -l scope set -q fish_key_bindings - or set -g fish_key_bindings - # This triggers the handler, which calls us again and ensures the user_key_bindings - # are executed. - set fish_key_bindings fish_vi_key_bindings - # unless the handler somehow doesn't exist, which would leave us without bindings. - # this happens in no-config mode. - functions -q __fish_reload_key_bindings - and return + or set scope -g + true + # We try to use `set --no-event`, but to avoid leaving the user without bindings + # if they run this with an older version we fall back on setting the variable + # with an event. + if ! set --no-event $scope fish_key_bindings fish_vi_key_bindings 2>/dev/null + # This triggers the handler, which calls us again + set $scope fish_key_bindings fish_vi_key_bindings + # unless the handler somehow doesn't exist, which would leave us without bindings. + # this happens in no-config mode. + functions -q __fish_reload_key_bindings + and return + end end set -l init_mode insert