summaryrefslogtreecommitdiffstats
path: root/SlickEdit/kkeys.e
blob: e7f39aa11a579979f42d06e59cc67325fa621d8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/* $Id: kkeys.e 3555 2022-02-16 13:20:30Z bird $ */
/** @file
 * Bird's key additions to Visual Slickedit.
 */

/*
 * Copyright (c) 2004-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
 *
 * This file is part of kBuild.
 *
 * kBuild is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * kBuild is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with kBuild.  If not, see <http://www.gnu.org/licenses/>
 *
 */

/*******************************************************************************
*  Header Files                                                                *
*******************************************************************************/
#include 'slick.sh'


/*******************************************************************************
*  Global Variables                                                            *
*******************************************************************************/
defeventtab default_keys
def  'A-UP'     = find_prev
def  'A-DOWN'   = find_next
def  'A-PGUP'   = prev_proc
def  'A-PGDN'   = next_proc
def  'A-d'      = delete_line
def  'A-o'      = kkeys_duplicate_line
def  'A-s'      = kkeys_switch_lines
def  'A-u'      = undo_cursor           /* will cursor movement in one undo step. */
def  'A-g'      = goto_line
def  'A-z'      = kkeys_fullscreen
def  'INS'      = boxer_paste
def  'S-INS'    = insert_toggle
def  'S- '      = kkey_space;
def  'C-UP'     = kkeys_scroll_down
def  'C-DOWN'   = kkeys_scroll_up
def  'C-PGUP'   = prev_window
def  'C-PGDN'   = next_window
def  'C-DEL'    = kkeys_delete_right
#if __VERSION__ >= 15.0
def  'S-C-='    = svn_diff_with_base
#endif
#if __VERSION__ >= 22.0
def  'C-='      = diff;
def  'C--'      = nil;
def  'S-A-C-='  = wfont_zoom_in;
def  'S-A-C--'  = wfont_zoom_out;
#endif
#if __VERSION__ >= 14.0
def  'C-/'      = kkeys_push_ref
def  'S-C-/'    = push_ref
def  'S-A-]'    = next_buff_tab
def  'S-A-['    = prev_buff_tab
def  'S-A-U'    = kkeys_gen_uuid
#endif
/* For the mac (A/M mix, all except A-z): */
def  'M-1'      = cursor_error
def  'M-UP'     = find_prev
def  'M-DOWN'   = find_next
def  'M-PGUP'   = prev_proc
def  'M-PGDN'   = next_proc
def  'M-d'      = delete_line
def  'M-f'      = kkeys_open_file_menu
def  'M-e'      = kkeys_open_edit_menu
def  'M-o'      = kkeys_duplicate_line
def  'M-s'      = kkeys_switch_lines
def  'M-t'      = kkeys_open_tools_menu
def  'M-u'      = undo_cursor
def  'M-g'      = goto_line
#if __VERSION__ >= 14.0
def  'S-M-]'    = next_buff_tab
def  'S-M-['    = prev_buff_tab
def  'S-M-U'    = kkeys_gen_uuid
#endif
#if __VERSION__ >= 22.0
def  'S-M-C-='  = wfont_zoom_in;
def  'S-M-C--'  = wfont_zoom_out;
#endif
/* Fixing brainfucked slickedit silliness: */
def  'M-v'      = paste

/* Want proper shift-space in C. */
defeventtab c_keys
def  'S- '      = kkey_space;


/** Saves the cursor position. */
static long kkeys_save_cur_pos()
{
   long offset = _QROffset();
   message(offset);
   return offset;
}

/** Restores a saved cursor position. */
static void kkeys_restore_cur_pos(long lSavedCurPos)
{
   _GoToROffset(lSavedCurPos);
}

/** Fixes shift-space while in block select, default slickedit since a while
 *  is to exit selection mode and insert a single space.  A long long time
 *  ago, I think slickedit would ask if you wanted the normal 'space'
 *  behaviour for this. */
_command void kkey_space()
{
   /** @todo figure out when these functions were added and such. */
   if (!select_active() || _select_type('') != 'BLOCK')
      keyin(' ');
   else
      block_insert_text(' ');
}

_command kkeys_switch_lines()
{
   /* Allocate a selection for copying the current line. */
   cursor_down();
   mark_id= _alloc_selection();
   if (mark_id>=0)
   {
      _select_line(mark_id);
      cursor_up();
      cursor_up();
      _move_to_cursor(mark_id);
      cursor_down();
      _free_selection(mark_id);
      // This selection can be freed because it is not the active selection.
   }
   else
      message(get_message(mark_id));
}

_command kkeys_duplicate_line()
{
   /* Allocate a selection for copying the current line. */
   mark_id= _alloc_selection();
   if (mark_id>=0)
   {
      _select_line(mark_id);
      _copy_to_cursor(mark_id);
      // This selection can be freed because it is not the active selection.
      _free_selection(mark_id);
      cursor_down();
   }
   else
       message(get_message(mark_id));
}

_command kkeys_delete_right()
{
   col=p_col;

   /* virtual space hack */
   keyin(" ");
   left();
   _delete_char();

   /* are we in a word, delete it? */
   ch = get_text();
   if (ch != ' ' && ch != "\t" && ch != "\r" && ch != "\n")
   {
      /* Delete word and any trailing spaces, but stop at new line.
         (Don't use delete_word here!) */
      if (search('([[:alnum:]_]#|?)[ \t]@','r+') == 0)
      {
         _nrseek(match_length('s'));
         _delete_text(match_length());
      }
   }
   else
   {
      /* delete spaces and newlines until the next word. */
      if (search('[ \t\n\r]#','r+') == 0)
      {
         _nrseek(match_length('s'));
         _delete_text(match_length());
      }
   }

   p_col=col
   //retrieve_command_results()
}

