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