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