_command kkeys_scroll_up()
{
   if (p_cursor_y == 0)
      down();
   set_scroll_pos(p_left_edge, p_cursor_y-1);
}

_command kkeys_scroll_down()
{
   if (p_cursor_y intdiv p_font_height == p_char_height-1)
      up()
   set_scroll_pos(p_left_edge, p_cursor_y+p_font_height);
}

_command boxer_paste()
{
   long lSavedCurPos = kkeys_save_cur_pos()
   paste();
   kkeys_restore_cur_pos(lSavedCurPos);
}

_command kkeys_fullscreen()
{
    fullscreen();
}


/* for later, not used yet. */

_command boxer_select()
{
   if (command_state())
      fSelected = (p_sel_length != 0);
   else
      fSelected = select_active();

   key = last_event();
   if (key :== name2event('s-down'))
   {
      if (!fSelected)
         select_line();
      else
         cursor_down();
   }
   else if (key :== name2event('s-up'))
   {
      if (!fSelected)
         select_line();
      else
         cursor_up();
   }
   else if (key :== name2event('s-left'))
   {
      if (!fSelected)
         select_char();
      else
         cursor_left();
   }
   else if (key :== name2event('s-right'))
   {
      if (!fSelected)
         select_char();
      else
         cursor_right();
   }
   else if (key :== name2event('s-home'))
   {
      if (!fSelected) select_char();
      begin_line_text_toggle();
   }
   else if (key :== name2event('s-end'))
   {
      if (!fSelected) select_char();
      end_line();
      if (p_col > 0) //this is not identical with boxer...
         cursor_left();
   }
   else if (key :== name2event('c-s-home'))
   {
      if (!fSelected) select_char();
      top_of_buffer();
   }
   else if (key :== name2event('c-s-end'))
   {
      if (!fSelected) select_char();
      bottom_of_buffer();
   }
   else if (key :== name2event('c-s-left'))
   {
      if (!fSelected)
      {
         cursor_left();
         select_char(); /* start this selection non-inclusive */
      }
      prev_word();
   }
   else if (key :== name2event('c-s-right'))
   {
      if (!fSelected)
      {
         select_char(); /* start this selection non-inclusive */
      }
      /* temporary hack */
      prevpos = p_col;
      prevline = p_line;
      p_col++;
      next_word();
      if ((p_line == prevline && p_col > prevpos + 1) || (p_line != prevline && p_col > 0))
         p_col--;
   }
}

#if __VERSION__ >= 14.0

/**
 * Search for references only in the current workspace.
 */
_command kkeys_push_ref()
{
   if (_isEditorCtl())
   {
      sProjTagFile = project_tags_filename();
      sLangId      = p_LangId;
      if (sProjTagFile != '')
      {

# if __VERSION__ < 21.0 /** @todo fix me? */
         /* HACK ALERT: Make sure gtag_filelist_last_ext has the right value. */
         _update_tag_filelist_ext(sLangId);

         /* save */
         boolean saved_gtag_filelist_cache_updated = gtag_filelist_cache_updated;
         _str    saved_gtag_filelist_ext[]         = gtag_filelist_ext;

         /* HACK ALERT: Replace the tag file list for this language. */
         gtag_filelist_ext._makeempty();
         gtag_filelist_ext[0] = sProjTagFile;
         gtag_filelist_cache_updated = true;
# endif

         /* Do the reference searching. */
         push_ref('-e ' :+ sLangId);

# if __VERSION__ < 21.0
         /* restore*/
         gtag_filelist_cache_updated = saved_gtag_filelist_cache_updated;
         gtag_filelist_ext           = saved_gtag_filelist_ext;
# endif
      }
      else
         push_ref();
   }
   else
      push_ref();
}


_command kkeys_gen_uuid()
{
   _str uuid = guid_create_string('G');
   uuid = lowcase(uuid);

   long lSavedCurPos = kkeys_save_cur_pos();
   _insert_text(uuid);
   kkeys_restore_cur_pos(lSavedCurPos);
}

#endif /* >= 14.0 */

/** @name Mac OS X Hacks: Alt+[fet] -> drop down menu
 *
 * This only works when the alt menu hotkeys are enabled in the
 * settings.  Al
 *
 * @{
 */
_command void kkeys_open_file_menu()
{
   call_key(A_F)
}

_command void kkeys_open_edit_menu()
{
   call_key(A_E)
}

_command void kkeys_open_tools_menu()
{
   call_key(A_T)
}
/** @} */

void nop()
{

}


#if __VERSION__ >= 14.0

/*
 * Some diff keyboard hacks for Mac OS X.
 */
defeventtab _diff_form
def  'M-f'      = kkeys_diffedit_find
def  'M-n'      = kkeys_diffedit_next
def  'M-p'      = kkeys_diffedit_prev

_command kkeys_diffedit_find()
{
   _nocheck _control _ctlfind;
   _ctlfind.call_event(_ctlfind, LBUTTON_UP);
}

_command kkeys_diffedit_next()
{
   _nocheck _control _ctlfile1;
   _nocheck _control _ctlfile2;
   _DiffNextDifference(_ctlfile1, _ctlfile2);
}

_command kkeys_diffedit_prev()
{
   _nocheck _control _ctlfile1;
   _nocheck _control _ctlfile2;
   _DiffNextDifference(_ctlfile1, _ctlfile2, '-');
}

#endif /* >= 14.0 */