[119] | 1 | /* $Id: kkeys.e 2428 2010-11-16 14:47:04Z 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 | {
|
---|
| 138 | col=p_col
|
---|
| 139 | search('[ \t]#|?|$|^','r+');
|
---|
| 140 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 141 | {
|
---|
| 142 | _nrseek(match_length('s'));
|
---|
| 143 | _delete_text(match_length());
|
---|
| 144 | }
|
---|
| 145 | else
|
---|
| 146 | delete_word();
|
---|
| 147 | p_col=col
|
---|
| 148 | //retrieve_command_results()
|
---|
| 149 |
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[561] | 152 | _command kkeys_delete_left()
|
---|
[114] | 153 | {
|
---|
| 154 | //denne virker ikkje som den skal!!!
|
---|
| 155 | message "not implemented"
|
---|
[561] | 156 | /*
|
---|
[114] | 157 | return;
|
---|
| 158 | col=p_col
|
---|
| 159 | search('[ \t]#|?|$|^','r-');
|
---|
| 160 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 161 | {
|
---|
| 162 | _nrseek(match_length('s'));
|
---|
| 163 | _delete_text(match_length());
|
---|
| 164 | }
|
---|
| 165 | else
|
---|
| 166 | delete_word();
|
---|
| 167 | p_col=col
|
---|
[561] | 168 | */
|
---|
[114] | 169 | }
|
---|
| 170 |
|
---|
[561] | 171 | _command kkeys_scroll_up()
|
---|
[114] | 172 | {
|
---|
| 173 | if (p_cursor_y == 0)
|
---|
| 174 | down();
|
---|
| 175 | set_scroll_pos(p_left_edge, p_cursor_y-1);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
[561] | 178 | _command kkeys_scroll_down()
|
---|
[114] | 179 | {
|
---|
| 180 | if (p_cursor_y intdiv p_font_height == p_char_height-1)
|
---|
| 181 | up()
|
---|
| 182 | set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[566] | 185 | _command boxer_paste()
|
---|
[114] | 186 | {
|
---|
[2388] | 187 | long lSavedCurPos = kkeys_save_cur_pos()
|
---|
| 188 | paste();
|
---|
| 189 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
[114] | 190 | }
|
---|
| 191 |
|
---|
[252] | 192 | _command kkeys_fullscreen()
|
---|
| 193 | {
|
---|
| 194 | fullscreen();
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | /* for later, not used yet. */
|
---|
| 199 |
|
---|
[114] | 200 | _command boxer_select()
|
---|
| 201 | {
|
---|
| 202 | if (command_state())
|
---|
| 203 | fSelected = (p_sel_length != 0);
|
---|
| 204 | else
|
---|
| 205 | fSelected = select_active();
|
---|
| 206 |
|
---|
| 207 | key = last_event();
|
---|
| 208 | if (key :== name2event('s-down'))
|
---|
| 209 | {
|
---|
| 210 | if (!fSelected)
|
---|
| 211 | select_line();
|
---|
| 212 | else
|
---|
| 213 | cursor_down();
|
---|
| 214 | }
|
---|
| 215 | else if (key :== name2event('s-up'))
|
---|
| 216 | {
|
---|
| 217 | if (!fSelected)
|
---|
| 218 | select_line();
|
---|
| 219 | else
|
---|
| 220 | cursor_up();
|
---|
| 221 | }
|
---|
| 222 | else if (key :== name2event('s-left'))
|
---|
| 223 | {
|
---|
| 224 | if (!fSelected)
|
---|
| 225 | select_char();
|
---|
| 226 | else
|
---|
| 227 | cursor_left();
|
---|
| 228 | }
|
---|
| 229 | else if (key :== name2event('s-right'))
|
---|
| 230 | {
|
---|
| 231 | if (!fSelected)
|
---|
| 232 | select_char();
|
---|
| 233 | else
|
---|
| 234 | cursor_right();
|
---|
| 235 | }
|
---|
| 236 | else if (key :== name2event('s-home'))
|
---|
| 237 | {
|
---|
| 238 | if (!fSelected) select_char();
|
---|
| 239 | begin_line_text_toggle();
|
---|
| 240 | }
|
---|
| 241 | else if (key :== name2event('s-end'))
|
---|
| 242 | {
|
---|
| 243 | if (!fSelected) select_char();
|
---|
| 244 | end_line();
|
---|
| 245 | if (p_col > 0) //this is not identical with boxer...
|
---|
| 246 | cursor_left();
|
---|
| 247 | }
|
---|
| 248 | else if (key :== name2event('c-s-home'))
|
---|
| 249 | {
|
---|
| 250 | if (!fSelected) select_char();
|
---|
| 251 | top_of_buffer();
|
---|
| 252 | }
|
---|
| 253 | else if (key :== name2event('c-s-end'))
|
---|
| 254 | {
|
---|
| 255 | if (!fSelected) select_char();
|
---|
| 256 | bottom_of_buffer();
|
---|
| 257 | }
|
---|
| 258 | else if (key :== name2event('c-s-left'))
|
---|
| 259 | {
|
---|
| 260 | if (!fSelected)
|
---|
| 261 | {
|
---|
| 262 | cursor_left();
|
---|
| 263 | select_char(); /* start this selection non-inclusive */
|
---|
| 264 | }
|
---|
| 265 | prev_word();
|
---|
| 266 | }
|
---|
| 267 | else if (key :== name2event('c-s-right'))
|
---|
| 268 | {
|
---|
| 269 | if (!fSelected)
|
---|
| 270 | {
|
---|
| 271 | select_char(); /* start this selection non-inclusive */
|
---|
| 272 | }
|
---|
| 273 | /* temporary hack */
|
---|
| 274 | prevpos = p_col;
|
---|
| 275 | prevline = p_line;
|
---|
| 276 | p_col++;
|
---|
| 277 | next_word();
|
---|
| 278 | if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
|
---|
| 279 | p_col--;
|
---|
| 280 | }
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[2407] | 283 | #if __VERSION__ >= 14.0
|
---|
[114] | 284 |
|
---|
[2407] | 285 | /**
|
---|
| 286 | * Search for references only in the current workspace.
|
---|
| 287 | */
|
---|
| 288 | _command kkeys_push_ref()
|
---|
| 289 | {
|
---|
| 290 | if (_isEditorCtl())
|
---|
| 291 | {
|
---|
| 292 | sProjTagFile = project_tags_filename();
|
---|
| 293 | sLangId = p_LangId;
|
---|
| 294 | if (sProjTagFile != '')
|
---|
| 295 | {
|
---|
| 296 |
|
---|
| 297 | /* HACK ALERT: Make sure gtag_filelist_last_ext has the right value. */
|
---|
| 298 | _update_tag_filelist_ext(sLangId);
|
---|
| 299 |
|
---|
| 300 | /* save */
|
---|
| 301 | boolean saved_gtag_filelist_cache_updated = gtag_filelist_cache_updated;
|
---|
| 302 | _str saved_gtag_filelist_ext[] = gtag_filelist_ext;
|
---|
| 303 |
|
---|
| 304 | /* HACK ALERT: Replace the tag file list for this language. */
|
---|
| 305 | gtag_filelist_ext._makeempty();
|
---|
| 306 | gtag_filelist_ext[0] = sProjTagFile;
|
---|
| 307 | saved_gtag_filelist_cache_updated = true;
|
---|
| 308 |
|
---|
| 309 | /* Do the reference searching. */
|
---|
| 310 | push_ref('-e ' :+ sLangId);
|
---|
| 311 |
|
---|
| 312 | /* restore*/
|
---|
| 313 | gtag_filelist_cache_updated = saved_gtag_filelist_cache_updated;
|
---|
| 314 | gtag_filelist_ext = saved_gtag_filelist_ext;
|
---|
| 315 | }
|
---|
| 316 | else
|
---|
| 317 | push_ref();
|
---|
| 318 | }
|
---|
| 319 | else
|
---|
| 320 | push_ref();
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 |
|
---|
[2388] | 324 | _command kkeys_gen_uuid()
|
---|
| 325 | {
|
---|
| 326 | _str uuid = guid_create_string('G');
|
---|
| 327 | uuid = lowcase(uuid);
|
---|
| 328 |
|
---|
| 329 | long lSavedCurPos = kkeys_save_cur_pos();
|
---|
| 330 | _insert_text(uuid);
|
---|
| 331 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
| 332 | }
|
---|
| 333 |
|
---|
[2407] | 334 | #endif /* >= 14.0 */
|
---|
| 335 |
|
---|
[2400] | 336 | /** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
|
---|
| 337 | *
|
---|
| 338 | * This only works when the alt menu hotkeys are enabled in the
|
---|
| 339 | * settings. Al
|
---|
| 340 | *
|
---|
| 341 | * @{
|
---|
| 342 | */
|
---|
| 343 | _command void kkeys_open_file_menu()
|
---|
| 344 | {
|
---|
| 345 | call_key(A_F)
|
---|
| 346 | }
|
---|
[2388] | 347 |
|
---|
[2400] | 348 | _command void kkeys_open_edit_menu()
|
---|
| 349 | {
|
---|
| 350 | call_key(A_E)
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | _command void kkeys_open_tools_menu()
|
---|
| 354 | {
|
---|
| 355 | call_key(A_T)
|
---|
| 356 | }
|
---|
| 357 | /** @} */
|
---|
| 358 |
|
---|
[114] | 359 | void nop()
|
---|
| 360 | {
|
---|
| 361 |
|
---|
| 362 | }
|
---|
| 363 |
|
---|
[2411] | 364 |
|
---|
| 365 | #if __VERSION__ >= 14.0
|
---|
| 366 |
|
---|
| 367 | /*
|
---|
| 368 | * Some diff keyboard hacks for Mac OS X.
|
---|
| 369 | */
|
---|
| 370 | defeventtab _diff_form
|
---|
| 371 | def 'M-f' = kkeys_diffedit_find
|
---|
| 372 | def 'M-n' = kkeys_diffedit_next
|
---|
| 373 | def 'M-p' = kkeys_diffedit_prev
|
---|
| 374 |
|
---|
| 375 | _command kkeys_diffedit_find()
|
---|
| 376 | {
|
---|
| 377 | _nocheck _control _ctlfind;
|
---|
| 378 | _ctlfind.call_event(_ctlfind, LBUTTON_UP);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | _command kkeys_diffedit_next()
|
---|
| 382 | {
|
---|
| 383 | _nocheck _control _ctlfile1;
|
---|
| 384 | _nocheck _control _ctlfile2;
|
---|
| 385 | _DiffNextDifference(_ctlfile1, _ctlfile2);
|
---|
| 386 | }
|
---|
| 387 |
|
---|
| 388 | _command kkeys_diffedit_prev()
|
---|
| 389 | {
|
---|
| 390 | _nocheck _control _ctlfile1;
|
---|
| 391 | _nocheck _control _ctlfile2;
|
---|
| 392 | _DiffNextDifference(_ctlfile1, _ctlfile2, '-');
|
---|
| 393 | }
|
---|
| 394 |
|
---|
| 395 | #endif /* >= 14.0 */
|
---|
| 396 |
|
---|