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