Skip to content

dump: Fix rountrip#136

Closed
wismill wants to merge 1 commit intolegionus:masterfrom
wismill:dump/fix-roundtrip
Closed

dump: Fix rountrip#136
wismill wants to merge 1 commit intolegionus:masterfrom
wismill:dump/fix-roundtrip

Conversation

@wismill
Copy link
Copy Markdown
Contributor

@wismill wismill commented Jun 4, 2025

These is a conflict between skipping the keymaps in lk_dump_keymaps and forcing all keymaps in lk_dump_keys.

Introduced a new function, lk_dump_keymaps2, that ensures consistency between the 2 functions.

Fixes #135

TODO:

  • Add tests with all keymap shapes

for (i = 0; i < ctx->keymap->total; i++) {
if (ctx->keywords & LK_KEYWORD_ALTISMETA && i == (i | M_ALT))
if (skip_alt && i == (i | M_ALT)) {
fprintf(stderr, "~~~ skip alt keymap %d\n", i);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

missing debug ?

Copy link
Copy Markdown
Contributor Author

@wismill wismill Jun 4, 2025

Choose a reason for hiding this comment

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

Yes 😄 and I have have already fixed it, along with minor formatting issues. Will sync once I have enough changes. I created the MR to let you know I am investigating, but it’s not ready (draft). The current fix is incomplete; there seem to be further issues with LK_KEYWORD_ALTISMETA.

It’s not easy to follow the logic, there are a lot of special cases.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Will sync once I have enough changes. I created the MR to let you know I am investigating.

Thanks!

It’s not easy to follow the logic, there are a lot of special cases.

A lot of code is carried over from the days before git by the original author. A lot of legacy code :(

@wismill wismill force-pushed the dump/fix-roundtrip branch from d412463 to 3ff73b6 Compare June 5, 2025 05:18
@wismill
Copy link
Copy Markdown
Contributor Author

wismill commented Jun 5, 2025

I refactored my fix.

Then I tried to compare the output of --mktable and --bkeymap using the built-in keymap and exported keymap (--tkeymap):

  • loadkeys -u --mktable us
  • loadkeys -u --tkeymap=8 us | loadkeys -u --mktable -

They do not match for any table shape!! Even with my current fix. So there is definitively something fishy with the serializer (and maybe the parser too).

I see the failing tests, so I have to investigate further: what I just break and how to fix master.

@legionus
Copy link
Copy Markdown
Owner

legionus commented Jun 5, 2025

Since loadkeys has never had the ability to dump keymap, no one has ever done such conformance tests.

@wismill wismill force-pushed the dump/fix-roundtrip branch from 3ff73b6 to 9933688 Compare June 5, 2025 17:45
There are two issues related when dumping a keymap in text format:
- These is a conflict between skipping the keymaps in `lk_dump_keymaps`
  and forcing all keymaps in `lk_dump_keys`.

  Fixed by always including all defined keymaps, independently of the
  `LK_KEYWORD_ALTISMETA` flag.
- The function `lk_add_constants` is not called, so implicit mappings
  such as `Ctrl + q = Control_q` are not set.

  Fixed by properly calling `lk_add_constants` before each call of
  `lk_dump_keymap`. `lk_add_constants` is not added to `lk_dump_keymap`,
  since it modifies the keymap.

  Note that since it is easy to forget to call `lk_add_constants`, a
  better fix could be to call `lk_add_constants` just before returning
  from `lk_parse_keymap`.

Signed-off-by: Pierre Le Marre <dev@wismill.eu>
@wismill wismill force-pushed the dump/fix-roundtrip branch from 9933688 to 4b4ab37 Compare June 5, 2025 17:51
@wismill
Copy link
Copy Markdown
Contributor Author

wismill commented Jun 5, 2025

OK, I think I got it: loadkeys --mktable and loadkeys --bkeymap use lk_add_constants(), which adds the implicit mappings. loadkeys --tkeymap and dumkeys did not, thus resulting in incomplete maps.

@legionus
Copy link
Copy Markdown
Owner

@wismill Any news about this ? Do you need any help ?

@legionus legionus mentioned this pull request Jun 29, 2025
@wismill
Copy link
Copy Markdown
Contributor Author

wismill commented Jun 30, 2025

@legionus just not enough freetime.

@legionus
Copy link
Copy Markdown
Owner

just not enough freetime.

@wismill I see.

I reopened your PR as #137, added some fixes and going to merge it.

@legionus legionus closed this Jul 1, 2025
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.

Error trying to roundtrip with --tkeymap

2 participants