-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Introduce splice_buffer!
abstraction for IOBuffer in the REPL
#6429
Conversation
cut
abstraction for IOBuffercut
abstraction for IOBuffer in the REPL
For consistency, it might be nice to have this be called |
Ah, yes, that's exactly what this functionality is. The name didn't feel quite right to me, either. In that case, would it make sense to define it as a true method of |
Thanks! |
After thinking about it, I'm more ambivalent about naming it |
Agreed. I'm currently mocking up a |
Sounds like a good plan. |
cut
abstraction for IOBuffer in the REPLsplice_buffer!
abstraction for IOBuffer in the REPL
@carlobaldassi - Finally got a chance to get back to this today. Best part about this PR is that it now completely removes all |
It would be really nice to separate the IOBuffer guts from how one programs the REPL. This is not an efficiency critical API so I think that copying strings around would be perfectly acceptable. No amount of human mashing on the keyboard is going to tax a modern computer. |
Looks good to me, and significantly cleaner. I'll leave it around for others to review as well (cc @loladiro, @nolta, ...). |
I basically had in mind that all line editing states would simply be represented by |
This sounds like a place where RopeStrings might actually be useful? On Tuesday, April 8, 2014, Stefan Karpinski notifications@github.com
|
Eh, doesn't really matter. You can type at the REPL until you're blue in the face and the CPU wouldn't even break a sweat.
|
I see. I actually wrote a stub for this using an Anyway, I don't think this discussion should block this PR, which simplifies and rationalizes a number of things, no? @mbauman, I can't merge right now because of conflicts, but if you rebase I think we can merge it. |
I certainly don't think it will simplify any of the complex logic involving Unicode characters and cursor position but that's not the point – the point is that's the only thing the code will have to worry about. It doesn't have to know anything at all about IOBuffers or anything else involved with I/O. It completely separates line editing logic from I/O logic – and that's a good thing. |
Behaves just like `splice!` for arrays, except that it accepts 0-indexed positions and keeps the cursor position stable with the text. Minor behavior change to kill_line -- when killing just a newline, that goes into the buffer.
Rebased and ready to go again. I like the idea of eventually moving to UTF8Strings, too. While it doesn't simplify the logic around unicode, it does allow us to abstract it and put it where it belongs — in utf8.jl. It'd be great to use Positions would be consistent (1-indexed), and we could still use a function like splice (albeit returning a new string instead of modifying it). |
@StefanKarpinski: I agree, that's why I originally thought about an abstraction layer between the REPL code and the IOBuffer code. I still think that could be a good idea as an intermediate step: 1) isolate the code which deals with the IOBuffer internals 2) create a new simpler type which implements the exact same interface 3) possibly simplify code, which at this point can be done in small steps, testing everything carefully. |
Travis failure is unrelated (arpack). |
Introduce `splice_buffer!` abstraction for IOBuffer in the REPL
Well, but positions are actually consistent already, just with the notion that the cursor is between characters rather than on top of one char. Basically, it's just the difference between |
While I'm fine with changing it to UTF8Strings with a separate index, I agree with @carlobaldassi that it would most likely not change the code very much at all and is therefore probably not all that big a priority. The nice thing about IOBuffers is that you can use mutation which is slightly more natural than creating new immutable strings. In any case, the real trick to make UTF8 work correctly is the line refresh algorithm anyway (which I think is pretty much correct at this point, but probably needs to be changed for windowed prompts (within the terminal e.g. ncurses style), since it assumes that newline wrap. |
Here's another idea – make all the REPL logic work with UTF32Strings instead of UTF8Strings. That gets rid of all the problems of dealing with variable width encoding. You just have to transcode on input and output. Bam, solved. |
Close, but no cigar. Currently we don't handle this, but consider
That's two unicode characters. |
What if you NFC normalize it? |
No dice. There are lots of these non-spacing, combining marks, and only a handful of combinations with them have 1-character equivalents. As a more concrete example, check out the grave accent. It can be normalized and combine with vowels but not consonants:
|
I knew it couldn't possibly be that easy. Seems like UTF-32 isn't really much better than UTF-8. I wonder if it makes sense to have another layer of abstraction over normal strings where the unit of data is the code point, but it's not even clear what the correct unit of is at the higher level. This is essentially the same issue as the reverse problem (#6165). |
What you want is graphemes, I think. utf8proc/libmojibake will break up a string into graphemes for you. (Probably we should expose this as an iterator: |
@StefanKarpinski, see #9261 for a grapheme iterator that adds precisely this layer of abstraction. |
Awesome. This is great to have. |
Now that we have a |
Removes all text between from and to, keeping the position stable with the text.Behaves just likesplice!
for arrays, except that it accepts 0-indexed positions and keeps the cursor position stable with the text. Minor behavior change to kill_line -- when killing just a newline, the newline char itself goes into the buffer.Takes the abstraction from #6427 that @carlobaldassi found useful.