-
Notifications
You must be signed in to change notification settings - Fork 4
/
wee.exw
2923 lines (2557 loc) · 87.8 KB
/
wee.exw
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Wee Euphoria Editor
--
-- Copyright (c) 1998-2018 Pete Eberlein
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-- THE SOFTWARE.
global constant
window_title = "Wee Euphoria Editor",
author = "Pete Eberlein <pete.eberlein@gmail.com>",
version = "0.52",
changelog = `
Version 0.52
- Change updater to raw.githubusercontent.com from cdn.rawgit.com
- Bug fix: Incorrect window position on multi-monitor (thanks Phil D.)
- Bug fix: Negative pointer crash due to incorrect link_c_* arguments (thanks Phil D.)
- View Subroutines list now accepts double-click as OK
- Bug fix: View Error/Open Ex.err was overwriting current tab
Version 0.51
- Fix terminal warning about overflow (thanks Irv)
Version 0.50
- Set codepage to UTF-8 (thanks Irv)
Version 0.49
- Bug fix: crash if wee_conf can't be opened for writing (thanks Bugmagnet)
Version 0.48
- Bug fix: hang during replace all (thanks Andreas)
- Auto-detect EOL characters when opening
Version 0.47
- Bug fix: parser support for "loop until" statement (thanks dcuny)
Version 0.46
- Bug fix: parser should allow case statements inside ifdef
- Bug fix: crash in parser for non-existent namespace include (thanks Andreas)
Version 0.45
- Help->Release Notes to view changelog
- Bug fix: use EUDIR when locating help index
- Bug fix: 'not' in ifdefs was flagged as an error
- Bug fix: set default indentation for new tabs
- Bug fix: clear insert chars after auto-indent
Version 0.44
- ARM scintilla library (tested on Raspberry Pi 2)
Version 0.43
- Bug fixed: open shell in current directory (UNIX)
Version 0.42
- Run commands in a temporary script (Linux/OSX)
Version 0.41
- Improved parsing speed
Version 0.40
- Bug fixed: crashes on auto-completion and error parsing (thanks dcuny)
Version 0.39
- Error indicators and mouse dwell message
- Add namespaces to auto-complete (with 'n' icon)
- Add EUDIR support
- Bug fixed: mousewheel tab change on Windows
Version 0.38
- Adding run options: background and test run (thanks KDR)
- Bug fixed: crash on fail to open file during parsing (thanks sdpringle)
- Bug fixed: crash on error while saving (thanks sdpringle)
Version 0.37
- Filename first in window title
- Tabs now have mouseover tooltip with full path (win32: only the active tab)
- Bug fixed: crash when interpreter list is empty (thanks Irv)
Version 0.36
- Windows icon built-in
- Run Set Interpreter now lets you override the interpreter used
Version 0.35
- Allow quoted include filename (thanks dcuny)
Version 0.34
- Bug fix: crash on parsing "-type ..." (thanks dcuny)
Version 0.33
- select next/prev tab using mouse wheel over tabs
- close tab with middle mouse button
- select next tab (Ctrl+Tab) and previous tab (Shift+Ctrl+Tab)
Version 0.32
- 64-bit supported on Windows (joining Linux/OSX)
- Bug fix: no message when opening saved tab whose file no longer exists
Version 0.31
- Bug fix: cursor color changes based on background (thanks Andreas)
- Bug fix: string color not loaded from config file (thanks Andreas)
- Bug fix: bold options reversed for String and Number
- Bug fix: incorrect tab or new tab selected when reopening tabs
Version 0.30
- Options to disable auto-completing statements or braces
- Auto-completion and syntax coloring disabled for non-Euphoria files
- Bold options for syntax coloring
- Bug fix: crash when typing character literals with calltip active
- Bug fix: GTK version: close tab didn't prompt to save modified files
Version 0.29
- Bug fix: crash + lose wee_conf when closing on Windows with reopen_tabs=1
Version 0.28
- Run menu choose which intepreter to use
- Run will choose interpreter location (based on eu.cfg include path)
- Option to reopen tabs next time
Version 0.27
- autocompletion list shows icons for each type of declaration
Version 0.26
- line wrap option
- Bug fix: preserve selection during comment/uncomment lines
Version 0.25
- fill in Find dialog with current selection
- allow search backward in Find and Replace dialogs
- quick search Find Next (Ctrl+G) Find Previous (Shift+Ctrl+G)
- comment/uncomment selected lines (Ctrl+M)
- go back (Esc) after doing View Declaration or Goto Error
- if there is a selection, it will be deselected first
Version 0.24
- drag'n'drop files
Version 0.23
- Bug fix: run/bind/shroud/translate didn't like spaces in the path
Version 0.22
- Bug fix: better at locating scintilla library when bound/compiled
Version 0.21
- dialog to change syntax highlighting colors
- popup menu on tab control
Version 0.20
- run with arguments (Shift+F5)
- move options to separate menu
- option to sort subroutines in View Subroutines dialog
- added Bind, Shroud and Translate to Run menu
Version 0.19
- Linux/Mac (using EuGTK)
- context-sensitive help (hit F1 on a word)
Version 0.18
- store syntax highlighting colors in wee.conf
Version 0.17
- updated: indent/unindent selection with tab/shift-tab
Version 0.16
- updated: ex.err dialog with buttons: <cancel> <open ex.err> <goto error>
- and listbox with call stack or multiple undeclared references
- Bug fix: weirdness with deletion autoinserted closing characters
- Bug fix: calltip popup displaying incorrect highlight after first time
- Bug fix: EOL mode on Linux/OSX
- Bug fix: completions are now sorted
- Bug fix: switch/case syntax highlight and autocomplete were missing
- Bug fix: shift-ctrl-Z does redo
Version 0.15
- hardcoded list of builtins and arguments in get_subroutine_arguents()
Version 0.13
- auto-complete with include puts it near top of file
- auto insert closing characters for ( { [ " '
- typing '(' after a subroutine will popup hints
- Bug fix: autocomplete avoids activating inside comments and strings
Version 0.12
- auto expansions for "if" "while" "for" and subroutines (thanks dcuny)
- auto indent newlines
- type ':' to autocomplete a namespace
Version 0.11
- view completions will search std includes
- Search->Find will remember last phrase
- fixed tab names not updating when save-as
- fixed "too many open files" error, wasn't closing files in view_error function
- fixed parsing ifdefs
- fixed crash after changing font (thanks euphoric)
- reloading a file that is modified externally loads into wrong tab (thanks dcuny)
Version 0.10
- Bug fix: ViewCompletions on whitespace crash
Version 0.09
- Scintilla edit control (using Lua lexer :/)
Version 0.08
- watch tabs for changes to files and ex.err
- goto declaration (Ctrl+F2) and view completions (Ctrl+Space)
Version 0.07
- tabs (can be selected using Alt+1..9)
Older Versions
- syntax coloring!
- Bug fix: save mode changed to "wb" (Thanks Lucius)
- replace all
- goto error
- hotkeys
- cursor position
- recent files list
- saving window pos+size and recent files to "wee_conf.txt"
- subroutines list dialog (F2)
- choose font dialog (we suggest "Consolas" 11pt)
- bugs fixed:
- ViewDeclaration wrong cursor pos
- audible ding when pressing Alt+1..9
- parser updates cache for modified include files
- files are now opened in binary mode since scintilla can handle any line endings
`
-- todo:
-- bug with reloading files, first few characters get garbled
-- expanding "for" should then tab between "=", "to", and "do"
-- as it is now, its really annoying (but better with overtyping)
-- fix brace highlighting in comments and strings
-- put arguments after each subroutine completion (maybe)
-- investigate Mike Duffy's scintilla Euphoria Lexer
-- multicolored brackets and parens
-- multiline comments and strings
-- code-aware identifier rename
-- add function to parser to get all instances of identifier in scope
-- use multi-select to replace all instances in one shot
-- limited to a single file (too difficult otherwise)
-- macro recording (SCI_STARTRECORD/SCI_STOPRECORD/SCN_MACRORECORD)
-- disable menu items when the action has no effect
-- disable cut/copy when no selection, or paste with empty clipboard
-- disable undo/redo when nothing to do
-- disable go back when nowhere to go back to
-- old calltips sometimes pop up after a calltip elsewhere is closed
-- probably due to nesting calltips
-- will crash by putting a function after sci_notify() (Linux/OSX 64-bit)
-- triggered by using Alt+1-9 to change tabs
-- Euphoria bug? file a ticket
-- help->check for updates
-- updating dll would require updater.ex
-- option to bind/shround/recompile
-- edit->tidy, to clean up indentation/formatting
--without warning
include parser.e
include scintilla.e
include std/get.e
include std/filesys.e
include std/sequence.e
include std/text.e
include std/machine.e
include std/error.e
include std/io.e
include weeicon.e
-- The ui includes are circular includes:
-- wee.exw -> ui_win.e -> wee.exw
-- The ui include is responsible for calling wee_init() and startup.
ifdef WINDOWS then
include ui_win.e
elsedef
include ui_gtk.e
end ifdef
-- all variables must be initialized in wee_init() due to circular include
global constant max_recent_files = 5
-- these are configuration settings saved to wee_conf
global atom x_pos, y_pos, x_size, y_size
global sequence font_name, recent_files,
terminal_program -- for GTK, runs programs in a terminal
global integer font_height,
line_numbers, -- boolean
sorted_subs, -- boolean
line_wrap, -- boolean
reopen_tabs, -- boolean
tab_width, -- usually 8
indentation_guides, -- boolean
caret_width, -- in pixels
complete_statements, -- when typing "if " -> "if | then\n \nend if"
complete_braces, -- when typing '(' or '[' or '{' or ''' or '"'
auto_namespace, -- when typing ':'
auto_complete, -- when typing two word chars or backspace
auto_arguments, -- when typing '(' after an identifier
auto_indent, -- when creating a new line
auto_indicator, -- underline words that are not in scope
run_testrun, -- run exe after bind/shroud/translate
run_background, -- for GTK, run programs/terminal in background
run_waitkey, -- wait for keypress after running in a terminal
keyword_color, builtin_color, string_color,
comment_color, number_color, normal_color, background_color,
linenumber_color, bracelight_color, bold_flags
sequence tabs_to_open -- {{"filename", pos, topline},...}
sequence file_types -- {{{"ext1","ext2",...}, SCLEX_x, {index, "keywords ...", ...}, {"match", "expand",...}
global sequence file_name, run_file_name, ex_err_name
global sequence find_phrase, replace_phrase, interpreter, wee_path
-- local variables
sequence
tab_hedits, tab_file_names, tab_timestamps,
recent_pos, tab_arguments, tab_pos_stack
integer current_tab, modified, initial_tab
atom hedit
atom ex_err_timestamp
integer expand_line, last_deleted_char
sequence insert_chars
sequence calltip_args -- {{start,end},...}
integer calltip_pos
sequence calltip_stack -- {calltip_pos, calltip_args...}
sequence calltip_text -- "routine_name(type1 arg1, ...)"
integer calltip_dwell -- flag indicating calltip from mouse dwell
sequence wee_conf_filename
sequence search_idx, search_dat
sequence expansions
sequence last_errors
atom change_time -- when to perform error indicator checking
-- shorthand helper function
function ssm(integer m, object w=0, object l=0)
return scintilla_send_message(hedit, m, w, l)
end function
function crash_cleanup(object x)
ui_message_box_error(window_title,
"Houston, Wee've had a problem.\n\n" &
"The editor crashed and is closing now.\n")
save_modified_tabs()
if length(wee_conf_filename) then
save_wee_conf(wee_conf_filename)
end if
return 0
end function
constant -- colors of various syntax classes
Black = #000000,
Gray = #AAAAAA,
DGray = #808080,
Green = #00AA00,
Yellow = #88FFFF,
Magenta = #AA00AA,
Cyan = #AAAA00,
Red = #0000AA,
Blue = #AA0000,
LightBlue = #FFFFDD,
White = #FFFFFF,
BrightRed = #0000FF
global procedure wee_init()
sequence cmdline
wee_conf_filename = ""
crash_routine(routine_id("crash_cleanup"))
recent_files = {}
recent_pos = {}
font_name = ""
font_height = 10
line_numbers = 0
sorted_subs = 0
line_wrap = 0
file_name = ""
hedit = 0
run_file_name = ""
ex_err_name = "ex.err"
ex_err_timestamp = get_timestamp(ex_err_name)
interpreter = ""
tab_hedits = {}
tab_file_names = {}
tab_timestamps = {}
tab_arguments = {}
tab_pos_stack = {}
last_errors = {}
modified = 0
expand_line = -1
insert_chars = ""
last_deleted_char = 0
auto_namespace = 1
auto_complete = 1
complete_statements = 1
complete_braces = 1
auto_arguments = 1
auto_indent = 1
tab_width = 8
indentation_guides = 0
caret_width = 2
auto_indicator = 1
run_testrun = 0
run_background = 1
run_waitkey = 1
calltip_args = {}
calltip_pos = -1
calltip_stack = {}
calltip_text = ""
calltip_dwell = 0
current_tab = 0
normal_color = Black
background_color = White
comment_color = DGray
number_color = Black
keyword_color = Green
builtin_color = Magenta
string_color = Blue
bracelight_color = LightBlue
linenumber_color = DGray
bold_flags = #40
search_idx = {}
search_dat = {}
find_phrase = ""
replace_phrase = ""
terminal_program = ""
reopen_tabs = 1
tabs_to_open = {}
initial_tab = 1
cmdline = command_line()
wee_path = canonical_path(dirname(cmdline[2]))
if length(wee_path) and wee_path[$] = SLASH then
wee_path = wee_path[1..$-1]
end if
file_types = {
{
-- extensions
{"ex", "e", "exw", "ew", "exu", "eu"},
-- SCLEX_constant
SCLEX_LUA,
-- identifiers used with SCI_SETIDENTIFIERS
{0,
"procedure function type end and or xor not if then elsif else for to by do while "&
"global constant include with without return exit "&
-- OE4
"public export enum as namespace ifdef elsifdef elsedef "&
"label entry break continue loop until routine switch case fallthru",
1,
get_builtins()
},
-- expansions used with auto_expand()
{{"if", "", " then", "end if"},
{"elsif", "", " then"},
{"while", "", " do", "end while"},
{"for", " = to ", " do", "end for"},
{"case", "", " then"},
{"loop", "", "do", "end loop"},
{"switch", "", " do", "end switch"},
{0, "global ", "public ", "export "},
{"procedure", "()", "", "end procedure"},
{"function", "()", "", "end function"},
{"type", "()", "", "end type"}
},
interpreter
},
{
-- extensions
{"c", "h", "cpp", "hpp"},
-- SCLEX_constant
SCLEX_CPP,
-- identifiers used with SCI_SETKEYWORDS
{0,
"if else for do while switch case default "&
"return break continue "&
"enum typedef struct union static const ",
1,
"void int char unsigned long sizeof"
},
-- expansions used with auto_expand()
{{"if", "()", " {", "}"},
{"} else if", "()", " { "},
{"while", "()", " {", "}"},
{"for", "(;;)", " {", "}"},
{"switch", "()", " {", "}"},
{"case", "", ":", "break;"}
}
},
{
-- extensions
{"htm", "html"},
-- SCLEX_constant
SCLEX_HTML,
-- identifiers used with SCI_SETKEYWORDS
{},
-- expansions used with auto_expand()
{}
}
}
expansions = {}
end procedure
global procedure load_wee_conf(sequence wee_conf_file)
integer f, eq, int_ok
object l
sequence key, val
f = open(wee_conf_file, "r")
if f = -1 then return end if
wee_conf_filename = wee_conf_file
l = gets(f)
while sequence(l) do
eq = find('=', l)
if eq then
key = l[1..eq-1]
val = l[eq+1..length(l)-1]
l = value(val)
int_ok = (l[1] = 0 and integer(l[2]))
if equal(key, "x_pos") and int_ok then
x_pos = l[2]
elsif equal(key, "y_pos") and int_ok then
y_pos = l[2]
elsif equal(key, "x_size") and int_ok then
x_size = l[2]
elsif equal(key, "y_size") and int_ok then
y_size = l[2]
elsif equal(key, "recent_file") then
recent_files &= {val}
elsif equal(key, "recent_pos") and int_ok then
recent_pos &= l[2]
elsif equal(key, "font_name") then
font_name = val
elsif equal(key, "font_height") and int_ok then
font_height = l[2]
if font_height < 0 then
font_height = -floor((font_height*96+36)/72)
end if
elsif equal(key, "line_numbers") and int_ok then
line_numbers = l[2]
elsif equal(key, "normal_color") and int_ok then
normal_color = l[2]
elsif equal(key, "background_color") and int_ok then
background_color = l[2]
elsif equal(key, "comment_color") and int_ok then
comment_color = l[2]
elsif equal(key, "keyword_color") and int_ok then
keyword_color = l[2]
elsif equal(key, "builtin_color") and int_ok then
builtin_color = l[2]
elsif equal(key, "number_color") and int_ok then
number_color = l[2]
elsif equal(key, "string_color") and int_ok then
string_color = l[2]
elsif equal(key, "linenumber_color") and int_ok then
linenumber_color = l[2]
elsif equal(key, "bracelight_color") and int_ok then
bracelight_color = l[2]
elsif equal(key, "sorted_subs") and int_ok then
sorted_subs = l[2]
elsif equal(key, "line_wrap") and int_ok then
line_wrap = l[2]
elsif equal(key, "interpreter") then
if not find(val, {"eui","euiw","ex","exw"}) then
interpreter = val
end if
elsif equal(key, "reopen_tabs") and int_ok then
reopen_tabs = l[2]
elsif equal(key, "open_tab") then
if length(l[2]) = 3 and sequence(l[2][1]) and integer(l[2][2]) and integer(l[2][3]) then
tabs_to_open = append(tabs_to_open, l[2])
else
tabs_to_open = append(tabs_to_open, {val, 0, 0})
end if
elsif equal(key, "open_tab_pos") and int_ok then
tabs_to_open[$][2] = l[2]
elsif equal(key, "open_tab_line") and int_ok then
tabs_to_open[$][3] = l[2]
elsif equal(key, "initial_tab") and int_ok then
initial_tab = l[2]
elsif equal(key, "complete_statements") and int_ok then
complete_statements = l[2]
elsif equal(key, "complete_braces") and int_ok then
complete_braces = l[2]
elsif equal(key, "bold_flags") and int_ok then
bold_flags = l[2]
elsif equal(key, "tab_width") and int_ok then
tab_width = l[2]
elsif equal(key, "indentation_guides") and int_ok then
indentation_guides = l[2]
elsif equal(key, "caret_width") and int_ok then
caret_width = l[2]
elsif equal(key, "terminal_program") then
terminal_program = val
elsif equal(key, "run_testrun") and int_ok then
run_testrun = l[2]
elsif equal(key, "run_background") and int_ok then
run_background = l[2]
elsif equal(key, "run_waitkey") and int_ok then
run_waitkey = l[2]
end if
end if
l = gets(f)
end while
close(f)
end procedure
global procedure save_wee_conf(sequence wee_conf_file)
integer f
f = open(wee_conf_file, "w")
if f < 0 then
ui_message_box_error(window_title,
"Unable to open "&wee_conf_file&" for writing.\n\n"&
"Your configuration settings can't be saved.")
return
end if
printf(f, "x_pos=%d\ny_pos=%d\nx_size=%d\ny_size=%d\nline_numbers=%d\n",
{x_pos, y_pos, x_size, y_size, line_numbers})
for i = 1 to length(recent_files) do
puts(f, "recent_file="&recent_files[i]&"\n")
printf(f, "recent_pos=%d\n", {recent_pos[i]})
end for
if length(font_name) and font_height != 0 then
printf(f, "font_name=%s\nfont_height=%d\n", {font_name, font_height})
end if
printf(f, "normal_color=#%06x\n", {normal_color})
printf(f, "background_color=#%06x\n", {background_color})
printf(f, "keyword_color=#%06x\n", {keyword_color})
printf(f, "builtin_color=#%06x\n", {builtin_color})
printf(f, "comment_color=#%06x\n", {comment_color})
printf(f, "number_color=#%06x\n", {number_color})
printf(f, "string_color=#%06x\n", {string_color})
printf(f, "linenumber_color=#%06x\n", {linenumber_color})
printf(f, "bracelight_color=#%06x\n", {bracelight_color})
printf(f, "bold_flags=#%x\n", {bold_flags})
printf(f, "sorted_subs=%d\n", {sorted_subs})
printf(f, "line_wrap=%d\n", {line_wrap})
printf(f, "interpreter=%s\n", {interpreter})
printf(f, "reopen_tabs=%d\n", {reopen_tabs})
printf(f, "initial_tab=%d\n", {current_tab})
if reopen_tabs then
for i = 1 to length(tab_file_names) do
if length(tab_file_names[i]) then
hedit = tab_hedits[i]
printf(f, "open_tab=%s\nopen_tab_pos=%d\nopen_tab_line=%d\n", {
tab_file_names[i],
ssm(SCI_GETCURRENTPOS),
ssm(SCI_GETFIRSTVISIBLELINE)})
end if
end for
end if
printf(f, "complete_statements=%d\n", {complete_statements})
printf(f, "complete_braces=%d\n", {complete_braces})
printf(f, "tab_width=%d\n", {tab_width})
printf(f, "indentation_guides=%d\n", {indentation_guides})
printf(f, "caret_width=%d\n", {caret_width})
printf(f, "terminal_program=%s\n", {terminal_program})
printf(f, "run_testrun=%d\n", {run_testrun})
printf(f, "run_background=%d\n", {run_background})
printf(f, "run_waitkey=%d\n", {run_waitkey})
close(f)
end procedure
function sreplace(sequence text, sequence what, sequence replacement)
integer i
i = match(what, text)
if i then
return text[1..i-1] & replacement & text[i+length(what)..$]
end if
return text
end function
-- update the hedit lexer based on the file extension
procedure update_lexer()
sequence ext, keywords
integer lexer
if length(tab_file_names[current_tab]) then
ext = lower(fileext(tab_file_names[current_tab]))
else
ext = "ex" -- New file
end if
lexer = SCLEX_NULL
expansions = {}
keywords = {}
for i = 1 to length(file_types) do
if find(ext, file_types[i][1]) then
lexer = file_types[i][2]
keywords = file_types[i][3]
expansions = file_types[i][4]
exit
end if
end for
if lexer != ssm(SCI_GETLEXER) then
ssm(SCI_SETLEXER, lexer)
init_edit(hedit)
for k = 1 to length(keywords) by 2 do
ssm(SCI_SETKEYWORDS, keywords[k], keywords[k+1])
end for
end if
end procedure
-- init edit, (or reinit all existing edits when hedit = 0)
global procedure init_edit(atom edit)
sequence font
integer lexer
hedit = edit
font = font_name
ifdef not WINDOWS then
font = sreplace(font, "Medium", "")
font = sreplace(font, "Thin", "")
font = sreplace(font, "Bold", "")
font = sreplace(font, "Italic", "")
font = sreplace(font, "Condensed", "")
font = rtrim(font)
end ifdef
ssm(SCI_STYLESETFONT, STYLE_DEFAULT, font)
ifdef not WINDOWS then
ssm(SCI_STYLESETBOLD, STYLE_DEFAULT, match(" Bold", font_name))
ssm(SCI_STYLESETITALIC, STYLE_DEFAULT, match(" Italic", font_name))
end ifdef
ssm(SCI_STYLESETSIZE, STYLE_DEFAULT, font_height)
ssm(SCI_STYLESETFORE, STYLE_DEFAULT, normal_color)
ssm(SCI_STYLESETBACK, STYLE_DEFAULT, background_color)
ssm(SCI_SETCARETFORE, xor_bits(background_color, #FFFFFF))
ssm(SCI_STYLESETBOLD, STYLE_DEFAULT, and_bits(bold_flags, 1))
ssm(SCI_STYLECLEARALL)
lexer = ssm(SCI_GETLEXER)
if lexer = SCLEX_LUA then
ssm(SCI_STYLESETFORE, SCE_LUA_COMMENT, comment_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_COMMENT, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_LUA_COMMENTLINE, comment_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_COMMENTLINE, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_LUA_STRING, string_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_STRING, 0 != and_bits(bold_flags, 4))
ssm(SCI_STYLESETFORE, SCE_LUA_WORD, keyword_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_WORD, 0 != and_bits(bold_flags, 8))
ssm(SCI_STYLESETFORE, SCE_LUA_WORD2, builtin_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_WORD2, 0 != and_bits(bold_flags, #10))
ssm(SCI_STYLESETFORE, SCE_LUA_NUMBER, number_color)
ssm(SCI_STYLESETBOLD, SCE_LUA_NUMBER, 0 != and_bits(bold_flags, #20))
elsif lexer = SCLEX_CPP then
ssm(SCI_STYLESETFORE, SCE_C_COMMENT, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_COMMENT, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_COMMENTLINE, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_COMMENTLINE, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_COMMENTDOC, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_COMMENTDOC, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_COMMENTLINEDOC, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_COMMENTLINEDOC, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_PREPROCESSORCOMMENT, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_PREPROCESSORCOMMENT, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_PREPROCESSORCOMMENTDOC, comment_color)
ssm(SCI_STYLESETBOLD, SCE_C_PREPROCESSORCOMMENTDOC, 0 != and_bits(bold_flags, 2))
ssm(SCI_STYLESETFORE, SCE_C_STRING, string_color)
ssm(SCI_STYLESETBOLD, SCE_C_STRING, 0 != and_bits(bold_flags, 4))
ssm(SCI_STYLESETFORE, SCE_C_WORD, keyword_color)
ssm(SCI_STYLESETBOLD, SCE_C_WORD, 0 != and_bits(bold_flags, 8))
ssm(SCI_STYLESETFORE, SCE_C_WORD2, builtin_color)
ssm(SCI_STYLESETBOLD, SCE_C_WORD2, 0 != and_bits(bold_flags, #10))
ssm(SCI_STYLESETFORE, SCE_C_NUMBER, number_color)
ssm(SCI_STYLESETBOLD, SCE_C_NUMBER, 0 != and_bits(bold_flags, #20))
end if
ssm(SCI_STYLESETBACK, STYLE_BRACELIGHT, bracelight_color)
ssm(SCI_STYLESETBOLD, STYLE_BRACELIGHT, 0 != and_bits(bold_flags, #40))
ssm(SCI_STYLESETFORE, STYLE_LINENUMBER, linenumber_color)
ssm(SCI_STYLESETBOLD, STYLE_LINENUMBER, 0 != and_bits(bold_flags, #80))
ssm(SCI_SETCODEPAGE,SC_CP_UTF8) -- added by Irv
ssm(SCI_SETMARGINWIDTHN, 0, 48*line_numbers) -- line numbers margin visible
ssm(SCI_SETMARGINWIDTHN, 1, 0) -- non-folding symbols margin hidden
ssm(SCI_SETTABINDENTS, 1)
ssm(SCI_SETBACKSPACEUNINDENTS, 1)
ssm(SCI_SETINDENTATIONGUIDES, indentation_guides)
ssm(SCI_SETTABWIDTH, tab_width)
ssm(SCI_SETCARETWIDTH, caret_width)
ssm(SCI_AUTOCSETSEPARATOR, '\n')
ssm(SCI_AUTOCSTOPS, 0, " ")
ssm(SCI_AUTOCSETFILLUPS, 0, "")
--ssm(SCI_AUTOCSETORDER, SC_ORDER_CUSTOM) -- declaration order
ssm(SCI_AUTOCSETORDER, SC_ORDER_PERFORMSORT) -- scintilla should sort
ssm(SCI_AUTOCSETCANCELATSTART)
-- call tips display above text
ssm(SCI_CALLTIPSETPOSITION, 1)
-- get modification events for deletetext
ssm(SCI_SETMODEVENTMASK,
SC_MOD_INSERTTEXT +
SC_MOD_DELETETEXT +
SC_MOD_BEFOREDELETE)
ssm(SCI_SETWRAPMODE, line_wrap)
ifdef WINDOWS then
ssm(SCI_SETEOLMODE, SC_EOL_CRLF)
elsedef
ssm(SCI_SETEOLMODE, SC_EOL_LF)
end ifdef
ssm(SCI_REGISTERIMAGE, DECL_ATOM, a_xpm)
ssm(SCI_REGISTERIMAGE, DECL_CONSTANT, c_xpm)
ssm(SCI_REGISTERIMAGE, DECL_ENUM, e_xpm)
ssm(SCI_REGISTERIMAGE, DECL_FUNCTION, f_xpm)
ssm(SCI_REGISTERIMAGE, DECL_INTEGER, i_xpm)
ssm(SCI_REGISTERIMAGE, DECL_NAMESPACE, n_xpm)
ssm(SCI_REGISTERIMAGE, DECL_OBJECT, o_xpm)
ssm(SCI_REGISTERIMAGE, DECL_PROCEDURE, p_xpm)
ssm(SCI_REGISTERIMAGE, DECL_SEQUENCE, s_xpm)
ssm(SCI_REGISTERIMAGE, DECL_TYPE, t_xpm)
ssm(SCI_INDICSETSTYLE, 3, INDIC_SQUIGGLE)
ssm(SCI_INDICSETFORE, 3, BrightRed)
ssm(SCI_SETINDICATORCURRENT, 3)
ssm(SCI_SETMOUSEDWELLTIME, 500) -- milliseconds
end procedure
global procedure reinit_all_edits()
atom saved_hedit
saved_hedit = hedit
for i = 1 to length(tab_hedits) do
init_edit(tab_hedits[i])
end for
hedit = saved_hedit
end procedure
procedure auto_detect_indent(sequence text)
integer i = 0, indent = 0, last = 0, tabs_used = 0, spaces_used = 0
integer cr = 0, crlf = 0, lf = 0
sequence indents = repeat(0, 8)
while i < length(text) do
i += 1
-- count spaces and tabs
if text[i] = ' ' then
indent += 1
if remainder(indent, tab_width) = 0 then
spaces_used += 1
end if
continue
end if
if text[i] = '\t' then
indent += tab_width - remainder(indent, tab_width)
tabs_used += 1
continue
end if
-- record positive indents
if indent - last >= 1 and indent - last <= length(indents) then
indents[indent - last] += 1
end if
last = indent
indent = 0
-- scan to end of line and count eol styles
while i <= length(text) do
if text[i] = '\r' then -- cr
if i < length(text) and text[i+1] = '\n' then -- crlf
i += 1
crlf += 1
else
cr += 1
end if
exit
elsif text[i] = '\n' then -- lf
lf += 1
if i < length(text) and text[i+1] = '\r' then -- lfcr - not counted
i += 1
end if
exit
end if
i += 1
end while
end while
-- pick the max used indent size
indent = 1
for x = 2 to length(indents) do
if indents[x] > indents[indent] then
indent = x
end if
end for
ssm(SCI_SETINDENT, indent)
ssm(SCI_SETUSETABS, tabs_used > spaces_used)
-- pick the most used eol style
if cr > crlf and cr > lf then
ssm(SCI_SETEOLMODE, SC_EOL_CR)
elsif crlf > cr and crlf > lf then
ssm(SCI_SETEOLMODE, SC_EOL_CRLF)
elsif lf > cr and lf > crlf then
ssm(SCI_SETEOLMODE, SC_EOL_LF)
end if
end procedure
-- pos is integer position in current tab, or {"filename", pos}
-- note: first character in document is at pos=1
global procedure goto_pos(object pos, integer len=0)
sequence prev = {ssm(SCI_GETCURRENTPOS),
ssm(SCI_GETFIRSTVISIBLELINE)}
if sequence(pos) then
sequence prev_file = file_name
if open_file(pos[1], 0) = 0 then
return -- file not found
end if
pos = pos[2]
if not equal(file_name, prev_file) then
-- open_file probably changed the current_tab
prev &= {prev_file}
end if
end if
tab_pos_stack[current_tab] &= {prev}
pos -= 1
ssm(SCI_SETANCHOR, pos)
ssm(SCI_SETCURRENTPOS, pos + len)
set_top_line(-1)
end procedure
-- restore the previous cursor and scroll position,
-- or clear the selection or autocompletion if there is one
global procedure go_back()
object pos = ssm(SCI_GETCURRENTPOS)
-- clear any active autocomplete, and return
-- cancel any active call tip, and return
if ssm(SCI_AUTOCACTIVE) or ssm(SCI_CALLTIPACTIVE) then
ssm(SCI_AUTOCCANCEL)
ssm(SCI_CALLTIPCANCEL)
calltip_pos = -1
calltip_stack = {}
return
end if
-- clear any selection, and return
if pos != ssm(SCI_GETANCHOR) then
ssm(SCI_SETEMPTYSELECTION, pos)
return
end if
if length(tab_pos_stack[current_tab]) = 0 then
return -- empty stack
end if
-- get the last {pos,top_line,[filename]} on stack, and remove it
pos = tab_pos_stack[current_tab][$]
tab_pos_stack[current_tab] = tab_pos_stack[current_tab][1..$-1]
if sequence(pos) and length(pos) >= 3 then
if length(pos[3]) = 0 then