Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REPL: implement a kill ring #23377

Merged
merged 6 commits into from
Sep 3, 2017
Merged

REPL: implement a kill ring #23377

merged 6 commits into from
Sep 3, 2017

Conversation

rfourquet
Copy link
Member

This fixes part of #8447. In order to implement a kill ring, which is a stack of previously killed region of text, the concept of "region" is indeed needed: after a "yank" ("C-y"), one can replace the yanked text with an older entry in the kill-ring via "M-y" (so the REPL must remember the region consisting of the first yanked text). While I was at it, it's now possible to "set the mark" with "C-Space", to copy/kill the current region with "M-w/M-W", and to exchange the mark with the current position with "C-xC-x". As "M-y" is normally possible only after a yank, commands can now return a symbol which will be remembered till the next command (kind of similar to "key repeats", but with more information).

There are still probably few bugs, but if someone is willing to review, I would require attention particularly on the following: previously, the char '\0' was used as a sentinel to indicate "wildcard" ("*"), but this conflicts with the code sent by "C-Space". So I chose another sentinel value, but I know very littly about UTF8; For some characters I got errors, for others I didn't get a functional REPL (sentinel not recognized, so no printed letters when matching "*"). The chosen working sentinel value is in a "Private Use range" (I got it from the code from rand(::Char)).

@rfourquet rfourquet added stdlib:REPL Julia's REPL (Read Eval Print Loop) needs tests Unit tests are required for this change labels Aug 21, 2017
@rfourquet
Copy link
Member Author

@Keno do you have an idea why some sentinel values other than '\0' don't work, and whether the new value here, which seems to work, is ok?

@Keno
Copy link
Member

Keno commented Aug 23, 2017

Should be ok. Terminals shouldn't really give you private plane Chars. In fact some of them (e.g. iTerm2) use private plane chars to store metadata, so they don't support them either.

@rfourquet rfourquet force-pushed the rf/REPL-killring branch 2 times, most recently from a0a04f2 to 5dd8843 Compare August 24, 2017 15:57
@rfourquet
Copy link
Member Author

Thanks for your answer Keno!
So I added tests, would be good to go I think. I will merge in a few days if that's fine.

'\0' was used as a sentinel for self-insert (spelled "*" in keymaps),
which made it un-available for Ctrl-Space combo.
We replace here '\0' with an un-assigned sentinel Char value.
* add possibility to set the "mark" in the edit area, with C-Space
* the mark and current position (the "point") delimit a region
* C-x C-x exchanges the mark with the point
* M-w is set to copy the region into the kill buffer
* M-W is set to kill the region into the kill buffer
  (in Emacs, the binding for this is C-w, but it's already taken
  by edit_werase)
After a yank ("^Y"), it's possible to "yank-pop" with
the "M-y" binding, which replaces the just-yanked text
with an older entry from the "kill-ring".
All call sites of `splice_buffer!` were manually substracting 1 to
the last position of the range, indicating that it's more natural
to specify a region with an open-close range.
Therefore, `splice_buffer!` and `edit_replace` (thin wrapper of
`splice_buffer!`) are merged into `edit_splice!`, which takes
a `Region` (a pair of integers) object instead of a range.
@rfourquet rfourquet merged commit f5b96f7 into master Sep 3, 2017
@rfourquet rfourquet deleted the rf/REPL-killring branch September 3, 2017 11:50
@rfourquet rfourquet removed the needs tests Unit tests are required for this change label Sep 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib:REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants