diff --git a/sphinx_doc_src/cmds/fish_mode_prompt.rst b/sphinx_doc_src/cmds/fish_mode_prompt.rst index 83588ec04..965ff2e77 100644 --- a/sphinx_doc_src/cmds/fish_mode_prompt.rst +++ b/sphinx_doc_src/cmds/fish_mode_prompt.rst @@ -13,6 +13,8 @@ Description The default ``fish_mode_prompt`` function will output indicators about the current Vi editor mode displayed to the left of the regular prompt. Define your own function to customize the appearance of the mode indicator. You can also define an empty ``fish_mode_prompt`` function to remove the Vi mode indicators. The ``$fish_bind_mode variable`` can be used to determine the current mode. It will be one of ``default``, ``insert``, ``replace_one``, or ``visual``. +fish_mode_prompt will be executed when the vi mode changes. If it produces any output, it is displayed and used. If it does not, the other prompt functions (:ref:`fish_prompt ` and :ref:`fish_right_prompt `) will be executed as well in case they contain a mode display. + Example ------- diff --git a/src/reader.cpp b/src/reader.cpp index e0112c113..222b17c32 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2483,18 +2483,21 @@ void reader_data_t::handle_readline_command(readline_cmd_t c, readline_loop_stat break; } case rl::repaint_mode: { - // Repaint the mode-prompt only if it exists. + // Repaint the mode-prompt only if possible. // This is an optimization basically exclusively for vi-mode, since the prompt // may sometimes take a while but when switching the mode all we care about is the // mode-prompt. - if (function_exists(MODE_PROMPT_FUNCTION_NAME, parser())) { - exec_mode_prompt(); + // + // Because some users set `fish_mode_prompt` to an empty function and display the mode elsewhere, + // we detect if the mode output is empty. + exec_mode_prompt(); + if(!mode_prompt_buff.empty()) { s_reset(&screen, screen_reset_current_line_and_prompt); screen_reset_needed = false; repaint(); break; } - // If it doesn't exist, we repaint as normal. + // Else we repaint as normal. /* fallthrough */ } case rl::force_repaint: