[119] | 1 | /* $Id: kkeys.e 3555 2022-02-16 13:20:30Z 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
|
---|
[3555] | 48 | def 'S- ' = kkey_space;
|
---|
[114] | 49 | def 'C-UP' = kkeys_scroll_down
|
---|
| 50 | def 'C-DOWN' = kkeys_scroll_up
|
---|
[134] | 51 | def 'C-PGUP' = prev_window
|
---|
| 52 | def 'C-PGDN' = next_window
|
---|
[118] | 53 | def 'C-DEL' = kkeys_delete_right
|
---|
[2428] | 54 | #if __VERSION__ >= 15.0
|
---|
| 55 | def 'S-C-=' = svn_diff_with_base
|
---|
| 56 | #endif
|
---|
[3146] | 57 | #if __VERSION__ >= 22.0
|
---|
| 58 | def 'C-=' = diff;
|
---|
| 59 | def 'C--' = nil;
|
---|
| 60 | def 'S-A-C-=' = wfont_zoom_in;
|
---|
| 61 | def 'S-A-C--' = wfont_zoom_out;
|
---|
| 62 | #endif
|
---|
[2353] | 63 | #if __VERSION__ >= 14.0
|
---|
[2407] | 64 | def 'C-/' = kkeys_push_ref
|
---|
| 65 | def 'S-C-/' = push_ref
|
---|
[2353] | 66 | def 'S-A-]' = next_buff_tab
|
---|
| 67 | def 'S-A-[' = prev_buff_tab
|
---|
[2388] | 68 | def 'S-A-U' = kkeys_gen_uuid
|
---|
[2353] | 69 | #endif
|
---|
[1590] | 70 | /* For the mac (A/M mix, all except A-z): */
|
---|
[2412] | 71 | def 'M-1' = cursor_error
|
---|
[1590] | 72 | def 'M-UP' = find_prev
|
---|
| 73 | def 'M-DOWN' = find_next
|
---|
| 74 | def 'M-PGUP' = prev_proc
|
---|
| 75 | def 'M-PGDN' = next_proc
|
---|
| 76 | def 'M-d' = delete_line
|
---|
[2400] | 77 | def 'M-f' = kkeys_open_file_menu
|
---|
| 78 | def 'M-e' = kkeys_open_edit_menu
|
---|
[1590] | 79 | def 'M-o' = kkeys_duplicate_line
|
---|
| 80 | def 'M-s' = kkeys_switch_lines
|
---|
[2400] | 81 | def 'M-t' = kkeys_open_tools_menu
|
---|
[1590] | 82 | def 'M-u' = undo_cursor
|
---|
| 83 | def 'M-g' = goto_line
|
---|
[2353] | 84 | #if __VERSION__ >= 14.0
|
---|
| 85 | def 'S-M-]' = next_buff_tab
|
---|
| 86 | def 'S-M-[' = prev_buff_tab
|
---|
[2388] | 87 | def 'S-M-U' = kkeys_gen_uuid
|
---|
[2353] | 88 | #endif
|
---|
[3146] | 89 | #if __VERSION__ >= 22.0
|
---|
| 90 | def 'S-M-C-=' = wfont_zoom_in;
|
---|
| 91 | def 'S-M-C--' = wfont_zoom_out;
|
---|
| 92 | #endif
|
---|
[1590] | 93 | /* Fixing brainfucked slickedit silliness: */
|
---|
| 94 | def 'M-v' = paste
|
---|
[114] | 95 |
|
---|
[3555] | 96 | /* Want proper shift-space in C. */
|
---|
| 97 | defeventtab c_keys
|
---|
| 98 | def 'S- ' = kkey_space;
|
---|
[2388] | 99 |
|
---|
[3555] | 100 |
|
---|
[2388] | 101 | /** Saves the cursor position. */
|
---|
| 102 | static long kkeys_save_cur_pos()
|
---|
| 103 | {
|
---|
| 104 | long offset = _QROffset();
|
---|
| 105 | message(offset);
|
---|
| 106 | return offset;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | /** Restores a saved cursor position. */
|
---|
| 110 | static void kkeys_restore_cur_pos(long lSavedCurPos)
|
---|
| 111 | {
|
---|
| 112 | _GoToROffset(lSavedCurPos);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[3555] | 115 | /** Fixes shift-space while in block select, default slickedit since a while
|
---|
| 116 | * is to exit selection mode and insert a single space. A long long time
|
---|
| 117 | * ago, I think slickedit would ask if you wanted the normal 'space'
|
---|
| 118 | * behaviour for this. */
|
---|
| 119 | _command void kkey_space()
|
---|
| 120 | {
|
---|
| 121 | /** @todo figure out when these functions were added and such. */
|
---|
| 122 | if (!select_active() || _select_type('') != 'BLOCK')
|
---|
| 123 | keyin(' ');
|
---|
| 124 | else
|
---|
| 125 | block_insert_text(' ');
|
---|
| 126 | }
|
---|
[2388] | 127 |
|
---|
[561] | 128 | _command kkeys_switch_lines()
|
---|
[114] | 129 | {
|
---|
| 130 | /* Allocate a selection for copying the current line. */
|
---|
| 131 | cursor_down();
|
---|
| 132 | mark_id= _alloc_selection();
|
---|
| 133 | if (mark_id>=0)
|
---|
| 134 | {
|
---|
| 135 | _select_line(mark_id);
|
---|
| 136 | cursor_up();
|
---|
| 137 | cursor_up();
|
---|
| 138 | _move_to_cursor(mark_id);
|
---|
| 139 | cursor_down();
|
---|
| 140 | _free_selection(mark_id);
|
---|
| 141 | // This selection can be freed because it is not the active selection.
|
---|
| 142 | }
|
---|
| 143 | else
|
---|
| 144 | message(get_message(mark_id));
|
---|
| 145 | }
|
---|
| 146 |
|
---|
[561] | 147 | _command kkeys_duplicate_line()
|
---|
[114] | 148 | {
|
---|
| 149 | /* Allocate a selection for copying the current line. */
|
---|
| 150 | mark_id= _alloc_selection();
|
---|
| 151 | if (mark_id>=0)
|
---|
| 152 | {
|
---|
| 153 | _select_line(mark_id);
|
---|
| 154 | _copy_to_cursor(mark_id);
|
---|
| 155 | // This selection can be freed because it is not the active selection.
|
---|
| 156 | _free_selection(mark_id);
|
---|
| 157 | cursor_down();
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | message(get_message(mark_id));
|
---|
| 161 | }
|
---|
| 162 |
|
---|
[561] | 163 | _command kkeys_delete_right()
|
---|
[114] | 164 | {
|
---|
[2437] | 165 | col=p_col;
|
---|
| 166 |
|
---|
[2558] | 167 | /* virtual space hack */
|
---|
[2437] | 168 | keyin(" ");
|
---|
| 169 | left();
|
---|
| 170 | _delete_char();
|
---|
| 171 |
|
---|
| 172 | /* are we in a word, delete it? */
|
---|
| 173 | ch = get_text();
|
---|
| 174 | if (ch != ' ' && ch != "\t" && ch != "\r" && ch != "\n")
|
---|
[2558] | 175 | {
|
---|
[3498] | 176 | /* Delete word and any trailing spaces, but stop at new line.
|
---|
| 177 | (Don't use delete_word here!) */
|
---|
[3499] | 178 | if (search('([[:alnum:]_]#|?)[ \t]@','r+') == 0)
|
---|
[2558] | 179 | {
|
---|
[3498] | 180 | _nrseek(match_length('s'));
|
---|
| 181 | _delete_text(match_length());
|
---|
[2558] | 182 | }
|
---|
| 183 | }
|
---|
| 184 | else
|
---|
[114] | 185 | {
|
---|
[2558] | 186 | /* delete spaces and newlines until the next word. */
|
---|
[2437] | 187 | if (search('[ \t\n\r]#','r+') == 0)
|
---|
| 188 | {
|
---|
| 189 | _nrseek(match_length('s'));
|
---|
| 190 | _delete_text(match_length());
|
---|
| 191 | }
|
---|
[114] | 192 | }
|
---|
[2437] | 193 |
|
---|
[114] | 194 | p_col=col
|
---|
| 195 | //retrieve_command_results()
|
---|
| 196 | }
|
---|
| 197 |
|
---|
[561] | 198 | _command kkeys_scroll_up()
|
---|
[114] | 199 | {
|
---|
| 200 | if (p_cursor_y == 0)
|
---|
| 201 | down();
|
---|
| 202 | set_scroll_pos(p_left_edge, p_cursor_y-1);
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[561] | 205 | _command kkeys_scroll_down()
|
---|
[114] | 206 | {
|
---|
| 207 | if (p_cursor_y intdiv p_font_height == p_char_height-1)
|
---|
| 208 | up()
|
---|
| 209 | set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[566] | 212 | _command boxer_paste()
|
---|
[114] | 213 | {
|
---|
[2388] | 214 | long lSavedCurPos = kkeys_save_cur_pos()
|
---|
| 215 | paste();
|
---|
| 216 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
[114] | 217 | }
|
---|
| 218 |
|
---|
[252] | 219 | _command kkeys_fullscreen()
|
---|
| 220 | {
|
---|
| 221 | fullscreen();
|
---|
| 222 | }
|
---|
| 223 |
|
---|
| 224 |
|
---|
| 225 | /* for later, not used yet. */
|
---|
| 226 |
|
---|
[114] | 227 | _command boxer_select()
|
---|
| 228 | {
|
---|
| 229 | if (command_state())
|
---|
| 230 | fSelected = (p_sel_length != 0);
|
---|
| 231 | else
|
---|
| 232 | fSelected = select_active();
|
---|
| 233 |
|
---|
| 234 | key = last_event();
|
---|
| 235 | if (key :== name2event('s-down'))
|
---|
| 236 | {
|
---|
| 237 | if (!fSelected)
|
---|
| 238 | select_line();
|
---|
| 239 | else
|
---|
| 240 | cursor_down();
|
---|
| 241 | }
|
---|
| 242 | else if (key :== name2event('s-up'))
|
---|
| 243 | {
|
---|
| 244 | if (!fSelected)
|
---|
| 245 | select_line();
|
---|
| 246 | else
|
---|
| 247 | cursor_up();
|
---|
| 248 | }
|
---|
| 249 | else if (key :== name2event('s-left'))
|
---|
| 250 | {
|
---|
| 251 | if (!fSelected)
|
---|
| 252 | select_char();
|
---|
| 253 | else
|
---|
| 254 | cursor_left();
|
---|
| 255 | }
|
---|
| 256 | else if (key :== name2event('s-right'))
|
---|
| 257 | {
|
---|
| 258 | if (!fSelected)
|
---|
| 259 | select_char();
|
---|
| 260 | else
|
---|
| 261 | cursor_right();
|
---|
| 262 | }
|
---|
| 263 | else if (key :== name2event('s-home'))
|
---|
| 264 | {
|
---|
| 265 | if (!fSelected) select_char();
|
---|
| 266 | begin_line_text_toggle();
|
---|
| 267 | }
|
---|
| 268 | else if (key :== name2event('s-end'))
|
---|
| 269 | {
|
---|
| 270 | if (!fSelected) select_char();
|
---|
| 271 | end_line();
|
---|
| 272 | if (p_col > 0) //this is not identical with boxer...
|
---|
| 273 | cursor_left();
|
---|
| 274 | }
|
---|
| 275 | else if (key :== name2event('c-s-home'))
|
---|
| 276 | {
|
---|
| 277 | if (!fSelected) select_char();
|
---|
| 278 | top_of_buffer();
|
---|
| 279 | }
|
---|
| 280 | else if (key :== name2event('c-s-end'))
|
---|
| 281 | {
|
---|
| 282 | if (!fSelected) select_char();
|
---|
| 283 | bottom_of_buffer();
|
---|
| 284 | }
|
---|
| 285 | else if (key :== name2event('c-s-left'))
|
---|
| 286 | {
|
---|
| 287 | if (!fSelected)
|
---|
| 288 | {
|
---|
| 289 | cursor_left();
|
---|
| 290 | select_char(); /* start this selection non-inclusive */
|
---|
| 291 | }
|
---|
| 292 | prev_word();
|
---|
| 293 | }
|
---|
| 294 | else if (key :== name2event('c-s-right'))
|
---|
| 295 | {
|
---|
| 296 | if (!fSelected)
|
---|
| 297 | {
|
---|
| 298 | select_char(); /* start this selection non-inclusive */
|
---|
| 299 | }
|
---|
| 300 | /* temporary hack */
|
---|
| 301 | prevpos = p_col;
|
---|
| 302 | prevline = p_line;
|
---|
| 303 | p_col++;
|
---|
| 304 | next_word();
|
---|
| 305 | if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
|
---|
| 306 | p_col--;
|
---|
| 307 | }
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[2407] | 310 | #if __VERSION__ >= 14.0
|
---|
[114] | 311 |
|
---|
[2407] | 312 | /**
|
---|
| 313 | * Search for references only in the current workspace.
|
---|
| 314 | */
|
---|
| 315 | _command kkeys_push_ref()
|
---|
| 316 | {
|
---|
| 317 | if (_isEditorCtl())
|
---|
| 318 | {
|
---|
| 319 | sProjTagFile = project_tags_filename();
|
---|
| 320 | sLangId = p_LangId;
|
---|
| 321 | if (sProjTagFile != '')
|
---|
| 322 | {
|
---|
| 323 |
|
---|
[3015] | 324 | # if __VERSION__ < 21.0 /** @todo fix me? */
|
---|
[2407] | 325 | /* HACK ALERT: Make sure gtag_filelist_last_ext has the right value. */
|
---|
| 326 | _update_tag_filelist_ext(sLangId);
|
---|
| 327 |
|
---|
| 328 | /* save */
|
---|
| 329 | boolean saved_gtag_filelist_cache_updated = gtag_filelist_cache_updated;
|
---|
| 330 | _str saved_gtag_filelist_ext[] = gtag_filelist_ext;
|
---|
| 331 |
|
---|
| 332 | /* HACK ALERT: Replace the tag file list for this language. */
|
---|
| 333 | gtag_filelist_ext._makeempty();
|
---|
| 334 | gtag_filelist_ext[0] = sProjTagFile;
|
---|
[3015] | 335 | gtag_filelist_cache_updated = true;
|
---|
| 336 | # endif
|
---|
[2407] | 337 |
|
---|
| 338 | /* Do the reference searching. */
|
---|
| 339 | push_ref('-e ' :+ sLangId);
|
---|
| 340 |
|
---|
[3015] | 341 | # if __VERSION__ < 21.0
|
---|
[2407] | 342 | /* restore*/
|
---|
| 343 | gtag_filelist_cache_updated = saved_gtag_filelist_cache_updated;
|
---|
| 344 | gtag_filelist_ext = saved_gtag_filelist_ext;
|
---|
[3015] | 345 | # endif
|
---|
[2407] | 346 | }
|
---|
| 347 | else
|
---|
| 348 | push_ref();
|
---|
| 349 | }
|
---|
| 350 | else
|
---|
| 351 | push_ref();
|
---|
| 352 | }
|
---|
| 353 |
|
---|
| 354 |
|
---|
[2388] | 355 | _command kkeys_gen_uuid()
|
---|
| 356 | {
|
---|
| 357 | _str uuid = guid_create_string('G');
|
---|
| 358 | uuid = lowcase(uuid);
|
---|
| 359 |
|
---|
| 360 | long lSavedCurPos = kkeys_save_cur_pos();
|
---|
| 361 | _insert_text(uuid);
|
---|
| 362 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
| 363 | }
|
---|
| 364 |
|
---|
[2407] | 365 | #endif /* >= 14.0 */
|
---|
| 366 |
|
---|
[2400] | 367 | /** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
|
---|
| 368 | *
|
---|
| 369 | * This only works when the alt menu hotkeys are enabled in the
|
---|
| 370 | * settings. Al
|
---|
| 371 | *
|
---|
| 372 | * @{
|
---|
| 373 | */
|
---|
| 374 | _command void kkeys_open_file_menu()
|
---|
| 375 | {
|
---|
| 376 | call_key(A_F)
|
---|
| 377 | }
|
---|
[2388] | 378 |
|
---|
[2400] | 379 | _command void kkeys_open_edit_menu()
|
---|
| 380 | {
|
---|
| 381 | call_key(A_E)
|
---|
| 382 | }
|
---|
| 383 |
|
---|
| 384 | _command void kkeys_open_tools_menu()
|
---|
| 385 | {
|
---|
| 386 | call_key(A_T)
|
---|
| 387 | }
|
---|
| 388 | /** @} */
|
---|
| 389 |
|
---|
[114] | 390 | void nop()
|
---|
| 391 | {
|
---|
| 392 |
|
---|
| 393 | }
|
---|
| 394 |
|
---|
[2411] | 395 |
|
---|
| 396 | #if __VERSION__ >= 14.0
|
---|
| 397 |
|
---|
| 398 | /*
|
---|
| 399 | * Some diff keyboard hacks for Mac OS X.
|
---|
| 400 | */
|
---|
| 401 | defeventtab _diff_form
|
---|
| 402 | def 'M-f' = kkeys_diffedit_find
|
---|
| 403 | def 'M-n' = kkeys_diffedit_next
|
---|
| 404 | def 'M-p' = kkeys_diffedit_prev
|
---|
| 405 |
|
---|
| 406 | _command kkeys_diffedit_find()
|
---|
| 407 | {
|
---|
| 408 | _nocheck _control _ctlfind;
|
---|
| 409 | _ctlfind.call_event(_ctlfind, LBUTTON_UP);
|
---|
| 410 | }
|
---|
| 411 |
|
---|
| 412 | _command kkeys_diffedit_next()
|
---|
| 413 | {
|
---|
| 414 | _nocheck _control _ctlfile1;
|
---|
| 415 | _nocheck _control _ctlfile2;
|
---|
| 416 | _DiffNextDifference(_ctlfile1, _ctlfile2);
|
---|
| 417 | }
|
---|
| 418 |
|
---|
| 419 | _command kkeys_diffedit_prev()
|
---|
| 420 | {
|
---|
| 421 | _nocheck _control _ctlfile1;
|
---|
| 422 | _nocheck _control _ctlfile2;
|
---|
| 423 | _DiffNextDifference(_ctlfile1, _ctlfile2, '-');
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | #endif /* >= 14.0 */
|
---|
| 427 |
|
---|