[119] | 1 | /* $Id: kkeys.e 2400 2010-03-07 14:08:52Z bird $ */
|
---|
| 2 | /** @file
|
---|
[1590] | 3 | * Bird's key additions to Visual Slickedit.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[2243] | 7 | * Copyright (c) 2004-2009 knut st. osmundsen <bird-kBuild-spamix@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
|
---|
[2353] | 53 | #if __VERSION__ >= 14.0
|
---|
| 54 | def 'S-A-]' = next_buff_tab
|
---|
| 55 | def 'S-A-[' = prev_buff_tab
|
---|
[2388] | 56 | def 'S-A-U' = kkeys_gen_uuid
|
---|
[2353] | 57 | #endif
|
---|
[1590] | 58 | /* For the mac (A/M mix, all except A-z): */
|
---|
| 59 | def 'M-UP' = find_prev
|
---|
| 60 | def 'M-DOWN' = find_next
|
---|
| 61 | def 'M-PGUP' = prev_proc
|
---|
| 62 | def 'M-PGDN' = next_proc
|
---|
| 63 | def 'M-d' = delete_line
|
---|
[2400] | 64 | def 'M-f' = kkeys_open_file_menu
|
---|
| 65 | def 'M-e' = kkeys_open_edit_menu
|
---|
[1590] | 66 | def 'M-o' = kkeys_duplicate_line
|
---|
| 67 | def 'M-s' = kkeys_switch_lines
|
---|
[2400] | 68 | def 'M-t' = kkeys_open_tools_menu
|
---|
[1590] | 69 | def 'M-u' = undo_cursor
|
---|
| 70 | def 'M-g' = goto_line
|
---|
[2353] | 71 | #if __VERSION__ >= 14.0
|
---|
| 72 | def 'S-M-]' = next_buff_tab
|
---|
| 73 | def 'S-M-[' = prev_buff_tab
|
---|
[2388] | 74 | def 'S-M-U' = kkeys_gen_uuid
|
---|
[2353] | 75 | #endif
|
---|
[1590] | 76 | /* Fixing brainfucked slickedit silliness: */
|
---|
| 77 | def 'M-v' = paste
|
---|
[114] | 78 |
|
---|
[2388] | 79 |
|
---|
| 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 |
|
---|
| 88 | /** Restores a saved cursor position. */
|
---|
| 89 | static void kkeys_restore_cur_pos(long lSavedCurPos)
|
---|
| 90 | {
|
---|
| 91 | _GoToROffset(lSavedCurPos);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
[561] | 95 | _command kkeys_switch_lines()
|
---|
[114] | 96 | {
|
---|
| 97 | /* Allocate a selection for copying the current line. */
|
---|
| 98 | cursor_down();
|
---|
| 99 | mark_id= _alloc_selection();
|
---|
| 100 | if (mark_id>=0)
|
---|
| 101 | {
|
---|
| 102 | _select_line(mark_id);
|
---|
| 103 | cursor_up();
|
---|
| 104 | cursor_up();
|
---|
| 105 | _move_to_cursor(mark_id);
|
---|
| 106 | cursor_down();
|
---|
| 107 | _free_selection(mark_id);
|
---|
| 108 | // This selection can be freed because it is not the active selection.
|
---|
| 109 | }
|
---|
| 110 | else
|
---|
| 111 | message(get_message(mark_id));
|
---|
| 112 | }
|
---|
| 113 |
|
---|
[561] | 114 | _command kkeys_duplicate_line()
|
---|
[114] | 115 | {
|
---|
| 116 | /* Allocate a selection for copying the current line. */
|
---|
| 117 | mark_id= _alloc_selection();
|
---|
| 118 | if (mark_id>=0)
|
---|
| 119 | {
|
---|
| 120 | _select_line(mark_id);
|
---|
| 121 | _copy_to_cursor(mark_id);
|
---|
| 122 | // This selection can be freed because it is not the active selection.
|
---|
| 123 | _free_selection(mark_id);
|
---|
| 124 | cursor_down();
|
---|
| 125 | }
|
---|
| 126 | else
|
---|
| 127 | message(get_message(mark_id));
|
---|
| 128 | }
|
---|
| 129 |
|
---|
[561] | 130 | _command kkeys_delete_right()
|
---|
[114] | 131 | {
|
---|
| 132 | col=p_col
|
---|
| 133 | search('[ \t]#|?|$|^','r+');
|
---|
| 134 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 135 | {
|
---|
| 136 | _nrseek(match_length('s'));
|
---|
| 137 | _delete_text(match_length());
|
---|
| 138 | }
|
---|
| 139 | else
|
---|
| 140 | delete_word();
|
---|
| 141 | p_col=col
|
---|
| 142 | //retrieve_command_results()
|
---|
| 143 |
|
---|
| 144 | }
|
---|
| 145 |
|
---|
[561] | 146 | _command kkeys_delete_left()
|
---|
[114] | 147 | {
|
---|
| 148 | //denne virker ikkje som den skal!!!
|
---|
| 149 | message "not implemented"
|
---|
[561] | 150 | /*
|
---|
[114] | 151 | return;
|
---|
| 152 | col=p_col
|
---|
| 153 | search('[ \t]#|?|$|^','r-');
|
---|
| 154 | if ( match_length()&& get_text(1,match_length('s'))=='' )
|
---|
| 155 | {
|
---|
| 156 | _nrseek(match_length('s'));
|
---|
| 157 | _delete_text(match_length());
|
---|
| 158 | }
|
---|
| 159 | else
|
---|
| 160 | delete_word();
|
---|
| 161 | p_col=col
|
---|
[561] | 162 | */
|
---|
[114] | 163 | }
|
---|
| 164 |
|
---|
[561] | 165 | _command kkeys_scroll_up()
|
---|
[114] | 166 | {
|
---|
| 167 | if (p_cursor_y == 0)
|
---|
| 168 | down();
|
---|
| 169 | set_scroll_pos(p_left_edge, p_cursor_y-1);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[561] | 172 | _command kkeys_scroll_down()
|
---|
[114] | 173 | {
|
---|
| 174 | if (p_cursor_y intdiv p_font_height == p_char_height-1)
|
---|
| 175 | up()
|
---|
| 176 | set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
|
---|
| 177 | }
|
---|
| 178 |
|
---|
[566] | 179 | _command boxer_paste()
|
---|
[114] | 180 | {
|
---|
[2388] | 181 | long lSavedCurPos = kkeys_save_cur_pos()
|
---|
| 182 | paste();
|
---|
| 183 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
[114] | 184 | }
|
---|
| 185 |
|
---|
[252] | 186 | _command kkeys_fullscreen()
|
---|
| 187 | {
|
---|
| 188 | fullscreen();
|
---|
| 189 | }
|
---|
| 190 |
|
---|
| 191 |
|
---|
| 192 | /* for later, not used yet. */
|
---|
| 193 |
|
---|
[114] | 194 | _command boxer_select()
|
---|
| 195 | {
|
---|
| 196 | if (command_state())
|
---|
| 197 | fSelected = (p_sel_length != 0);
|
---|
| 198 | else
|
---|
| 199 | fSelected = select_active();
|
---|
| 200 |
|
---|
| 201 | key = last_event();
|
---|
| 202 | if (key :== name2event('s-down'))
|
---|
| 203 | {
|
---|
| 204 | if (!fSelected)
|
---|
| 205 | select_line();
|
---|
| 206 | else
|
---|
| 207 | cursor_down();
|
---|
| 208 | }
|
---|
| 209 | else if (key :== name2event('s-up'))
|
---|
| 210 | {
|
---|
| 211 | if (!fSelected)
|
---|
| 212 | select_line();
|
---|
| 213 | else
|
---|
| 214 | cursor_up();
|
---|
| 215 | }
|
---|
| 216 | else if (key :== name2event('s-left'))
|
---|
| 217 | {
|
---|
| 218 | if (!fSelected)
|
---|
| 219 | select_char();
|
---|
| 220 | else
|
---|
| 221 | cursor_left();
|
---|
| 222 | }
|
---|
| 223 | else if (key :== name2event('s-right'))
|
---|
| 224 | {
|
---|
| 225 | if (!fSelected)
|
---|
| 226 | select_char();
|
---|
| 227 | else
|
---|
| 228 | cursor_right();
|
---|
| 229 | }
|
---|
| 230 | else if (key :== name2event('s-home'))
|
---|
| 231 | {
|
---|
| 232 | if (!fSelected) select_char();
|
---|
| 233 | begin_line_text_toggle();
|
---|
| 234 | }
|
---|
| 235 | else if (key :== name2event('s-end'))
|
---|
| 236 | {
|
---|
| 237 | if (!fSelected) select_char();
|
---|
| 238 | end_line();
|
---|
| 239 | if (p_col > 0) //this is not identical with boxer...
|
---|
| 240 | cursor_left();
|
---|
| 241 | }
|
---|
| 242 | else if (key :== name2event('c-s-home'))
|
---|
| 243 | {
|
---|
| 244 | if (!fSelected) select_char();
|
---|
| 245 | top_of_buffer();
|
---|
| 246 | }
|
---|
| 247 | else if (key :== name2event('c-s-end'))
|
---|
| 248 | {
|
---|
| 249 | if (!fSelected) select_char();
|
---|
| 250 | bottom_of_buffer();
|
---|
| 251 | }
|
---|
| 252 | else if (key :== name2event('c-s-left'))
|
---|
| 253 | {
|
---|
| 254 | if (!fSelected)
|
---|
| 255 | {
|
---|
| 256 | cursor_left();
|
---|
| 257 | select_char(); /* start this selection non-inclusive */
|
---|
| 258 | }
|
---|
| 259 | prev_word();
|
---|
| 260 | }
|
---|
| 261 | else if (key :== name2event('c-s-right'))
|
---|
| 262 | {
|
---|
| 263 | if (!fSelected)
|
---|
| 264 | {
|
---|
| 265 | select_char(); /* start this selection non-inclusive */
|
---|
| 266 | }
|
---|
| 267 | /* temporary hack */
|
---|
| 268 | prevpos = p_col;
|
---|
| 269 | prevline = p_line;
|
---|
| 270 | p_col++;
|
---|
| 271 | next_word();
|
---|
| 272 | if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
|
---|
| 273 | p_col--;
|
---|
| 274 | }
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 |
|
---|
[2388] | 278 | #if __VERSION__ >= 14.0
|
---|
| 279 | _command kkeys_gen_uuid()
|
---|
| 280 | {
|
---|
| 281 | _str uuid = guid_create_string('G');
|
---|
| 282 | uuid = lowcase(uuid);
|
---|
| 283 |
|
---|
| 284 | long lSavedCurPos = kkeys_save_cur_pos();
|
---|
| 285 | _insert_text(uuid);
|
---|
| 286 | kkeys_restore_cur_pos(lSavedCurPos);
|
---|
| 287 | }
|
---|
| 288 | #endif
|
---|
| 289 |
|
---|
[2400] | 290 | /** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
|
---|
| 291 | *
|
---|
| 292 | * This only works when the alt menu hotkeys are enabled in the
|
---|
| 293 | * settings. Al
|
---|
| 294 | *
|
---|
| 295 | * @{
|
---|
| 296 | */
|
---|
| 297 | _command void kkeys_open_file_menu()
|
---|
| 298 | {
|
---|
| 299 | call_key(A_F)
|
---|
| 300 | }
|
---|
[2388] | 301 |
|
---|
[2400] | 302 | _command void kkeys_open_edit_menu()
|
---|
| 303 | {
|
---|
| 304 | call_key(A_E)
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | _command void kkeys_open_tools_menu()
|
---|
| 308 | {
|
---|
| 309 | call_key(A_T)
|
---|
| 310 | }
|
---|
| 311 | /** @} */
|
---|
| 312 |
|
---|
[114] | 313 | void nop()
|
---|
| 314 | {
|
---|
| 315 |
|
---|
| 316 | }
|
---|
| 317 |
|
---|