Skip to content

Implement changing editing mode - #681

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
ima1zumi:implement-change-editing-mode
Apr 16, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
ima1zumi:implement-change-editing-mode

Conversation

@ima1zumi

@ima1zumi ima1zumi commented Apr 15, 2024 •

Copy link
Copy Markdown
Member

I implemented Readline’s emacs-editing-mode (C-e) and vi-editing-mode (M-C-j, M-C-m) to switch editing modes. The keymap was aligned with Readline's behavior. But M-C-m was used in the yamatanooroti tests, so I decided not to map it.

@ima1zumi ima1zumi added the enhancement New feature or request label Apr 15, 2024
@ima1zumi
ima1zumi force-pushed the implement-change-editing-mode branch from 5d55556 to 2a75980 Compare April 15, 2024 14:43
@st0012

st0012 commented Apr 15, 2024

Copy link
Copy Markdown
Member

Since both mappings are currently used for other operations, this feels like a breaking change.
Do we know if people use the current mappings and did we receive request for the new behaviour?

@ima1zumi

Copy link
Copy Markdown
Member Author

The original key mapping is different from Readline, so I believe few people use it.
On second thoughts, not many people, other than maintainers, want to change between Vi mode and Emacs mode using the default key bindings. I think I should stop binding them by default. Thank you for your comment!

@ima1zumi
ima1zumi marked this pull request as draft April 15, 2024 15:55
@tompng

tompng commented Apr 15, 2024

Copy link
Copy Markdown
Member

Just for information, GNU Bash source code comment also says it's confusing.

  /* In Bash, the user can switch editing modes with "set -o [vi emacs]",
     so it is not necessary to allow C-M-j for context switching.  Turn
     off this occasionally confusing behaviour. */
  ...
  if (func == rl_vi_editing_mode)
    rl_unbind_key_in_map (CTRL('J'), emacs_meta_keymap);
  ...
  if (func == rl_vi_editing_mode)
    rl_unbind_key_in_map (CTRL('M'), emacs_meta_keymap);
  ...
  if (func == rl_emacs_editing_mode)
    rl_unbind_key_in_map (CTRL('E'), vi_movement_keymap);

@ima1zumi
ima1zumi force-pushed the implement-change-editing-mode branch from 2a75980 to 92ef148 Compare April 15, 2024 16:52
end

def test_vi_editing_mode
@line_editor.__send__(:vi_editing_mode, nil)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When key binding is set, key.char is passed as symbol to LineEditor#update.
I can't seem to test it properly with input_keys. If you have a better way to do this, please let me know.

@ima1zumi
ima1zumi marked this pull request as ready for review April 15, 2024 16:56
@ima1zumi
ima1zumi merged commit 501b9a6 into ruby:master Apr 16, 2024
@ima1zumi
ima1zumi deleted the implement-change-editing-mode branch April 16, 2024 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants