codethread / qmk.nvim

Format qmk and zmk keymaps in neovim
MIT License
134 stars 5 forks source link

Saving destroys the layout #17

Closed RomanoZumbe closed 1 year ago

RomanoZumbe commented 1 year ago

When I save my layout all keymaps will be written into a single line. The plugin then complains with E03. Thats because the closing bracket of the keymaps array is in the same line as the last keymap. When I change that I can use QMKFormat but after saving the issue is there again. So I guess another formatter is in the way.

Also since a couple of days I get a lot of errors when loading the plugin from lazy. Could that be a problem with neovim 0.9?

codethread commented 1 year ago

hi, thanks for raising

The errors shouldn't be present if you update to the latest version, this was indeed warnings coming from 0.9, and they should now be resolved.

As for the saving issue, please could you post your current config and your keymap please? thanks 😄

RomanoZumbe commented 1 year ago

Hi! Thanks for the fast response! After updating I can't load the plugin anymore. This is the error nvim throws:

image

This is my (lazy)config:

return {
  'codethread/qmk.nvim',
  config = function()
    local conf = {
      name = 'LAYOUT',
      layout = {
        'x x x x x x _ _ _ x x x x x x',
        'x x x x x x _ _ _ x x x x x x',
        'x x x x x x _ _ _ x x x x x x',
        'x x x x x x x _ x x x x x x x',
        '_ _ x x x x x _ x x x x x _ _',
      }
    }
    require('qmk').setup(conf)
  end
}

And these are my layouts (after saving). I removed the comments:

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { [Qwerty] = LAYOUT(KC_ESC, KC_0, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_LALT, LGUI_T(KC_Q), KC_W, KC_E, KC_R, KC_T, DE_Y, KC_U, KC_I, ALGR_T(KC_O), KC_P, KC_LALT, KC_LGUI, KC_A, KC_S, LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_H, LSFT_T(KC_J), LCTL_T(KC_K), LALT_T(KC_L), DE_QUOT, KC_LGUI, SS_CIRC, LT(Button, DE_Z), LALT_T(KC_X), KC_C, KC_V, KC_B, KC_MUTE, XXXXXXX, KC_N, KC_M, DE_COMM, DE_DOT, DE_SLSH, KC_DLR, TD(TD_LOCK_LAYER), KC_LALT, LT(Media, KC_ESC), LT(Nav, KC_ENT), LT(Mouse, KC_TAB), LT(Sym, KC_SPC), LT(Num, KC_BSPC), LT(Fun, KC_DEL), KC_RALT, KC_RGUI),

[Nav] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, LGUI_T(KC_Q), KC_W, KC_E, KC_R, KC_PSCR, DE_Y, KC_U, KC_I, KC_O, KC_P, KC_ESC, SS_CIRC, KC_A, KC_S, LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_LEFT, KC_DOWN, KC_UP, KC_RIGHT, DE_QUOT, KC_DLR, KC_ESC, LT(Button, DE_Z), LALT_T(KC_X), KC_C, KC_V, KC_B, KC_MUTE, XXXXXXX, KC_HOME, KC_PGDN, KC_PGUP, KC_END, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, LT(Media, KC_ESC), LT(Nav, KC_ENT), LT(Mouse, KC_TAB), KC_SPC, KC_BSPC, KC_DEL, KC_RALT, KC_RGUI),

[Mouse] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, LGUI_T(KC_Q), KC_W, KC_E, KC_R, KC_T, DE_Y, DE_UDIA, KC_MS_U, DE_ODIA, KC_P, KC_ESC, SS_CIRC, DE_ADIA, DE_SS, LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_LEFT, KC_MS_L, KC_MS_D, KC_MS_R, DE_QUOT, KC_DLR, KC_ESC, LT(Button, DE_Z), LALT_T(KC_X), KC_C, KC_V, KC_B, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, LT(Media, KC_ESC), LT(Nav, KC_ENT), LT(Mouse, KC_TAB), KC_BTN2, KC_BTN1, KC_BTN3, KC_RALT, KC_RGUI),

[Media] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, LGUI_T(KC_Q), KC_W, KC_E, KC_R, KC_T, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG, KC_ESC, SS_CIRC, DE_ADIA, DE_SS, LCTL_T(KC_D), LSFT_T(KC_F), KC_G, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, KC_ESC, KC_ESC, KC_ESC, LT(Button, DE_Z), LALT_T(KC_X), KC_C, KC_V, KC_B, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, LT(Media, KC_ESC), LT(Nav, KC_ENT), LT(Mouse, KC_TAB), KC_MSTP, KC_MPLY, KC_MUTE, KC_RALT, KC_RGUI),

[Num] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, DE_LBRC, KC_7, KC_8, KC_9, DE_RBRC, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG, KC_ESC, SS_CIRC, DE_SCLN, KC_4, KC_5, KC_6, DE_EQL, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, KC_ESC, KC_ESC, KC_ESC, DE_GRV, KC_1, KC_2, KC_3, DE_BSLS, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, DE_DOT, KC_0, DE_MINS, KC_SPC, KC_BSPC, KC_DEL, KC_ENT, KC_RGUI),

[Sym] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, DE_LCBR, DE_AMPR, DE_ASTR, DE_LPRN, DE_RCBR, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG, KC_ESC, SS_CIRC, DE_COLN, DE_DLR, DE_PERC, DE_CIRC, DE_PLUS, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, KC_ESC, KC_ESC, KC_ESC, DE_TILD, DE_EXLM, DE_AT, DE_HASH, DE_PIPE, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, DE_LPRN, DE_RPRN, DE_UNDS, KC_MSTP, KC_MPLY, KC_MUTE, KC_RALT, KC_RGUI),

[Fun] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, KC_F12, KC_F7, KC_F8, KC_F9, KC_PSCR, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG, KC_ESC, SS_CIRC, KC_F11, KC_F4, KC_F5, KC_F6, KC_SCROLL_LOCK, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, KC_ESC, KC_ESC, KC_ESC, KC_F10, KC_F1, KC_F2, KC_F3, KC_PAUS, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, KC_APP, KC_SPC, KC_TAB, KC_MSTP, KC_MPLY, KC_MUTE, KC_RALT, KC_RGUI),

[Button] = LAYOUT(KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, SS_CRYPT, KC_ESC, C(DE_Z), C(KC_X), C(KC_C), C(KC_V), C(DE_Y), RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, RGB_TOG, KC_ESC, SS_CIRC, KC_F11, KC_F4, KC_F5, KC_F6, KC_SCROLL_LOCK, KC_MPRV, KC_VOLD, KC_VOLU, KC_MNXT, KC_ESC, KC_ESC, KC_ESC, KC_F10, KC_F1, KC_F2, KC_F3, KC_PAUS, KC_MUTE, XXXXXXX, KC_WH_L, KC_WH_D, KC_WH_U, KC_WH_R, KC_INS, KC_ESC, TD(TD_LOCK_LAYER), KC_LALT, KC_APP, KC_SPC, KC_TAB, KC_MSTP, KC_MPLY, KC_MUTE, KC_RALT, KC_RGUI),

[Emoji] = LAYOUT(KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_GRV, KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, DE_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, X(SWEAT), X(GRIN), X(THUMBS_UP), X(ROFL), KC_QUOT, KC_LSFT, DE_Z, KC_X, KC_C, KC_V, KC_B, KC_MUTE, XXXXXXX, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, TD(TD_LOCK_LAYER), KC_LALT, KC_LCTL, _______, MT(MOD_LSFT, KC_ENT), KC_SPC, KC_RAISE, KC_RCTL, KC_RALT, KC_RGUI)};
codethread commented 1 year ago

🤦 ok the error was my bad - grab the latest version and that is also now fixed 😅

as for the layout, it works fine for me... the only edit I needed to make was putting the trailing } on a new line:

- ... KC_RGUI)};
becomes
+ ... KC_RGUI)
+ };

and then everything formats:

image

So all I can think is that like you say, there is another formatter, perhaps clang? You can use a comment to disable it if so, e.g:

// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[_QWERTY] = LAYOUT_preonic_grid(
// ...etc

You can use :au BufWritePre in neovim to see all autocommands that will run when the file is saved, and hopefully that helps you narrow it down 😄

codethread commented 1 year ago

As I can format with the desired behaviour, and I believe the loading errors are sorted, I'm going to resolve this. Please feel free to reopen if you are still getting issues with the installation, or believe there is a conflict between what this plugin is doing and others are doing to format files (that can't be resolved by disabling one, e.g through comments) 😄 thanks

RomanoZumbe commented 1 year ago

Works perfect! Thank you for the work! I didn't know about turning off formating via comments. That will be very usefull