patchThe GNU Bourne-Again SHell - Patches: patch #10195, No bind listed for...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

patch #10195: No bind listed for 'edit-and-execute-command' in vi mode

Submitter:  Matthew Hughes <mjh>
Submitted:  Tue 05 Apr 2022 08:02:06 PM UTC
   
 
Category:  None Priority:  5 - Normal
Status:  Done Privacy:  Public
Assigned to:  None Open/Closed:  Open

Wed 06 Apr 2022 01:16:23 PM UTC, comment #1: 

Thanks for the report. This was fixed back in February by adding the bindable command name `vi-edit-and-execute-command'.

Chet Ramey <chet>
Group administrator
Tue 05 Apr 2022 08:02:06 PM UTC, original submission:  

Hello,

I noticed 'bind -p' listed this as not bound in vi mode and thought I'd see if I could change this (see commit for more details).

This is my first time poking around the bash code, so my fix may be a bit naive.

Thanks for your time :)


commit 1c6d9173310bb996802f5d9f4aa495e0bb4153a2
Author: Matthew Hughes
Date:   Tue Apr 5 13:30:03 2022 +0100

    Fix missing bind for `edit-and-execute-command`

    In vi mode there is no binding listed for this command (in either insert
    or movement mode)

        $ set -o vi && bind -p | grep 'edit-and'
        # edit-and-execute-command (not bound)

    Compare with emacs mode:

        $ set -o emacs && bind -p | grep 'edit-and'
        "\C-x\C-e": edit-and-execute-command

    Though a key is bound to this ('v' by default), in `initialize_readline`:

        $ git show 9439ce094c9aa7557a9d53ac7b412a23aa66e36b:bashline.c | sed --quiet '594,596p'
        #if defined (VI_MODE)
          rl_bind_key_if_unbound_in_map ('v', vi_edit_and_execute_command, vi_movement_keymap);
        #  if defined (ALIAS)

    The reason for this is that "edit-and-execute-command" is mapped to
    `emacs_edit_and_execute_command` (also in `initialize_readline`):

        $ git show 9439ce094c9aa7557a9d53ac7b412a23aa66e36b:bashline.c | sed --quiet '482,482p'
          rl_add_defun ("edit-and-execute-command", emacs_edit_and_execute_command, -1);

    To fix this, remove `{emacs,vi}_edit_and_execute_command` and update
    `edit_and_execute_command` to handle both of these cases.

diff --git a/bashline.c b/bashline.c
index c69c0c5e..73cd526e 100644
--- a/bashline.c
+++ b/bashline.c
@@ -261,12 +261,10 @@ static int bash_glob_list_expansions PARAMS((int, int));

 #endif /* SPECIFIC_COMPLETION_FUNCTIONS */

-static int edit_and_execute_command PARAMS((int, int, int, char *));
+static int edit_and_execute_command PARAMS((int, int));
 #if defined (VI_MODE)
-static int vi_edit_and_execute_command PARAMS((int, int));
 static int bash_vi_complete PARAMS((int, int));
 #endif
-static int emacs_edit_and_execute_command PARAMS((int, int));

 /* Non-zero once initialize_readline () has been called. */
 int bash_readline_initialized = 0;
@@ -479,7 +477,7 @@ initialize_readline ()
   rl_add_defun ("insert-last-argument", rl_yank_last_arg, -1);

   rl_add_defun ("display-shell-version", display_shell_version, -1);
-  rl_add_defun ("edit-and-execute-command", emacs_edit_and_execute_command, -1);
+  rl_add_defun ("edit-and-execute-command", edit_and_execute_command, -1);

 #if defined (BRACE_COMPLETION)
   rl_add_defun ("complete-into-braces", bash_brace_completion, -1);
@@ -590,9 +588,9 @@ initialize_readline ()
   rl_ignore_some_completions_function = filename_completion_ignore;

   /* Bind C-xC-e to invoke emacs and run result as commands. */
-  rl_bind_key_if_unbound_in_map (CTRL ('E'), emacs_edit_and_execute_command, emacs_ctlx_keymap);
+  rl_bind_key_if_unbound_in_map (CTRL ('E'), edit_and_execute_command, emacs_ctlx_keymap);
 #if defined (VI_MODE)
-  rl_bind_key_if_unbound_in_map ('v', vi_edit_and_execute_command, vi_movement_keymap);
+  rl_bind_key_if_unbound_in_map ('v', edit_and_execute_command, vi_movement_keymap);
 #  if defined (ALIAS)
   rl_bind_key_if_unbound_in_map ('@', posix_edit_macros, vi_movement_keymap);
 #  endif
@@ -926,14 +924,23 @@ hostnames_matching (text)
 #define POSIX_VI_EDIT_COMMAND        "fc -e vi"

 static int
-edit_and_execute_command (count, c, editing_mode, edit_command)
-     int count, c, editing_mode;
-     char *edit_command;
+edit_and_execute_command (count, c)
+     int count, c;
 {
-  char *command, *metaval;
-  int r, rrs, metaflag;
+  char *command, *metaval, *edit_command;
+  int r, rrs, metaflag, editing_mode;
   sh_parser_state_t ps;

+  editing_mode = rl_editing_mode;
+  if (rl_editing_mode == EMACS_EDITING_MODE)
+    edit_command = EMACS_EDIT_COMMAND;
+#if defined (VI_MODE)
+  else if (editing_mode == VI_EDITING_MODE)
+    edit_command = posixly_correct ? POSIX_VI_EDIT_COMMAND : VI_EDIT_COMMAND;
+#endif /* VI_MODE */
+  else
+    return 0;
+
   rrs = rl_readline_state;
   saved_command_line_count = current_command_line_count;

@@ -1000,25 +1007,6 @@ edit_and_execute_command (count, c, editing_mode, edit_command)
   return r;
 }

-#if defined (VI_MODE)
-static int
-vi_edit_and_execute_command (count, c)
-     int count, c;
-{
-  if (posixly_correct)
-    return (edit_and_execute_command (count, c, VI_EDITING_MODE, POSIX_VI_EDIT_COMMAND));
-  else
-    return (edit_and_execute_command (count, c, VI_EDITING_MODE, VI_EDIT_COMMAND));
-}
-#endif /* VI_MODE */
-
-static int
-emacs_edit_and_execute_command (count, c)
-     int count, c;
-{
-  return (edit_and_execute_command (count, c, EMACS_EDITING_MODE, EMACS_EDIT_COMMAND));
-}
-
 #if defined (ALIAS)
 static int
 posix_edit_macros (count, key)


Matthew Hughes <mjh>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by chet (Posted a comment)
  • -email is unavailable- added by mjh (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follows 1 latest change.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-04-06 chet StatusNone Done

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code