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