babblePaste.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* A library to output the right key shortcut in any common app.
  2. Given a global variable babble_mode to show the environment and a
  3. key that calls the paste macro, do the right type of paste.
  4. Setting the context is done by another macro, or TBD interaction with the host.
  5. Huge thanks to https://en.wikipedia.org/wiki/Table_of_keyboard_shortcuts
  6. and https://github.com/qmk/qmk_firmware/blob/master/keyboards/planck/keymaps/jeebak/keymap.c
  7. */
  8. #include "babblePaste.h"
  9. #include "action_macro.h"
  10. #ifdef USE_BABLPASTE
  11. // GLOBAL variable to determine mode. Sets startup default if no eeppom
  12. uint8_t babble_mode =0 ;
  13. // Today I learned that the preprocessor can not create a switch statement label from an argument
  14. // And else statements have problems, see https://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC15
  15. #define BABLM(ent, macro...) \
  16. if ( ent == shortcut ) \
  17. { action_macro_play( MACRO(macro)); return MACRO_NONE; }
  18. const macro_t *babblePaste (keyrecord_t *record, uint8_t shortcut) {
  19. /* this function runs the appropriate babblepaste macro, given
  20. the global babble_mode, and a shortcut from the ENUM in babblePaste.h
  21. TODO, the pointers in this function should be stored in a PROGMEM array, not ram.
  22. But that requires even more clever preprocessor foo.
  23. */
  24. if ( shortcut < BABL_START_NUM || \
  25. shortcut >= (BABL_START_NUM + BABL_NUM_MACROS ) ) {
  26. return MACRO_NONE;
  27. }
  28. switch(babble_mode) {
  29. #ifdef MS_MODE
  30. case MS_MODE:
  31. BABLM( BABL_DEL_RIGHT_1C, T(DEL), END );
  32. BABLM( BABL_DEL_LEFT_WORD, D(LCTRL), T(BSPACE), U(LCTRL), END );
  33. BABLM( BABL_DEL_RIGHT_WORD,D(LCTRL), T(DEL), U(LCTRL), END );
  34. BABLM( BABL_GO_LEFT_1C, T(LEFT), END );
  35. BABLM( BABL_GO_RIGHT_1C , T(RIGHT), END );
  36. BABLM( BABL_GO_LEFT_WORD, D(LCTRL), T(LEFT), U(LCTRL), END );
  37. BABLM( BABL_GO_RIGHT_WORD, D(LCTRL), T(RIGHT), U(LCTRL), END );
  38. BABLM( BABL_GO_START_LINE, T(HOME), END );
  39. BABLM( BABL_GO_START_DOC, D(LCTRL),T(HOME), U(LCTRL),END );
  40. BABLM( BABL_GO_END_LINE, T(END), END );
  41. BABLM( BABL_GO_END_DOC, D(LCTRL),T(END), U(LCTRL),END );
  42. BABLM( BABL_GO_NEXT_LINE, T(DOWN), END );
  43. BABLM( BABL_GO_PREV_LINE, T(UP), END );
  44. BABLM( BABL_PGDN, T(PGDN), END );
  45. BABLM( BABL_PGUP, T(PGUP), END );
  46. #ifndef BABL_MOVEMENTONLY
  47. BABLM( BABL_UNDO, D(LCTRL), T(Z), U(LCTRL), END );
  48. BABLM( BABL_REDO, D(LCTRL), T(Y), U(LCTRL), END );
  49. BABLM( BABL_CUT, D(LCTRL), T(X), U(LCTRL), END );
  50. BABLM( BABL_COPY, D(LCTRL), T(C), U(LCTRL), END );
  51. BABLM( BABL_PASTE, D(LCTRL), T(V), U(LCTRL), END );
  52. BABLM( BABL_SELECT_ALL, D(LCTRL), T(A), U(LCTRL), END );
  53. BABLM( BABL_UNDO, D(LCTRL), T(Z), U(LCTRL), END );
  54. BABLM( BABL_REDO, D(LCTRL), T(Y), U(LCTRL), END );
  55. BABLM( BABL_CUT, D(LCTRL), T(X), U(LCTRL), END );
  56. BABLM( BABL_COPY, D(LCTRL), T(C), U(LCTRL), END );
  57. BABLM( BABL_PASTE, D(LCTRL), T(V), U(LCTRL), END );
  58. BABLM( BABL_SELECT_ALL, D(LCTRL), T(A), U(LCTRL), END );
  59. BABLM( BABL_FIND, D(LCTRL),T(F), U(LCTRL),END );
  60. BABLM( BABL_FIND_NEXT, T(F3),END );
  61. BABLM( BABL_FIND_REPLACE, D(LCTRL),T(H), U(LCTRL),END );
  62. BABLM( BABL_RUNAPP, D(LGUI),T(R), U(LGUI),END );
  63. BABLM( BABL_SWITCH_APP_NEXT, D(LALT),T(TAB), U(LALT),END );
  64. BABLM( BABL_SWITCH_APP_LAST, D(LSFT),D(LALT),T(TAB), U(LALT), U(LSFT),END );
  65. BABLM( BABL_CLOSE_APP, D(LALT),T(F4), U(LALT),END );
  66. BABLM( BABL_HELP, T(F1),END );
  67. #endif
  68. return MACRO_NONE;
  69. #endif /* MS_MODE*/
  70. #ifdef LINUX_MODE
  71. case LINUX_MODE:
  72. BABLM( BABL_DEL_RIGHT_1C , D(DEL), END );
  73. BABLM( BABL_DEL_LEFT_WORD , D(LCTRL), T(BSPACE), U(LCTRL), END );
  74. BABLM( BABL_DEL_RIGHT_WORD , D(LCTRL), T(DEL), U(LCTRL), END );
  75. BABLM( BABL_GO_LEFT_1C , T(LEFT), END );
  76. BABLM( BABL_GO_RIGHT_1C , T(RIGHT), END );
  77. BABLM( BABL_GO_LEFT_WORD , D(LCTRL), T(LEFT), U(LCTRL), END );
  78. BABLM( BABL_GO_RIGHT_WORD , D(LCTRL), T(RIGHT), U(LCTRL), END );
  79. BABLM( BABL_GO_START_LINE , T(HOME), END );
  80. BABLM( BABL_GO_START_DOC , D(LCTRL),T(HOME), U(LCTRL),END );
  81. BABLM( BABL_GO_END_LINE , T(END), END );
  82. BABLM( BABL_GO_END_DOC , D(LCTRL),T(END), U(LCTRL),END );
  83. BABLM( BABL_GO_NEXT_LINE , T(DOWN), END );
  84. BABLM( BABL_GO_PREV_LINE , T(UP), END );
  85. BABLM( BABL_PGDN , T(PGDN), END );
  86. BABLM( BABL_PGUP , T(PGUP), END );
  87. #ifndef BABL_MOVEMENTONLY
  88. BABLM( BABL_UNDO , D(LCTRL), T(Z), U(LCTRL), END );
  89. BABLM( BABL_REDO , D(LCTRL), T(Y), U(LCTRL), END );
  90. BABLM( BABL_CUT , D(LCTRL), T(X), U(LCTRL), END );
  91. BABLM( BABL_COPY , D(LCTRL), T(C), U(LCTRL), END );
  92. BABLM( BABL_PASTE , D(LCTRL), T(V), U(LCTRL), END );
  93. BABLM( BABL_SELECT_ALL, D(LCTRL), T(A), U(LCTRL), END );
  94. BABLM( BABL_FIND, D(LCTRL),T(F), U(LCTRL),END );
  95. /* BABLM(BABL_FIND_NEXT , T(F3),END ); KDE */
  96. BABLM( BABL_FIND_NEXT, D(LCTRL),T(G), U(LCTRL),END ); // Gnome*/
  97. /* BABLM( , D(LCTRL),T(R), U(LCTRL),END ); KDE */
  98. BABLM( BABL_FIND_REPLACE, D(LCTRL),T(H), U(LCTRL),END ); // Gnome*/
  99. BABLM( BABL_RUNAPP, D(LALT),T(F2), U(LALT),END );
  100. BABLM( BABL_SWITCH_APP_NEXT, D(LCTL),T(TAB), U(LCTL),END );
  101. BABLM( BABL_SWITCH_APP_LAST, D(LSFT),D(LCTL),T(TAB), U(LCTL), U(LSFT),END );
  102. BABLM( BABL_CLOSE_APP, D(LALT),T(F4), U(LALT),END );
  103. BABLM( BABL_HELP, END );
  104. #endif
  105. return MACRO_NONE;
  106. #endif
  107. #ifdef MAC_MODE
  108. case MAC_MODE:
  109. BABLM( BABL_DEL_RIGHT_1C , D(DEL), END );
  110. BABLM( BABL_DEL_LEFT_WORD , D(LALT), T(BSPACE), U(LALT), END );
  111. BABLM( BABL_DEL_RIGHT_WORD, D(LALT), T(DEL), U(LALT), END );
  112. BABLM( BABL_GO_LEFT_1C , T(LEFT), END );
  113. BABLM( BABL_GO_RIGHT_1C, T(RIGHT), END );
  114. BABLM( BABL_GO_LEFT_WORD , D(LALT), T(LEFT), U(LALT), END );
  115. BABLM( BABL_GO_RIGHT_WORD , D(LALT), T(RIGHT), U(LALT), END );
  116. BABLM( BABL_GO_START_LINE , D(LGUI), T(LEFT), U(LGUI), END );
  117. BABLM( BABL_GO_START_DOC , D(LGUI),T(UP), U(LGUI),END );
  118. BABLM( BABL_GO_END_LINE , D(LGUI), T(RIGHT), U(LGUI), END );
  119. BABLM( BABL_GO_END_DOC , D(LGUI),T(DOWN), U(LGUI),END );
  120. BABLM( BABL_GO_NEXT_LINE , T(DOWN), END );
  121. BABLM( BABL_GO_PREV_LINE , T(UP), END );
  122. BABLM( BABL_PGDN , D(LALT),T(DOWN), U(LALT), END );
  123. BABLM( BABL_PGUP , D(LALT),T(UP), U(LALT), END );
  124. #ifndef BABL_MOVEMENTONLY
  125. BABLM( BABL_UNDO , D(1), D(LGUI), T(Z), U(LGUI), END );
  126. BABLM( BABL_REDO , D(LSFT),D(LGUI), T(Z), U(LSFT),U(LGUI), END );
  127. BABLM( BABL_CUT , D(LGUI), T(X), U(LGUI), END );
  128. BABLM( BABL_COPY , D(LGUI), T(C), U(LGUI), END );
  129. BABLM( BABL_PASTE , D(LGUI), T(V), U(LGUI), END );
  130. BABLM( BABL_SELECT_ALL , D(LGUI), T(A), U(LGUI), END );
  131. BABLM( BABL_FIND , D(LGUI),T(F), U(LGUI),END );
  132. BABLM( BABL_FIND_NEXT, D(LGUI),T(G), U(LGUI),END );
  133. BABLM( BABL_FIND_REPLACE, D(LGUI),T(F), U(LGUI),END );
  134. BABLM( BABL_RUNAPP , D(LGUI),T(R), U(LGUI),END );
  135. BABLM( BABL_SWITCH_APP_NEXT , D(LGUI),T(TAB), U(LGUI),END );
  136. BABLM( BABL_SWITCH_APP_LAST , D(LSFT),D(LGUI),T(TAB), U(LGUI), U(LSFT),END );
  137. BABLM( BABL_CLOSE_APP , D(LGUI),T(Q), U(LGUI),END );
  138. BABLM( BABL_HELP , D(LSFT),D(LGUI),T(SLASH), U(LGUI), U(LSFT),END );
  139. #endif
  140. return MACRO_NONE;
  141. #endif
  142. #ifdef EMACS_MODE
  143. case EMACS_MODE:
  144. switch(shortcut) {
  145. //probably should allow meta to not be ALT
  146. case BABL_DEL_RIGHT_1C:
  147. BABLM( , D(LCTL), T(D), U(LCTL),END );
  148. case BABL_DEL_LEFT_WORD:
  149. BABLM( , D(LCTL), T(BSPACE), U(LCTL), END );
  150. case BABL_DEL_RIGHT_WORD:
  151. BABLM( , D(LALT), T(D), U(LALT), END );
  152. case BABL_GO_LEFT_1C:
  153. BABLM( , T(LEFT), END );
  154. case BABL_GO_RIGHT_1C:
  155. BABLM( , T(RIGHT), END );
  156. case BABL_GO_LEFT_WORD:
  157. BABLM( , D(LALT), T(B), U(LALT), END );
  158. case BABL_GO_RIGHT_WORD:
  159. BABLM( , D(LALT), T(F), U(LALT), END );
  160. case BABL_GO_START_LINE:
  161. BABLM( , D(LCTRL), T(A), U(LCTRL), END );
  162. case BABL_GO_START_DOC:
  163. BABLM( , D(LALT), D(LSFT), T(COMM),U(LSFT), U(LALT) ,END );
  164. case BABL_GO_END_LINE:
  165. BABLM( , D(LCTRL), T(E), U(LCTRL), END );
  166. case BABL_GO_END_DOC:
  167. BABLM( , D(LALT), D(LSFT), T(DOT),U(LSFT), U(LALT) ,END );
  168. case BABL_GO_NEXT_LINE:
  169. BABLM( , D(LCTRL), T(N), U(LCTRL), END );
  170. case BABL_GO_PREV_LINE:
  171. BABLM( , D(LCTRL), T(P), U(LCTRL), END );
  172. case BABL_PGDN:
  173. BABLM( ,D(LCTRL), T(V), U(LCTRL), END );
  174. case BABL_PGUP:
  175. BABLM( , D(LALT), T(V), U(LALT), END );
  176. #ifndef BABL_MOVEMENTONLY
  177. case BABL_UNDO:
  178. BABLM( , D(LCTL), T(X), U(LCTL),T(C), END );
  179. case BABL_REDO:
  180. BABLM( , D(LCTL), T(X), U(LCTL),T(C), END ); // arguably
  181. case BABL_CUT:
  182. BABLM( , D(LCTL), T(W), U(LCTL), END );
  183. case BABL_COPY:
  184. BABLM( , D(LALT), T(W), U(LALT), END ); //really?
  185. case BABL_PASTE:
  186. BABLM( , D(LCTL), T(Y), U(LCTL), END );
  187. case BABL_SELECT_ALL:
  188. BABLM( ,D(LCTL), T(X), U(LCTL),T(H), END );
  189. case BABL_FIND:
  190. BABLM( , D(LCTRL), T(S), U(LCTRL),END );
  191. case BABL_FIND_NEXT:
  192. BABLM( , D(LCTRL), T(S), U(LCTRL),END );
  193. case BABL_FIND_REPLACE:
  194. BABLM( , D(LALT),D(LSFT), T(5),U(LSFT), U(LALT), END );
  195. case BABL_RUNAPP:
  196. BABLM( , D(LALT), T(X), U(LALT),T(S),T(H),T(E),T(L),T(L),END );// arguably
  197. case BABL_SWITCH_APP_NEXT:
  198. BABLM( , D(LCTL), T(X), U(LCTL),T(RIGHT), END ); // arguably
  199. case BABL_SWITCH_APP_LAST:
  200. BABLM( , D(LCTL), T(X), U(LCTL),T(LEFT), END ); // arguably
  201. case BABL_CLOSE_APP:
  202. BABLM( ,D(LCTL), T(X), U(LCTL),T(C),END );
  203. case BABL_HELP:
  204. BABLM( , D(LCTL),T(H), U(LCTL),T(A),END); // start search in help
  205. #endif
  206. break;
  207. return MACRO_NONE;
  208. }
  209. #endif
  210. #ifdef VI_MODE
  211. case VI_MODE:
  212. //assume esc is already called
  213. BABLM( BABL_DEL_RIGHT_1C , T(X),END );
  214. BABLM( BABL_DEL_LEFT_WORD , T(D),T(G),T(E),END );
  215. BABLM( BABL_DEL_RIGHT_WORD , T(D),T(W),END );
  216. BABLM( BABL_GO_LEFT_1C , T(H), END );
  217. BABLM( BABL_GO_RIGHT_1C , T(L), END );
  218. BABLM( BABL_GO_LEFT_WORD , T(B),END );
  219. BABLM( BABL_GO_RIGHT_WORD , T(W), END );
  220. BABLM( BABL_GO_START_LINE , D(LSFT), T(6),U(LSFT), END ); //^
  221. BABLM( BABL_GO_START_DOC , T(G),T(G) ,END );
  222. BABLM( BABL_GO_END_LINE , D(LSFT), T(4),U(LSFT) , END ); //$
  223. BABLM( BABL_GO_END_DOC , D(LSFT), T(G),U(LSFT),END );
  224. BABLM( BABL_GO_NEXT_LINE , T(J), END );
  225. BABLM( BABL_GO_PREV_LINE, T(K), END );
  226. BABLM( BABL_PGDN ,D(LCTRL), T(F), U(LCTRL), END );
  227. BABLM( BABL_PGUP , D(LCTRL), T(B), U(LCTRL), END );
  228. #ifndef BABL_MOVEMENTONLY
  229. BABLM( BABL_UNDO , T(U), END );
  230. BABLM( BABL_REDO , D(LCTL), T(R), U(LCTL), END );
  231. BABLM( BABL_CUT , T(X), END );
  232. BABLM( BABL_COPY , T(Y),END );
  233. BABLM( BABL_PASTE , T(P), END );
  234. BABLM( BABL_SELECT_ALL , D(LSFT), T(SCLN),U(LSFT),D(LSFT), T(5),U(LSFT),T(Y), END ); // wrong but helpful?
  235. BABLM( BABL_FIND , T(SLASH),END );
  236. BABLM( BABL_FIND_NEXT , T(N),END );
  237. BABLM( BABL_FIND_REPLACE , D(LALT),D(LSFT), T(5),U(LSFT), U(LALT), END );
  238. BABLM( BABL_RUNAPP,END );
  239. BABLM( BABL_SWITCH_APP_NEXT ,END );
  240. BABLM( BABL_SWITCH_APP_LAST ,END );
  241. BABLM(BABL_CLOSE_APP, D(LSFT), T(SCLN),U(LSFT), T(Q), D(RSFT), T(1),U(RSFT), END );
  242. BABLM(BABL_HELP, D(LSFT), T(SCLN),U(LSFT),T(H),END); // start search in help
  243. #endif
  244. return MACRO_NONE;
  245. #endif
  246. #ifdef READMUX_MODE
  247. // Readline command line editing + tmux windowing
  248. // I havent decided how much to do readline and how much tmux
  249. case READMUX_MODE:
  250. BABLM( BABL_DEL_RIGHT_1C , D(LCTL), T(D), U(LCTL),END );
  251. BABLM( BABL_DEL_LEFT_WORD , D(LCTL), T(W), U(LCTL), END );
  252. BABLM( BABL_DEL_RIGHT_WORD , D(LALT), T(D), U(LALT), END );
  253. BABLM( BABL_GO_LEFT_1C , T(LEFT), END );
  254. BABLM( BABL_GO_RIGHT_1C , T(RIGHT), END );
  255. BABLM( BABL_GO_LEFT_WORD , D(LALT), T(B), U(LALT), END );
  256. BABLM( BABL_GO_RIGHT_WORD , D(LALT), T(F), U(LALT), END );
  257. BABLM( BABL_GO_START_LINE , D(LCTRL), T(A), U(LCTRL), END );
  258. BABLM( BABL_GO_START_DOC ,END );// tmux?
  259. BABLM( BABL_GO_END_LINE , D(LCTRL), T(E), U(LCTRL), END );
  260. BABLM( BABL_GO_END_DOC ,END ); // tmux?
  261. BABLM( BABL_GO_NEXT_LINE , D(LCTRL), T(N), U(LCTRL), END );
  262. BABLM( BABL_GO_PREV_LINE , D(LCTRL), T(P), U(LCTRL), END );
  263. BABLM( BABL_PGDN , T(PGDN), END );
  264. BABLM( BABL_PGUP , T(PGUP), END );
  265. #ifndef BABL_MOVEMENTONLY
  266. BABLM( BABL_UNDO , D(LALT), T(R), U(LALT) , END );
  267. BABLM( BABL_REDO , D(LCTL), T(X), U(LCTL),T(C), END ); // arguably
  268. BABLM( BABL_CUT , D(LCTL), T(K), U(LCTL), END ); // wrong half the time
  269. BABLM( BABL_COPY ,END );
  270. BABLM( BABL_PASTE , D(LCTL), T(Y), U(LCTL), END );
  271. BABLM( BABL_SELECT_ALL ,D(LCTL), T(A), T(K), T(Y), U(LCTL) , END );
  272. BABLM( BABL_FIND , D(LCTRL), T(R), U(LCTRL), END ); // search history
  273. BABLM(BABL_FIND_NEXT, D(LCTRL), T(S), U(LCTRL), END );
  274. BABLM( BABL_FIND_REPLACE ,END );
  275. BABLM( BABL_RUNAPP , D(LCTRL), T(B), U(LCTRL), T(C),END ); //tmux
  276. BABLM( BABL_SWITCH_APP_NEXT , D(LCTRL), T(B), U(LCTRL), T(N),END ); //tmux
  277. BABLM( BABL_SWITCH_APP_LAST , D(LCTRL), T(B), U(LCTRL), T(P),END ); //tmux
  278. BABLM( BABL_CLOSE_APP , D(LCTRL), T(B), U(LCTRL), T(D),END); // usually what I want
  279. BABLM( BABL_HELP ,END );
  280. #endif
  281. return MACRO_NONE;
  282. #endif
  283. default:
  284. return MACRO_NONE;
  285. }
  286. }
  287. #endif