On Sat, 9 Dec 2017, Chet Ramey wrote:

So the problem is simply that you don't like the default strings in
bash-4.3?

Well, subjectively, yes. There's a difference between "don't like" and "won't work in the larger context of complex prompts", though.

If this is a serious problem, move the setting of the variable into the
bash startup files, where you can run the appropriate `bind' command
based on the values of $BASH_VERSION and $BASH_VERSINFO.

That'd work for bash, but not other readline consumers.

Not exactly.  The documentation is garbled, but it's simply wrong to
assume that the behavior of show-mode-in-prompt being a toggle to turn
the behavior on and off would have changed between bash-4.3 and bash-4.4
without me noting the change in the change log. The documentation is
obviously in error, but the desired behavior is that show-mode-in-prompt
toggle the display of the mode characters (4.3) or mode strings (4.4).

The documentation doesn't mention show-mode-in-prompt outside of its own description, and the man page doesn't mention the mode strings there, either. Why would anyone unfamiliar with its history assume it's relevant? I certainly didn't. Regardless, the patch doesn't change the behavior of show-mode-in-prompt itself in any way.

On desirability: the default behavior of show-mode-in-prompt doesn't play well with complex prompts, and setting any of the mode string variables would seem to indicate intent that they be used, in which case show-mode-in-prompt is superfluous. Does a use case exist for setting mode strings but not using them?

I've attached another version of the patch that's arguably more robust across mode changes with odd combinations of settings.

-Rob
diff --git a/lib/readline/display.c b/lib/readline/display.c
index 54566efd..bcc155a8 100644
--- a/lib/readline/display.c
+++ b/lib/readline/display.c
@@ -341,7 +341,7 @@ expand_prompt (char *pmt, int flags, int *lp, int *lip, int 
*niflp, int *vlp)
 
   /* We only expand the mode string for the last line of a multiline prompt
      (a prompt with embedded newlines). */
-  ms = (((pmt == rl_prompt) ^ (flags & PMT_MULTILINE)) && 
_rl_show_mode_in_prompt) ? prompt_modestr (&mlen) : 0;
+  ms = (((pmt == rl_prompt) ^ (flags & PMT_MULTILINE)) && 
SHOW_MODE_IN_PROMPT()) ? prompt_modestr (&mlen) : 0;
   if (ms)
     {
       l = strlen (pmt);
diff --git a/lib/readline/misc.c b/lib/readline/misc.c
index 64b1457d..d47154b3 100644
--- a/lib/readline/misc.c
+++ b/lib/readline/misc.c
@@ -648,7 +648,7 @@ rl_emacs_editing_mode (int count, int key)
   _rl_set_insert_mode (RL_IM_INSERT, 1); /* emacs mode default is insert mode 
*/
   _rl_keymap = emacs_standard_keymap;
 
-  if (_rl_show_mode_in_prompt)
+  if (SHOW_MODE_IN_PROMPT())
     _rl_reset_prompt ();
 
   return 0;
diff --git a/lib/readline/readline.c b/lib/readline/readline.c
index 64154c54..fa420e16 100644
--- a/lib/readline/readline.c
+++ b/lib/readline/readline.c
@@ -419,7 +419,7 @@ readline_internal_setup (void)
     rl_vi_insertion_mode (1, 'i');     /* don't want to reset last */
   else
 #endif /* VI_MODE */
-    if (_rl_show_mode_in_prompt)
+    if (SHOW_MODE_IN_PROMPT())
       _rl_reset_prompt ();
 
   /* If we're not echoing, we still want to at least print a prompt, because
diff --git a/lib/readline/rlprivate.h b/lib/readline/rlprivate.h
index 2fd2f5ea..e587df74 100644
--- a/lib/readline/rlprivate.h
+++ b/lib/readline/rlprivate.h
@@ -38,6 +38,8 @@
 #define VI_COMMAND_MODE()      (rl_editing_mode == vi_mode && _rl_keymap == 
vi_movement_keymap)
 #define VI_INSERT_MODE()       (rl_editing_mode == vi_mode && _rl_keymap == 
vi_insertion_keymap)
 
+#define SHOW_MODE_IN_PROMPT()  (_rl_show_mode_in_prompt || _rl_emacs_mode_str 
|| _rl_vi_ins_mode_str || _rl_vi_cmd_mode_str)
+
 #define RL_CHECK_SIGNALS() \
        do { \
          if (_rl_caught_signal) _rl_signal_handler (_rl_caught_signal); \
diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c
index 3cb7e8c9..bf92e5ad 100644
--- a/lib/readline/vi_mode.c
+++ b/lib/readline/vi_mode.c
@@ -685,7 +685,7 @@ rl_vi_insertion_mode (int count, int key)
 {
   _rl_keymap = vi_insertion_keymap;
   _rl_vi_last_key_before_insert = key;
-  if (_rl_show_mode_in_prompt)
+  if (SHOW_MODE_IN_PROMPT())
     _rl_reset_prompt ();
   return (0);
 }
@@ -801,7 +801,7 @@ rl_vi_movement_mode (int count, int key)
   if (RL_ISSTATE (RL_STATE_VICMDONCE) == 0)
     rl_free_undo_list ();
 
-  if (_rl_show_mode_in_prompt)
+  if (SHOW_MODE_IN_PROMPT())
     _rl_reset_prompt ();
 
   RL_SETSTATE (RL_STATE_VICMDONCE);
_______________________________________________
Bug-readline mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-readline

Reply via email to