Skip to content

Conversation

hardenedapple
Copy link
Contributor

@hardenedapple hardenedapple commented Apr 10, 2017

I had written some tests initially intending to fix the problems they show.
I've changed my mind, and don't plan on fixing them, as, frankly it's not a pain point for me, and it seems like a lot of effort.
I've made some improvements in the 'langmap' option by recording the translated keys.

I have also covered two special cases that were previously not translated. I think this is an improvement, but others may disagree.
I have left other special cases alone despite thinking they may be better changed -- that's a topic I'd like to get input on.

n.b. the recording of 'langmap' translations in macros was discussed here.

@marvim marvim added the WIP label Apr 10, 2017
@hardenedapple hardenedapple changed the title [WIP] Langmap things [RFC] Langmap things Apr 11, 2017
@marvim marvim added RFC and removed WIP labels Apr 11, 2017
end)
-- pending('-- More -- prompt', function()
-- -- The 'b' 'j' 'd' 'f' commands at the -- More -- prompt
-- end)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should be implemented, but I couldn't immediately see how to write it and just left it as a comment.

local curwin = helpers.curwin

describe("'langmap'", function()
clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? it's already in before_each().

@justinmk
Copy link
Member

justinmk commented May 13, 2017

In 5414960 this wording doesn't make sense to me:

This changes functionality it two places that used to be in my
"exceptions" category. It now applies 'langmap' in these cases when it
didn't before.
I'm not "fixing" them because I believe they should be changed. On the
other hand, there are still other "exception" cases that have not been
changed because the way to do so is reasonably ugly, and not changing
percieved bad behaviour is not objectionable.

A lot of things in that paragraph seem contradictory. Can it be reworded?

@@ -1465,9 +1465,10 @@ int vgetc(void)
* converted character.
* Note: This will loop until enough bytes are received!
*/
if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1) {
buf[0] = (char_u)c;
i = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is an odd place to put this, because it's done again on line 1472. Perhaps this should go in a else {} block?

-- This is a reasonably easy fix, but it doesn't make sense to fix this and
-- not translating text recorded in the macro when mappings are not
-- applied.
feed_command('nnoremap w l')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use command in most cases, unless the asynchrony of feed_command is needed.

@hardenedapple
Copy link
Contributor Author

Just as a caveat -- at the time I made this PR [RFC] it was to get feedback on whether the functional changes I'd made were good or not, not because I thought the commits were ready to merge.

Yeah I apologise about that commit message, what I was trying to say was:

  • At the moment (before that commit) there are 7 exceptions (that I know of) where vim takes a character to apply as a command, yet langmap is not applied I personally think they shouldn't exist.
  • After that commit, 2 of those exceptions are not exceptions any more, I could make them exceptions again, but that requires adding a few lines of code.
  • On the other hand, in that commit I don't add code to force the functional change on the other 5 exceptions because I believe that adding code requires more justification than not adding it.

A less kind-to-me way of putting it is:

I'm lazy and like the changes in functionality this introduces so I'm not going to bother adding code to get rid of it. On the other hand, I don't think I can justify changing all the other cases just because I don't like them in what claims to be a bug-fix / code-neaten PR.

@hardenedapple
Copy link
Contributor Author

To note (thought this might be unclear just from the commits).

  • c8e8196 is an independent bug-fix commit that doesn't need any of the others. It's this that I referred to in the gitter room.
  • ccf7e5d makes it so that a map triggered while recording a macro is triggered when replaying it (i.e. applies langmap to the characters recorded when those characters trigger a map). It doesn't make sense to have this but not 5414960
  • 5414960 does the same fix as ccf7e5d for recording unmapped keys in a macro (so that replaying a macro does the same as what happened while recording it), but it introduces the other functionality changes I'm unsure about.

@justinmk justinmk added this to the 0.2.1 milestone May 14, 2017
@hardenedapple
Copy link
Contributor Author

I just noticed a bug while recording macros under this PR and wanted to mention it so the bug doesn't get merged.

The bug can be seen using a special key like <BS>.

Starting with neovim -u NONE and pressing the following keys

qaohellot<BS><esc>q@a

you see that the macro doesn't replay the same actions that happened while it was being recorded.
I expect this is because recording is now done after unescaping special keys instead of before.

I'll get round to fixing it, but in a while ...

I still believe the commit changing the definition of the LANGMAP_ADJUST is good (it's independent of the others).

@justinmk justinmk modified the milestones: 0.2.1, 0.2.2 Sep 16, 2017
@justinmk
Copy link
Member

@hardenedapple Which commits here are ready to merge?

@hardenedapple
Copy link
Contributor Author

hardenedapple commented Jan 21, 2018

@justinmk I'll have a look at this over the next week (probably next weekend).

There is one commit that fixes a simple bug, while the other commits are around
getting 'langmap' to behave with macros in the same way that #5658
was trying to get :lmap to behave.

From what I remember, this PR worked fine, but changing 'langmap' without
changing :lmap seemed inconsistent, and hence I didn't push anything through.

I'll need to find those parts of the tests I introduced to check the macro
behaviour and split them out from the tests checking the current behaviour of
'langmap'.

Once I've done that I'll create a separate PR containing the tests for the
current behaviour (including some known bugs) and the commit fixing the plain
bug.

@hardenedapple
Copy link
Contributor Author

hardenedapple commented Jan 27, 2018

I've split the PR into two.
PR #7919 is the bug fix, this PR now only contains the behaviour to do with macro recording in a similar way to #5658 .

This PR is some commits on top of the ones in #7919
This PR has merge conflicts with #5658 they're ones I've resolved quite a few times locally.

@hardenedapple
Copy link
Contributor Author

After the merge of #7919 this has been rebased onto master.

@hardenedapple hardenedapple changed the title [RFC] Langmap things [RDY] Langmap things Feb 11, 2018
@marvim marvim removed the RFC label Feb 11, 2018
We put LANGMAP_ADJUST() in vgetc() instead of vgetorpeekc(), because
vgetc() is the first place that vim switches from handling bytes to
characters.
The only place vgetorpeek() is called outside of vgetc() is vpeekc()
Each of the calling places of this is written below, along with the
reason that not applying LANGMAP in that case is fine.

insertchar() (in INSERT mode)
command_line_execute() (in CMDLINE mode)
command_line_changed() (in CMDLINE mode)
getexline() (used when executing from register)
openscript() (return value is not used)
vpeekc_any() which is used in
    ins_compl_check_keys() (in INSERT mode)
    f_getchar() (checked against empty (i.e. LANGMAP doesn't matter)
    command_line_changed() (check for empty)
char_avail() (checked against empty)
normal_get_additional_char() (Check for empty,
                              Check for empty,
                              Check for multibyte to determine
                              whether need to read more, any more is
                              read with plain_vgetc())
do_mouse() (Check for empty)

Before this commit, there are 7 exceptions to the rule that 'langmap' is
applied whenever neovim takes a key to be interpreted as a command.
These exceptions are mentioned in the test spec.
This commit changes two of these so they are no longer exceptions,
these are: confirming whether to apply a substitution after :s///c, and
asking y/n after a backwards range.

I'm leaving the changes as I believe they are improvements.
On the other hand, I'm not changing the behaviour of the other
exceptions despite being of the opinion that they should change, as the
point of this commit is to record the 'langmap' translation in macros,
not to change when the 'langmap' translation is applied.
@justinmk justinmk modified the milestones: 0.3.1, 0.3.2 Jun 10, 2018
@justinmk
Copy link
Member

justinmk commented Jan 3, 2019

@hardenedapple Now would be a good time to merge this. But users won't know about it unless we describe it. Can you suggest a documentation update, or at least a brief description of the behavior changes?

@roket1428
Copy link

Tested, it fixes macro behaviors of langmap. Sweet!

@hardenedapple
Copy link
Contributor Author

@justinmk I've just merged with master and re-run the tests.

One thing that surprised me:

If you remember from my comment above #6494 (comment) , there were some exceptions to the general rule of "commands have LANGMAP applied" that I recorded in the testsuite.
One of those exceptions is not an exception any more.

Frankly I don't understand the previous behaviour (haven't spent enough time investigating since I'm not worried about it) but the current behaviour makes sense.

Overall, the PR doesn't seem to have bitrotted too much.

Documentation changes?

In regards to documentation changes: The idea is that this series makes things work as one would expect from the documentation as it is. The differences are:

  1. Macros behave properly after langmap translation.
  2. Some places where one would expect a LANGMAP translation but there isn't one now have that translation applied.

Apologies for going dark -- I got more busy ;-)

@janlazo janlazo modified the milestones: 0.5, 0.5.1 Feb 14, 2021
@bfredl bfredl modified the milestones: 0.5.1, 0.6 Aug 15, 2021
@bfredl bfredl modified the milestones: 0.6, 0.7 Oct 30, 2021
@clason clason removed this from the 0.7 milestone Feb 24, 2022
@amerlyq
Copy link

amerlyq commented Apr 24, 2022

I still can't understand, does this PR fixes the vim/vim#3018 bug, and specifically vim/vim#7458 bug of not supporting multibyte chars in "from" ?

@zeertzjq zeertzjq added the input label Mar 20, 2023
@dundargoc dundargoc changed the title [RDY] Langmap things Langmap things Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants