Skip to content

Instantly share code, notes, and snippets.

@germ
Last active February 10, 2020 09:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save germ/982d242fb5c44c2f33a0d078118318c5 to your computer and use it in GitHub Desktop.
Save germ/982d242fb5c44c2f33a0d078118318c5 to your computer and use it in GitHub Desktop.
#ifndef PREFIX // This could easily be macro'd
#define PREFIX KC_Z
#endif
SUBS(c1, "void *", PREFIX, KC_H)
SUBS(c2, "int ", PREFIX, KC_J)
SUBS(c3, "const", PREFIX, KC_K)
SUBS(c4, "};", PREFIX, KC_L)
...
#undef PREFIX
#include "c-keywords"
// Override the leader
#define PREFIX KC_N
#include "js-keywords"
// List any combo dictionaries you want loaded to
// your device below!
// QMK wide includes
#include "combos/germ-vim-helpers.def"
#include "combos/jrh-i3-binds.def"
#include "combos/common-statements.def"
// User includes
#include "gergoplex.def"
#include "bigraphhs.def"
#include "laser-shortcuts.def"
#include "cnc-shortcuts.def"
// Keymap helpers
#define K_ENUM(name, key, ...) name,
#define K_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
#define K_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
#define A_ENUM(name, string, ...) name,
#define A_DATA(name, string, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
#define A_COMB(name, string, ...) [name] = COMBO_ACTION(cmb_##name),
#define A_ACTI(name, string, ...) case name: if (pressed) SEND_STRING(string); break;
#define BLANK(...)
// Generate data needed for combos/actions
// Create Enum
#undef COMB
#undef SUBS
#define COMB K_ENUM
#define SUBS A_ENUM
enum combos {
#include "combos.def"
};
// Bake combos into mem
#undef COMB
#undef SUBS
#define COMB K_DATA
#define SUBS A_DATA
#include "combos.def"
#undef COMB
#undef SUBS
// Fill combo array
#define COMB K_COMB
#define SUBS A_COMB
combo_t key_combos[] = {
#include "combos.def"
};
#undef COMB
#undef SUBS
// Export length to combo module
int COMBO_LEN = sizeof(key_combos)/sizeof(key_combos[0]);
// Fill QMK hook
#define COMB BLANK
#define SUBS A_ACTI
void process_combo_event(uint8_t combo_index, bool pressed) {
switch(combo_index) {
#include "combos.def"
}
}
#undef COMB
#undef SUBS
#ifndef PREFIX // This could easily be macro'd
#define PREFIX KC_X
#endif
SUBS(c1, "function ()", PREFIX, KC_H)
SUBS(c2, "number ", PREFIX, KC_J)
SUBS(c3, "const", PREFIX, KC_K)
SUBS(c4, "};", PREFIX, KC_L)
...
#undef PREFIX
// Combos
enum combos {
WE,AS,SD,DF,XC,OP,CV,
UI,HJ,JK,KL,MC,NM,
FV,GB,HN,
SDJK
};
const uint16_t PROGMEM we_combo[] = {KC_W, KC_E, COMBO_END};
const uint16_t PROGMEM sd_combo[] = {KC_S, KC_D, COMBO_END};
const uint16_t PROGMEM df_combo[] = {KC_D, KC_F, COMBO_END};
const uint16_t PROGMEM xc_combo[] = {KC_X, KC_C, COMBO_END};
const uint16_t PROGMEM cv_combo[] = {KC_C, KC_V, COMBO_END};
const uint16_t PROGMEM op_combo[] = {KC_O, KC_P, COMBO_END};
const uint16_t PROGMEM ui_combo[] = {KC_U, KC_I, COMBO_END};
const uint16_t PROGMEM hj_combo[] = {KC_H, KC_J, COMBO_END};
const uint16_t PROGMEM jk_combo[] = {KC_J, KC_K, COMBO_END};
const uint16_t PROGMEM kl_combo[] = {KC_K, KC_L, COMBO_END};
const uint16_t PROGMEM nm_combo[] = {KC_N, KC_M, COMBO_END};
const uint16_t PROGMEM mc_combo[] = {KC_M, KC_COMM, COMBO_END};
const uint16_t PROGMEM gb_combo[] = {KC_G, KC_B, COMBO_END};
const uint16_t PROGMEM fv_combo[] = {KC_F, KC_V, COMBO_END};
const uint16_t PROGMEM hn_combo[] = {KC_H, KC_N, COMBO_END};
const uint16_t PROGMEM sdjk_combo[] = {KC_J, KC_K, KC_S, KC_D, COMBO_END};
combo_t key_combos[COMBO_COUNT] = {
// Horizontal Chords
[WE] = COMBO(we_combo, KC_ESC),
[SD] = COMBO(sd_combo, KC_BSPC),
[DF] = COMBO(df_combo, KC_TAB),
[XC] = COMBO(xc_combo, KC_MINS),
[CV] = COMBO(cv_combo, KC_ENT),
[OP] = COMBO(op_combo, KC_BSLS),
[UI] = COMBO(ui_combo, KC_ESC),
[HJ] = COMBO(hj_combo, KC_LT),
[JK] = COMBO(jk_combo, KC_COLN),
[KL] = COMBO(kl_combo, KC_GT),
[MC] = COMBO(mc_combo, KC_UNDS), // m,
[NM] = COMBO(nm_combo, KC_QUOT),
// Vertical
[GB] = COMBO(gb_combo, KC_BTN1),
[FV] = COMBO(fv_combo, KC_BTN2),
[HN] = COMBO(hn_combo, KC_ENT)
};
#define C_ENUM(name, key, ...) name,
#define C_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
#define C_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
#define BLANK(...)
// Generate data needed for combos/actions
// Create Enum
#undef COMB
#define COMB C_ENUM
enum combos {
#include "combos.def"
};
// Bake combos into mem
#undef COMB
#define COMB C_DATA
#include "combos.def"
#undef COMB
// Fill combo array
#define COMB C_COMB
combo_t key_combos[] = {
#include "combos.def"
};
#undef COMB
...
#include QMK_KEYBOARD_H
#include "g/keymap_combo.h" // Nasty stuff hidden away, loads combo.def
...
#define COMBO(outputKey, inputKeys...) // Wait this needs to be in three places!
#define C_ENUM(id) id,
#define C_STOR(name, ...) const uint16_t PROGMEM cmb_#name[] = {__VA_ARGS__, COMBO_END};
#define C_COMBO(id, name, key) [id] = COMBO(name, key),
#define C_ENUM(name, key, ...) name,
#define C_DATA(name, key, ...) const uint16_t PROGMEM cmb_##name[] = {__VA_ARGS__, COMBO_END};
#define C_COMB(name, key, ...) [name] = COMBO(cmb_##name, key),
enum combo_events {
ZC_COPY,
XV_PASTE
};
const uint16_t PROGMEM copy_combo[] = {KC_Z, KC_C, COMBO_END};
const uint16_t PROGMEM paste_combo[] = {KC_X, KC_V, COMBO_END};
combo_t key_combos[COMBO_COUNT] = {
[ZC_COPY] = COMBO_ACTION(copy_combo),
[XV_PASTE] = COMBO_ACTION(paste_combo),
};
void process_combo_event(uint8_t combo_index, bool pressed) {
switch(combo_index) {
case ZC_COPY:
if (pressed) {
tap_code16(LCTL(KC_C));
}
break;
case XV_PASTE:
if (pressed) {
tap_code16(LCTL(KC_V));
}
break;
}
}
// Vim-Mode combos
COMB(weEsc, KC_ESC, KC_W, KC_E)
COMB(sdBspc, KC_BSPC, KC_S, KC_D)
COMB(dfTab, KC_TAB, KC_D, KC_F)
COMB(cvEnt, KC_ENT, KC_C, KC_V)
COMB(uiEsc, KC_ESC, KC_U, KC_I)
COMB(jkCol, KC_COLN, KC_J, KC_K)
COMB(hnEnt, KC_ENT, KC_H, KC_N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment