| 1 | /* $Id: kkeys.e 1590 2008-05-01 19:31:04Z bird $ */ | 
|---|
| 2 | /** @file | 
|---|
| 3 | * Bird's key additions to Visual Slickedit. | 
|---|
| 4 | */ | 
|---|
| 5 |  | 
|---|
| 6 | /* | 
|---|
| 7 | * | 
|---|
| 8 | * Copyright (c) 2004-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net> | 
|---|
| 9 | * | 
|---|
| 10 | * This file is part of kBuild. | 
|---|
| 11 | * | 
|---|
| 12 | * kBuild is free software; you can redistribute it and/or modify | 
|---|
| 13 | * it under the terms of the GNU General Public License as published by | 
|---|
| 14 | * the Free Software Foundation; either version 2 of the License, or | 
|---|
| 15 | * (at your option) any later version. | 
|---|
| 16 | * | 
|---|
| 17 | * kBuild is distributed in the hope that it will be useful, | 
|---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 20 | * GNU General Public License for more details. | 
|---|
| 21 | * | 
|---|
| 22 | * You should have received a copy of the GNU General Public License | 
|---|
| 23 | * along with kBuild; if not, write to the Free Software | 
|---|
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA | 
|---|
| 25 | * | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | defeventtab default_keys | 
|---|
| 29 | def  'A-UP'     = find_prev | 
|---|
| 30 | def  'A-DOWN'   = find_next | 
|---|
| 31 | def  'A-PGUP'   = prev_proc | 
|---|
| 32 | def  'A-PGDN'   = next_proc | 
|---|
| 33 | def  'A-d'      = delete_line | 
|---|
| 34 | def  'A-o'      = kkeys_duplicate_line | 
|---|
| 35 | def  'A-s'      = kkeys_switch_lines | 
|---|
| 36 | def  'A-u'      = undo_cursor           /* will cursor movement in one undo step. */ | 
|---|
| 37 | def  'A-g'      = goto_line | 
|---|
| 38 | def  'A-z'      = kkeys_fullscreen | 
|---|
| 39 | def  'INS'      = boxer_paste | 
|---|
| 40 | def  'S-INS'    = insert_toggle | 
|---|
| 41 | def  'C-UP'     = kkeys_scroll_down | 
|---|
| 42 | def  'C-DOWN'   = kkeys_scroll_up | 
|---|
| 43 | def  'C-PGUP'   = prev_window | 
|---|
| 44 | def  'C-PGDN'   = next_window | 
|---|
| 45 | def  'C-DEL'    = kkeys_delete_right | 
|---|
| 46 | /* For the mac (A/M mix, all except A-z): */ | 
|---|
| 47 | def  'M-UP'     = find_prev | 
|---|
| 48 | def  'M-DOWN'   = find_next | 
|---|
| 49 | def  'M-PGUP'   = prev_proc | 
|---|
| 50 | def  'M-PGDN'   = next_proc | 
|---|
| 51 | def  'M-d'      = delete_line | 
|---|
| 52 | def  'M-o'      = kkeys_duplicate_line | 
|---|
| 53 | def  'M-s'      = kkeys_switch_lines | 
|---|
| 54 | def  'M-u'      = undo_cursor | 
|---|
| 55 | def  'M-g'      = goto_line | 
|---|
| 56 | /* Fixing brainfucked slickedit silliness: */ | 
|---|
| 57 | def  'M-v'      = paste | 
|---|
| 58 |  | 
|---|
| 59 | _command kkeys_switch_lines() | 
|---|
| 60 | { | 
|---|
| 61 | /* Allocate a selection for copying the current line. */ | 
|---|
| 62 | cursor_down(); | 
|---|
| 63 | mark_id= _alloc_selection(); | 
|---|
| 64 | if (mark_id>=0) | 
|---|
| 65 | { | 
|---|
| 66 | _select_line(mark_id); | 
|---|
| 67 | cursor_up(); | 
|---|
| 68 | cursor_up(); | 
|---|
| 69 | _move_to_cursor(mark_id); | 
|---|
| 70 | cursor_down(); | 
|---|
| 71 | _free_selection(mark_id); | 
|---|
| 72 | // This selection can be freed because it is not the active selection. | 
|---|
| 73 | } | 
|---|
| 74 | else | 
|---|
| 75 | message(get_message(mark_id)); | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | _command kkeys_duplicate_line() | 
|---|
| 79 | { | 
|---|
| 80 | /* Allocate a selection for copying the current line. */ | 
|---|
| 81 | mark_id= _alloc_selection(); | 
|---|
| 82 | if (mark_id>=0) | 
|---|
| 83 | { | 
|---|
| 84 | _select_line(mark_id); | 
|---|
| 85 | _copy_to_cursor(mark_id); | 
|---|
| 86 | // This selection can be freed because it is not the active selection. | 
|---|
| 87 | _free_selection(mark_id); | 
|---|
| 88 | cursor_down(); | 
|---|
| 89 | } | 
|---|
| 90 | else | 
|---|
| 91 | message(get_message(mark_id)); | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | _command kkeys_delete_right() | 
|---|
| 95 | { | 
|---|
| 96 | col=p_col | 
|---|
| 97 | search('[ \t]#|?|$|^','r+'); | 
|---|
| 98 | if ( match_length()&& get_text(1,match_length('s'))=='' ) | 
|---|
| 99 | { | 
|---|
| 100 | _nrseek(match_length('s')); | 
|---|
| 101 | _delete_text(match_length()); | 
|---|
| 102 | } | 
|---|
| 103 | else | 
|---|
| 104 | delete_word(); | 
|---|
| 105 | p_col=col | 
|---|
| 106 | //retrieve_command_results() | 
|---|
| 107 |  | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | _command kkeys_delete_left() | 
|---|
| 111 | { | 
|---|
| 112 | //denne virker ikkje som den skal!!! | 
|---|
| 113 | message "not implemented" | 
|---|
| 114 | /* | 
|---|
| 115 | return; | 
|---|
| 116 | col=p_col | 
|---|
| 117 | search('[ \t]#|?|$|^','r-'); | 
|---|
| 118 | if ( match_length()&& get_text(1,match_length('s'))=='' ) | 
|---|
| 119 | { | 
|---|
| 120 | _nrseek(match_length('s')); | 
|---|
| 121 | _delete_text(match_length()); | 
|---|
| 122 | } | 
|---|
| 123 | else | 
|---|
| 124 | delete_word(); | 
|---|
| 125 | p_col=col | 
|---|
| 126 | */ | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | _command kkeys_scroll_up() | 
|---|
| 130 | { | 
|---|
| 131 | if (p_cursor_y == 0) | 
|---|
| 132 | down(); | 
|---|
| 133 | set_scroll_pos(p_left_edge, p_cursor_y-1); | 
|---|
| 134 | } | 
|---|
| 135 |  | 
|---|
| 136 | _command kkeys_scroll_down() | 
|---|
| 137 | { | 
|---|
| 138 | if (p_cursor_y intdiv p_font_height == p_char_height-1) | 
|---|
| 139 | up() | 
|---|
| 140 | set_scroll_pos(p_left_edge, p_cursor_y+p_font_height); | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | _command boxer_paste() | 
|---|
| 144 | { | 
|---|
| 145 | int rc; | 
|---|
| 146 | offset = _QROffset(); | 
|---|
| 147 | message(offset); | 
|---|
| 148 | rc = paste(); | 
|---|
| 149 | _GoToROffset(offset); | 
|---|
| 150 | } | 
|---|
| 151 |  | 
|---|
| 152 | _command kkeys_fullscreen() | 
|---|
| 153 | { | 
|---|
| 154 | fullscreen(); | 
|---|
| 155 | } | 
|---|
| 156 |  | 
|---|
| 157 |  | 
|---|
| 158 | /* for later, not used yet. */ | 
|---|
| 159 |  | 
|---|
| 160 | _command boxer_select() | 
|---|
| 161 | { | 
|---|
| 162 | if (command_state()) | 
|---|
| 163 | fSelected = (p_sel_length != 0); | 
|---|
| 164 | else | 
|---|
| 165 | fSelected = select_active(); | 
|---|
| 166 |  | 
|---|
| 167 | key = last_event(); | 
|---|
| 168 | if (key :== name2event('s-down')) | 
|---|
| 169 | { | 
|---|
| 170 | if (!fSelected) | 
|---|
| 171 | select_line(); | 
|---|
| 172 | else | 
|---|
| 173 | cursor_down(); | 
|---|
| 174 | } | 
|---|
| 175 | else if (key :== name2event('s-up')) | 
|---|
| 176 | { | 
|---|
| 177 | if (!fSelected) | 
|---|
| 178 | select_line(); | 
|---|
| 179 | else | 
|---|
| 180 | cursor_up(); | 
|---|
| 181 | } | 
|---|
| 182 | else if (key :== name2event('s-left')) | 
|---|
| 183 | { | 
|---|
| 184 | if (!fSelected) | 
|---|
| 185 | select_char(); | 
|---|
| 186 | else | 
|---|
| 187 | cursor_left(); | 
|---|
| 188 | } | 
|---|
| 189 | else if (key :== name2event('s-right')) | 
|---|
| 190 | { | 
|---|
| 191 | if (!fSelected) | 
|---|
| 192 | select_char(); | 
|---|
| 193 | else | 
|---|
| 194 | cursor_right(); | 
|---|
| 195 | } | 
|---|
| 196 | else if (key :== name2event('s-home')) | 
|---|
| 197 | { | 
|---|
| 198 | if (!fSelected) select_char(); | 
|---|
| 199 | begin_line_text_toggle(); | 
|---|
| 200 | } | 
|---|
| 201 | else if (key :== name2event('s-end')) | 
|---|
| 202 | { | 
|---|
| 203 | if (!fSelected) select_char(); | 
|---|
| 204 | end_line(); | 
|---|
| 205 | if (p_col > 0) //this is not identical with boxer... | 
|---|
| 206 | cursor_left(); | 
|---|
| 207 | } | 
|---|
| 208 | else if (key :== name2event('c-s-home')) | 
|---|
| 209 | { | 
|---|
| 210 | if (!fSelected) select_char(); | 
|---|
| 211 | top_of_buffer(); | 
|---|
| 212 | } | 
|---|
| 213 | else if (key :== name2event('c-s-end')) | 
|---|
| 214 | { | 
|---|
| 215 | if (!fSelected) select_char(); | 
|---|
| 216 | bottom_of_buffer(); | 
|---|
| 217 | } | 
|---|
| 218 | else if (key :== name2event('c-s-left')) | 
|---|
| 219 | { | 
|---|
| 220 | if (!fSelected) | 
|---|
| 221 | { | 
|---|
| 222 | cursor_left(); | 
|---|
| 223 | select_char(); /* start this selection non-inclusive */ | 
|---|
| 224 | } | 
|---|
| 225 | prev_word(); | 
|---|
| 226 | } | 
|---|
| 227 | else if (key :== name2event('c-s-right')) | 
|---|
| 228 | { | 
|---|
| 229 | if (!fSelected) | 
|---|
| 230 | { | 
|---|
| 231 | select_char(); /* start this selection non-inclusive */ | 
|---|
| 232 | } | 
|---|
| 233 | /* temporary hack */ | 
|---|
| 234 | prevpos = p_col; | 
|---|
| 235 | prevline = p_line; | 
|---|
| 236 | p_col++; | 
|---|
| 237 | next_word(); | 
|---|
| 238 | if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0)) | 
|---|
| 239 | p_col--; | 
|---|
| 240 | } | 
|---|
| 241 | } | 
|---|
| 242 |  | 
|---|
| 243 |  | 
|---|
| 244 | void nop() | 
|---|
| 245 | { | 
|---|
| 246 |  | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|