On Thu, 7 Dec 2017, Chet Ramey wrote:

On 12/6/17 11:46 PM, Rob Foehl wrote:
Any chance these could be made to work as documented, removing the
dependency on show-mode-in-prompt?

The `dependency' on show-mode-in-prompt is intentional: the strings aren't
prefixed to the displayed prompt string unless that variable is enabled.
That has been the case even when the strings weren't user-settable (e.g.,
bash-4.3). If the documentation doesn't make that clear, then I need to
clarify it.

Right, but that's the issue here: in bash-4.3, for example, trying to use an inputrc which sets the various mode strings and show-mode-in-prompt just results in the prompt being mangled by the fixed strings included in that release, and the custom strings ignored. Since there's no way to test the application version in readline conditionals, this means the inputrc isn't portable to older releases -- a problem with shared home directories and the like.

If, on the other hand, the mode string variables were used unconditionally after being set, and without show-mode-in-prompt set, then there is no issue with older releases -- and this is how they're currently documented to work in readline-7.0 / bash-4.4, even if that wasn't intentional.

This turned out to be a fairly minor change; see attached patch against current devel branch from git. I believe this covers all cases correctly, including emacs-mode-string, and without causing any backward compatibility issues since the show-mode-in-prompt behavior is unchanged if set. Would you consider applying this?

-Rob
diff --git a/lib/readline/display.c b/lib/readline/display.c
index 54566efd..0371ff31 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)) && 
(_rl_show_mode_in_prompt || _rl_emacs_mode_str || _rl_vi_ins_mode_str || 
_rl_vi_cmd_mode_str)) ? prompt_modestr (&mlen) : 0;
   if (ms)
     {
       l = strlen (pmt);
diff --git a/lib/readline/misc.c b/lib/readline/misc.c
index 64b1457d..7e674112 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 (_rl_show_mode_in_prompt || _rl_emacs_mode_str)
     _rl_reset_prompt ();
 
   return 0;
diff --git a/lib/readline/readline.c b/lib/readline/readline.c
index 64154c54..573a60dc 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 (_rl_show_mode_in_prompt || _rl_emacs_mode_str)
       _rl_reset_prompt ();
 
   /* If we're not echoing, we still want to at least print a prompt, because
diff --git a/lib/readline/vi_mode.c b/lib/readline/vi_mode.c
index 3cb7e8c9..c2ffcc9c 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 (_rl_show_mode_in_prompt || _rl_vi_ins_mode_str)
     _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 (_rl_show_mode_in_prompt || _rl_vi_cmd_mode_str)
     _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