VirtualBox

source: kBuild/trunk/SlickEdit/kkeys.e

Last change on this file was 3555, checked in by bird, 3 years ago

kkeys.e: shift-space in block selection mode workaround.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette