peterh / liner

Pure Go line editor with history, inspired by linenoise
MIT License
1.04k stars 132 forks source link

Emacs-like killRing #22

Closed ElPincheTopo closed 9 years ago

ElPincheTopo commented 9 years ago

Small but very useful changes. Now, when you do ctrlK the part of the line that was "killed" or removed is added to a circular linked list, called the killRing. When ctrlY is pressed, the prompt enters killRing mode.

When entering killRing mode, the element pointed as current by the killRing is inserted to the line in the current position, then the system waits for one of twothings:

After the function returns, if the value for next is ctrlY then the functions starts again.

peterh commented 9 years ago

Seems reasonable in principle. In practice, I'm not sure I want to add anything that accepts Alt. Alt is a brand new keystroke, and would need widespread testing.

There are a number of bugs in this implementation:

http://cnswww.cns.cwru.edu/php/chet/readline/readline.html#SEC6

ElPincheTopo commented 9 years ago

For now, I think I will add altY as an action, just to get it working and then we can discuss how to properly add the alt to the runes.

I will make any kill operation save the killed text to the kill ring and make the killring a member of commonState.

ElPincheTopo commented 9 years ago

About the whole alt thing. If you prefer, maybe we should consider changing the altY for another key so we keep avoiding using alt.

peterh commented 9 years ago

I will make any kill operation save the killed text to the kill ring and make the killring a member of commonState.

Thanks. Don't forget that consecutive kill operations append (or prepend, depending) to the same slot.

About the whole alt thing. If you prefer, maybe we should consider changing the altY for another key so we keep avoiding using alt.

If it's going to be implemented, it should use the same keys as readline. I was just pointing out that Alt is new, so we should be extra careful to test with as many terminal emulators as possible.

ElPincheTopo commented 9 years ago

@peterh Done, tested in linux and windows. :smile:

peterh commented 9 years ago

Looks good. Thanks!