Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Emacs mode #73

Open
VarLad opened this issue Apr 10, 2023 · 7 comments
Open

Emacs mode #73

VarLad opened this issue Apr 10, 2023 · 7 comments

Comments

@VarLad
Copy link

VarLad commented Apr 10, 2023

Hello, thanks for taking the time to make this!
I was wondering if you could also implement an emacs/nano style mode (for people who don't want modal editing)

@vamolessa
Copy link
Owner

Hi! Thanks for taking interest in the project!
However, a non-modal editing model is really outside of the scope. I also have very little expericence with emacs editing model (in the terminal).

However, should you want to edit the source, I can give you an overview on how to achieve it.
There's mainly only two modes for editing: normal and insert. The work would be to collapse them into a single mode that does both navigation and editing.

Will close for now. But should you have questions on specifics, feel free to reopen.

Thanks again

@VarLad
Copy link
Author

VarLad commented Apr 12, 2023

@vamolessa Just wondering, can this be done via a plugin, or will I have to fork it?
If not, does a feature request to make the keybindings more extensible via plugins make sense?

@VarLad
Copy link
Author

VarLad commented Apr 12, 2023

@vamolessa I've some interest in implementing this (although lack time). This is a good reference for what I want. https://www.nano-editor.org/dist/v7/nano.pdf#Editor%20Basics

@vamolessa
Copy link
Owner

Maybe it's possible to implement the bulk of the input logic in a plugin and then add a small patch to normal mode to always imediately switch to that plugin mode.
If that works and the change to the modes system is minimal I think we could merge the patch.

@VarLad
Copy link
Author

VarLad commented Apr 12, 2023

@vamolessa How can I start looking into this?

@vamolessa
Copy link
Owner

here is a small example of how to use the pepper lib crate to create your own binary
together with how to register plugins you wish to use:
https://github.com/vamolessa/pepper/blob/master/mine/src/main.rs
(this is the binary that i use daily btw)

here you can see what the plugin struct is (and also the PluginDefinition struct):
https://github.com/vamolessa/pepper/blob/master/pepper/src/plugin.rs#L22

there you can see that there is a function ptr for input keys you can provide: on_keys.

with this, you should be able to handle key inputs once you're in you plugin's mode.

however, for all of this to work, there are some changes that will be needed:

  • add a change_to_plugin fn to impl Mode in pepper/src/mode.rs that changes kind to ModeKind::Plugin and sets plugin_handle to your plugin handle
    • you receive your plugin handle in the instantiate fn that you provide in your PluginDefinition)
    • dont forget to call the on_exit on the old mode and on_enter on the new one (just see the src of Mode::change_to)
  • then you can either create a command that calls Mode::change_to_plugin(editor, plugin_handle) which lets you manually change to your emacs mode; or you can change peppe/src/mode/normal.rs to call Mode::change_to_plugin(editor, plugin_handle) automatically inside its on_enter (going this way you would either to put your plugin_handle in a global or also add it as a field to Editor struct
  • after this, you will have to move all implementation of at least both pepper/src/mode/normal.rs and pepper/src/mode/insert.rs to inside your on_keys plugin function
    • the bulk of navigation implementation is inside the on_client_keys_with_buffer_view fn; the way it's implemented is a really big match on keys from the editor KeysIterator

this is the highlevel view
hope it helps!

@vamolessa
Copy link
Owner

will reopen this while you're trying to get this going :)
it's easier to find this issue this way

@vamolessa vamolessa reopened this Apr 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants