From a32fa8fac9fd7b54f52349fdca660fc5af9d4979 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 14 Nov 2021 11:08:30 +0100 Subject: [PATCH] Read $fish_autosuggestion_enabled on interactive startup This allows to disable autosuggestions in config or with fish -C 'set -g fish_autosuggestion_enabled 0' instead of only in existing interactive sessions. I'm not sure if passing the env var table is actually necessary here, since we already have a reader. --- src/env_dispatch.cpp | 8 ++------ src/reader.cpp | 12 ++++++++++-- src/reader.h | 4 ++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index eed9d0fa7..d7b1d98fb 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -247,12 +247,8 @@ static void handle_fish_history_change(const env_stack_t &vars) { reader_change_history(history_session_id(vars)); } -static void handle_autosuggestion_change(const env_stack_t &vars) { - bool enabled = true; - if (auto val = vars.get(L"fish_autosuggestion_enabled")) { - if (val->as_string() == L"0") enabled = false; - } - reader_set_autosuggestion_enabled(enabled); +void handle_autosuggestion_change(const env_stack_t &vars) { + reader_set_autosuggestion_enabled(vars); } static void handle_function_path_change(const env_stack_t &vars) { diff --git a/src/reader.cpp b/src/reader.cpp index 30acffa9c..7145fc6c5 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2612,10 +2612,18 @@ void reader_change_history(const wcstring &name) { } } -void reader_set_autosuggestion_enabled(bool enable) { +static bool check_autosuggestion_enabled(const env_stack_t &vars) { + if (auto val = vars.get(L"fish_autosuggestion_enabled")) { + return val->as_string() != L"0"; + } + return true; +} + +void reader_set_autosuggestion_enabled(const env_stack_t &vars) { // We don't need to _change_ if we're not initialized yet. reader_data_t *data = current_data_or_null(); if (data) { + bool enable = check_autosuggestion_enabled(vars); if (data->conf.autosuggest_ok != enable) { data->conf.autosuggest_ok = enable; data->force_exec_prompt_and_repaint = true; @@ -2768,7 +2776,7 @@ static int read_i(parser_t &parser) { conf.complete_ok = true; conf.highlight_ok = true; conf.syntax_check_ok = true; - conf.autosuggest_ok = true; + conf.autosuggest_ok = check_autosuggestion_enabled(parser.vars()); conf.expand_abbrev_ok = true; if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) { diff --git a/src/reader.h b/src/reader.h index 31dad3b97..75370e084 100644 --- a/src/reader.h +++ b/src/reader.h @@ -149,8 +149,8 @@ void restore_term_mode(); /// Change the history file for the current command reading context. void reader_change_history(const wcstring &name); -/// Enable or disable autosuggestions. -void reader_set_autosuggestion_enabled(bool enable); +/// Enable or disable autosuggestions based on the associated variable. +void reader_set_autosuggestion_enabled(const env_stack_t &vars); /// Write the title to the titlebar. This function is called just before a new application starts /// executing and just after it finishes.