-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
[RFC] Vgetorpeek disect #6370
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
[RFC] Vgetorpeek disect #6370
Conversation
|
👍 Try to keep the PR as small as possible, and avoid style changes where a line would otherwise be untouched. Then we can merge (and review more easily) the incremental steps. |
|
Just a note for anyone viewing the commits: adding This is especially useful for those commits adding/removing a block separation. |
|
I made a mistake in 90fed0a that I fixed in 18697a9 . I now have the code mostly readable, so I'm going to slowly rebase to remove that mistake. That's when I'll make sure each commit passes all automated tests. Just mentioning that here so that anyone having a look at this PR understands where all the commits go after this point. |
1f8b808 to
9241309
Compare
9241309 to
f9a31e9
Compare
|
That was an accidental close -- I ran |
48f4ca2 to
726f9da
Compare
|
While I didn't keep the entire PR small, each step is really small, so reviewing and merging individual commits should be easy. |
|
82 commits is a bit much to review commits individually, maybe logically similar commits can be squashed? Also small stylistic/clint changes can be squashed together with a preceding related change, no need for a separate commit just for joining two lines, for instance. |
src/nvim/getchar.c
Outdated
| if ((*mb_ptr2cells)(ptr + col) > 1) | ||
| --curwin->w_wcol; | ||
| vcol += lbr_chartabsize(ptr, ptr + col, (colnr_T)vcol); | ||
| if (has_mbyte) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use that has_mbyte is always true in nvim.
src/nvim/getchar.c
Outdated
| --curwin->w_wcol; | ||
| vcol += lbr_chartabsize(ptr, ptr + col, (colnr_T)vcol); | ||
| if (has_mbyte) { | ||
| col += (*mb_ptr2len)(ptr + col); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also with larger refactorings we should change (*mb_func)( and MB_FUNC( to to mb_func(. The only reason against would be merging from vim easier but with heavy refactoring applying patches must be done manually anyway.
c797be6 to
3dfa1ae
Compare
|
I've merged a bunch of logically similar commits together as suggested. |
src/nvim/getchar.c
Outdated
| return p_tm; | ||
| } | ||
|
|
||
| static int handle_int(const int advance) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I appreciate that int is often understood as interrupt and brevity is important, I think it would make sense to name this one handle_interrupt.
The block only did anything if (mp == NULL), but was entered if (mp == NULL || <something>), so remove the <something>.
After a lot of small changes it becomes apparent that this value a) is not used anywhere else, and b) has no stored state over different loop iterations.
It's a little superfluous, but it means that no-one has to look in check_togglepaste() to see that if a mapping has been found it does nothing. This makes it clearer when viewing look_in_typebuf() that mappings are treated preferentially.
Separate the uses into measuring the number of bytes read by inchar() and returning to vgetorpeek() the next character to use. The only time that it matters what value vgetorpeek() ends up with for 'c' is when it's breaking out of the for loop. This is only when get_key_from_user() is returning 1.
It's never used as a value in the for(;;) loop -- it's just set to the return value before signalling that vgetorpeek() has to break out of the loop and return.
I had added it to demonstrate that showcmd_len, wait_tb_len, and c1, were only ever used in that block. After more refactoring it's obvious because this block is now at the end of a function.
Because this block was the last in the for loop, we don't need to distinguish between `carry on` and `continue;`. Hence I can substitute all `return 0;` statements with `return -1;` and use returning `0` as a valid value to set 'c'.
Initially it was in the middle of things, so it needed to specify continue/break/fall-through etc, but now it's at the end of a function, and given the use of the function, we can remove most flow-control from it. This leaves the if/else clause only updating things as required.
First step to putting this in separate function.
Use local_State in the LANGMAP_ADJUST() condition Separate a long if clause into many Set `mode_deleted` and `timedout` to be bools
Improvements in comments. Rename handle_int() -> handle_interrupt() Show keylen is set to 0 in find_typed_map() when no mapping found. Replace NUL with 0.
As he pointed out, there's no real benefit to having it as a separate function.
e664ee1 to
3cd65d6
Compare
Rather than pass values by reference into functions that only need to update those values, we don't give functions that information, and make all updates in the calling function by copying members from a returned structure. This makes it much clearer what information a function may be affected by, and what information is updated. Also use an enum in a few places, to limit the information a function is given.
3cd65d6 to
8cae556
Compare
Easier to work on top of, and if that's not taken on board then the likelyhood of this being taken on board is pretty low.
|
Vim patches 8.1.1792, 8.1.1797 refactor |
I'm in the middle of trying to understand
vgetorpeek(), and in order to do so I'm refactoring it into a form I can read easier.I thought I'd open a PR to see if people want the refactoring in the main branch and to take advantage of the multiple tests runs.
I can see that refactoring in such a low-level function may feel too dangerous too include.
I haven't done much as yet -- most of splitting into separate functions hasn't been started yet.