Skip to content

Conversation

@hardenedapple
Copy link
Contributor

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.

@justinmk
Copy link
Member

👍 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.

@justinmk justinmk added this to the 0.2.1 milestone Mar 26, 2017
@marvim marvim added the WIP label Mar 26, 2017
@hardenedapple
Copy link
Contributor Author

Just a note for anyone viewing the commits: adding ?w=1 to the end of a commit URL gives the diff ignoring whitespace.

This is especially useful for those commits adding/removing a block separation.

@hardenedapple
Copy link
Contributor Author

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.

@hardenedapple hardenedapple force-pushed the vgetorpeek-disect branch 2 times, most recently from 1f8b808 to 9241309 Compare March 28, 2017 14:56
@jszakmeister jszakmeister removed the WIP label Mar 28, 2017
@hardenedapple
Copy link
Contributor Author

That was an accidental close -- I ran git-push with the base commit in the hopes the travis tests would be run on something without any changes.

@hardenedapple hardenedapple reopened this Mar 28, 2017
@marvim marvim added the WIP label Mar 28, 2017
@hardenedapple hardenedapple force-pushed the vgetorpeek-disect branch 7 times, most recently from 48f4ca2 to 726f9da Compare April 3, 2017 15:57
@hardenedapple hardenedapple changed the title [WIP] Vgetorpeek disect [RFC] Vgetorpeek disect Apr 5, 2017
@hardenedapple
Copy link
Contributor Author

While I didn't keep the entire PR small, each step is really small, so reviewing and merging individual commits should be easy.

@bfredl
Copy link
Member

bfredl commented Apr 5, 2017

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.

if ((*mb_ptr2cells)(ptr + col) > 1)
--curwin->w_wcol;
vcol += lbr_chartabsize(ptr, ptr + col, (colnr_T)vcol);
if (has_mbyte) {
Copy link
Member

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.

--curwin->w_wcol;
vcol += lbr_chartabsize(ptr, ptr + col, (colnr_T)vcol);
if (has_mbyte) {
col += (*mb_ptr2len)(ptr + col);
Copy link
Member

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.

@marvim marvim added RFC and removed WIP labels Apr 5, 2017
@hardenedapple
Copy link
Contributor Author

I've merged a bunch of logically similar commits together as suggested.

return p_tm;
}

static int handle_int(const int advance)
Copy link
Contributor

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.
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.
hardenedapple added a commit to hardenedapple/neovim that referenced this pull request Apr 25, 2017
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.
@justinmk justinmk modified the milestones: 0.2.1, 0.2.2 Sep 16, 2017
@justinmk justinmk modified the milestones: 0.3.1, 0.3.2 Jun 10, 2018
@justinmk justinmk removed the RFC label Jan 28, 2020
@janlazo
Copy link
Contributor

janlazo commented Nov 14, 2020

Vim patches 8.1.1792, 8.1.1797 refactor vgetorpeek. Reopen this if porting those patches is insufficient.

@janlazo janlazo closed this Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants