PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/kBuild/VSlickMacros/kkeys.e

#
Specman e | 409 lines | 357 code | 48 blank | 4 comment | 73 complexity | 652be44c7c246a56c53281ffb23fa358 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-3.0, ISC, GPL-2.0, CC-BY-SA-4.0, LGPL-2.0
  1. /* $Id: kkeys.e 2437 2011-03-28 19:17:08Z bird $ */
  2. /** @file
  3. * Bird's key additions to Visual Slickedit.
  4. */
  5. /*
  6. * Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
  7. *
  8. * This file is part of kBuild.
  9. *
  10. * kBuild is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * kBuild is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with kBuild. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. /*******************************************************************************
  25. * Header Files *
  26. *******************************************************************************/
  27. #include 'slick.sh'
  28. /*******************************************************************************
  29. * Global Variables *
  30. *******************************************************************************/
  31. defeventtab default_keys
  32. def 'A-UP' = find_prev
  33. def 'A-DOWN' = find_next
  34. def 'A-PGUP' = prev_proc
  35. def 'A-PGDN' = next_proc
  36. def 'A-d' = delete_line
  37. def 'A-o' = kkeys_duplicate_line
  38. def 'A-s' = kkeys_switch_lines
  39. def 'A-u' = undo_cursor /* will cursor movement in one undo step. */
  40. def 'A-g' = goto_line
  41. def 'A-z' = kkeys_fullscreen
  42. def 'INS' = boxer_paste
  43. def 'S-INS' = insert_toggle
  44. def 'C-UP' = kkeys_scroll_down
  45. def 'C-DOWN' = kkeys_scroll_up
  46. def 'C-PGUP' = prev_window
  47. def 'C-PGDN' = next_window
  48. def 'C-DEL' = kkeys_delete_right
  49. #if __VERSION__ >= 15.0
  50. def 'S-C-=' = svn_diff_with_base
  51. #endif
  52. #if __VERSION__ >= 14.0
  53. def 'C-/' = kkeys_push_ref
  54. def 'S-C-/' = push_ref
  55. def 'S-A-]' = next_buff_tab
  56. def 'S-A-[' = prev_buff_tab
  57. def 'S-A-U' = kkeys_gen_uuid
  58. #endif
  59. /* For the mac (A/M mix, all except A-z): */
  60. def 'M-1' = cursor_error
  61. def 'M-UP' = find_prev
  62. def 'M-DOWN' = find_next
  63. def 'M-PGUP' = prev_proc
  64. def 'M-PGDN' = next_proc
  65. def 'M-d' = delete_line
  66. def 'M-f' = kkeys_open_file_menu
  67. def 'M-e' = kkeys_open_edit_menu
  68. def 'M-o' = kkeys_duplicate_line
  69. def 'M-s' = kkeys_switch_lines
  70. def 'M-t' = kkeys_open_tools_menu
  71. def 'M-u' = undo_cursor
  72. def 'M-g' = goto_line
  73. #if __VERSION__ >= 14.0
  74. def 'S-M-]' = next_buff_tab
  75. def 'S-M-[' = prev_buff_tab
  76. def 'S-M-U' = kkeys_gen_uuid
  77. #endif
  78. /* Fixing brainfucked slickedit silliness: */
  79. def 'M-v' = paste
  80. /** Saves the cursor position. */
  81. static long kkeys_save_cur_pos()
  82. {
  83. long offset = _QROffset();
  84. message(offset);
  85. return offset;
  86. }
  87. /** Restores a saved cursor position. */
  88. static void kkeys_restore_cur_pos(long lSavedCurPos)
  89. {
  90. _GoToROffset(lSavedCurPos);
  91. }
  92. _command kkeys_switch_lines()
  93. {
  94. /* Allocate a selection for copying the current line. */
  95. cursor_down();
  96. mark_id= _alloc_selection();
  97. if (mark_id>=0)
  98. {
  99. _select_line(mark_id);
  100. cursor_up();
  101. cursor_up();
  102. _move_to_cursor(mark_id);
  103. cursor_down();
  104. _free_selection(mark_id);
  105. // This selection can be freed because it is not the active selection.
  106. }
  107. else
  108. message(get_message(mark_id));
  109. }
  110. _command kkeys_duplicate_line()
  111. {
  112. /* Allocate a selection for copying the current line. */
  113. mark_id= _alloc_selection();
  114. if (mark_id>=0)
  115. {
  116. _select_line(mark_id);
  117. _copy_to_cursor(mark_id);
  118. // This selection can be freed because it is not the active selection.
  119. _free_selection(mark_id);
  120. cursor_down();
  121. }
  122. else
  123. message(get_message(mark_id));
  124. }
  125. _command kkeys_delete_right()
  126. {
  127. col=p_col;
  128. /* virtual space hack*/
  129. keyin(" ");
  130. left();
  131. _delete_char();
  132. /* are we in a word, delete it? */
  133. ch = get_text();
  134. if (ch != ' ' && ch != "\t" && ch != "\r" && ch != "\n")
  135. delete_word();
  136. /* delete spaces and newlines until the next word. */
  137. ch = get_text();
  138. if (ch == ' ' || ch == "\t" || ch == "\r" || ch == "\n")
  139. {
  140. if (search('[ \t\n\r]#','r+') == 0)
  141. {
  142. _nrseek(match_length('s'));
  143. _delete_text(match_length());
  144. }
  145. }
  146. p_col=col
  147. //retrieve_command_results()
  148. }
  149. _command kkeys_delete_left()
  150. {
  151. //denne virker ikkje som den skal!!!
  152. message "not implemented"
  153. /*
  154. return;
  155. col=p_col
  156. search('[ \t]#|?|$|^','r-');
  157. if ( match_length()&& get_text(1,match_length('s'))=='' )
  158. {
  159. _nrseek(match_length('s'));
  160. _delete_text(match_length());
  161. }
  162. else
  163. delete_word();
  164. p_col=col
  165. */
  166. }
  167. _command kkeys_scroll_up()
  168. {
  169. if (p_cursor_y == 0)
  170. down();
  171. set_scroll_pos(p_left_edge, p_cursor_y-1);
  172. }
  173. _command kkeys_scroll_down()
  174. {
  175. if (p_cursor_y intdiv p_font_height == p_char_height-1)
  176. up()
  177. set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
  178. }
  179. _command boxer_paste()
  180. {
  181. long lSavedCurPos = kkeys_save_cur_pos()
  182. paste();
  183. kkeys_restore_cur_pos(lSavedCurPos);
  184. }
  185. _command kkeys_fullscreen()
  186. {
  187. fullscreen();
  188. }
  189. /* for later, not used yet. */
  190. _command boxer_select()
  191. {
  192. if (command_state())
  193. fSelected = (p_sel_length != 0);
  194. else
  195. fSelected = select_active();
  196. key = last_event();
  197. if (key :== name2event('s-down'))
  198. {
  199. if (!fSelected)
  200. select_line();
  201. else
  202. cursor_down();
  203. }
  204. else if (key :== name2event('s-up'))
  205. {
  206. if (!fSelected)
  207. select_line();
  208. else
  209. cursor_up();
  210. }
  211. else if (key :== name2event('s-left'))
  212. {
  213. if (!fSelected)
  214. select_char();
  215. else
  216. cursor_left();
  217. }
  218. else if (key :== name2event('s-right'))
  219. {
  220. if (!fSelected)
  221. select_char();
  222. else
  223. cursor_right();
  224. }
  225. else if (key :== name2event('s-home'))
  226. {
  227. if (!fSelected) select_char();
  228. begin_line_text_toggle();
  229. }
  230. else if (key :== name2event('s-end'))
  231. {
  232. if (!fSelected) select_char();
  233. end_line();
  234. if (p_col > 0) //this is not identical with boxer...
  235. cursor_left();
  236. }
  237. else if (key :== name2event('c-s-home'))
  238. {
  239. if (!fSelected) select_char();
  240. top_of_buffer();
  241. }
  242. else if (key :== name2event('c-s-end'))
  243. {
  244. if (!fSelected) select_char();
  245. bottom_of_buffer();
  246. }
  247. else if (key :== name2event('c-s-left'))
  248. {
  249. if (!fSelected)
  250. {
  251. cursor_left();
  252. select_char(); /* start this selection non-inclusive */
  253. }
  254. prev_word();
  255. }
  256. else if (key :== name2event('c-s-right'))
  257. {
  258. if (!fSelected)
  259. {
  260. select_char(); /* start this selection non-inclusive */
  261. }
  262. /* temporary hack */
  263. prevpos = p_col;
  264. prevline = p_line;
  265. p_col++;
  266. next_word();
  267. if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
  268. p_col--;
  269. }
  270. }
  271. #if __VERSION__ >= 14.0
  272. /**
  273. * Search for references only in the current workspace.
  274. */
  275. _command kkeys_push_ref()
  276. {
  277. if (_isEditorCtl())
  278. {
  279. sProjTagFile = project_tags_filename();
  280. sLangId = p_LangId;
  281. if (sProjTagFile != '')
  282. {
  283. /* HACK ALERT: Make sure gtag_filelist_last_ext has the right value. */
  284. _update_tag_filelist_ext(sLangId);
  285. /* save */
  286. boolean saved_gtag_filelist_cache_updated = gtag_filelist_cache_updated;
  287. _str saved_gtag_filelist_ext[] = gtag_filelist_ext;
  288. /* HACK ALERT: Replace the tag file list for this language. */
  289. gtag_filelist_ext._makeempty();
  290. gtag_filelist_ext[0] = sProjTagFile;
  291. saved_gtag_filelist_cache_updated = true;
  292. /* Do the reference searching. */
  293. push_ref('-e ' :+ sLangId);
  294. /* restore*/
  295. gtag_filelist_cache_updated = saved_gtag_filelist_cache_updated;
  296. gtag_filelist_ext = saved_gtag_filelist_ext;
  297. }
  298. else
  299. push_ref();
  300. }
  301. else
  302. push_ref();
  303. }
  304. _command kkeys_gen_uuid()
  305. {
  306. _str uuid = guid_create_string('G');
  307. uuid = lowcase(uuid);
  308. long lSavedCurPos = kkeys_save_cur_pos();
  309. _insert_text(uuid);
  310. kkeys_restore_cur_pos(lSavedCurPos);
  311. }
  312. #endif /* >= 14.0 */
  313. /** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
  314. *
  315. * This only works when the alt menu hotkeys are enabled in the
  316. * settings. Al
  317. *
  318. * @{
  319. */
  320. _command void kkeys_open_file_menu()
  321. {
  322. call_key(A_F)
  323. }
  324. _command void kkeys_open_edit_menu()
  325. {
  326. call_key(A_E)
  327. }
  328. _command void kkeys_open_tools_menu()
  329. {
  330. call_key(A_T)
  331. }
  332. /** @} */
  333. void nop()
  334. {
  335. }
  336. #if __VERSION__ >= 14.0
  337. /*
  338. * Some diff keyboard hacks for Mac OS X.
  339. */
  340. defeventtab _diff_form
  341. def 'M-f' = kkeys_diffedit_find
  342. def 'M-n' = kkeys_diffedit_next
  343. def 'M-p' = kkeys_diffedit_prev
  344. _command kkeys_diffedit_find()
  345. {
  346. _nocheck _control _ctlfind;
  347. _ctlfind.call_event(_ctlfind, LBUTTON_UP);
  348. }
  349. _command kkeys_diffedit_next()
  350. {
  351. _nocheck _control _ctlfile1;
  352. _nocheck _control _ctlfile2;
  353. _DiffNextDifference(_ctlfile1, _ctlfile2);
  354. }
  355. _command kkeys_diffedit_prev()
  356. {
  357. _nocheck _control _ctlfile1;
  358. _nocheck _control _ctlfile2;
  359. _DiffNextDifference(_ctlfile1, _ctlfile2, '-');
  360. }
  361. #endif /* >= 14.0 */