-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSciTE.lua
2658 lines (2476 loc) · 102 KB
/
SciTE.lua
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
-- ***Welcome***
-- An experimental setup for SciTE with the following aims:
-- Remove dependency upon binary addins - i.e. DLLs
-- Minimal use of external tools - annotated with **
-- Remove extman dependency
-- Maximise Lua customisation
-- Custom OnKey handler - catches all key presses outside menu and dialog boxes
-- Custom OnDoubleClick handler - action dependent upon indicators
-- Short function names for use in a Command Strip
-- Replace as many floating dialogs as possible - with strips
-- Consistent UI for strips
-- Only one visible strip at a time - is proving difficult!
-- Remember last entry - across buffers
-- Repeat with enter
-- Dismiss with esc
-- Platform for my extensions to the string library for modal/macro editing
-- See scite.Block* functions
-- Expected directory structure
-- SciteDefaultHome
-- confSciTE/mac Macros
-- confSciTE/mod Modified properties files
-- ctags
-- dictionary
-- help
-- history
-- hunspell
-- insertions
-- snippets
-- templates
-- View this file with all folds closed and it make more sense
require("extensions") -- Simple additions to Lua for Command Strip
-- ***Modifications for Lua version***
if not loadstring then
-- Make loadstring -- Assume Scite >=4.4.4 i.e. Lua 5.3
loadstring = load
else
-- Make scite constants -- Assume Scite 3.7.5 i.e. Lua 5.1
for i=1,5050 do
if pcall(scite.ConstantName,i) then
_G[scite.ConstantName(i)]=tonumber(i)
end
end
end
-- ***Extensions to Lua***
-- Overloading of the Lua Standard Libraries may be considered tasteless https://stackoverflow.com/a/2032066
function string.split(text, sep) -- Everybody need this!
-- Splits for a single character e.g. , or /
-- https://stackoverflow.com/questions/1426954/split-string-in-lua
if sep == nil then
sep = "%s"
end
local t={}
local i=1
for str in string.gmatch(text, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
if i>1 then
return t
else
return text
end
end
function table.dedup(t) -- Remove table duplicates
-- Remove duplicate v
local hash = {}
local res = {}
for _,v in ipairs(t) do
v = string.lower(v)
if (not hash[v]) then
res[#res+1] = v -- you could print here instead of saving to result table if you wanted
hash[v] = true
end
end
return res
end
function table.length(t) -- Length of array/table
local count = 0
for _ in pairs(t) do count = count + 1 end
return count
end
function os.datestamp(date1) -- Returns my date stamp e.g. 201507_28_70089
-- e.g. print(os.datestamp())
if date1 and date1~="" then
if os.datevalid(date1) then
local v, d, m, y = os.datevalid(date1)
return os.date("%Y%m_%d_",os.time({year=y,month=m,day=d}))
else
return nil
end
else
local t = os.date("*t",var)
local sec = ((t.hour*60*60)+(t.min*60)+(t.sec))
return os.date("%Y%m_%d_"..sec)
end
end
function io.exists(filename) -- Tests for file or directory
-- io.exists(filename or directory)
if type(filename)~="string" then
return false
end
return os.rename(filename,filename) and true or false
-- Source: http://stackoverflow.com/questions/4990990/lua-check-if-a-file-exists
end
function io.mkdir(path) -- Create directory - parent must exist!
-- io.mkdir(path) - an extension to create a directory absolute or relative
os.execute("mkdir " .. path)
end
function io.dir(dir) -- Returns the first 1000 files
-- Validate parameters
if type(dir)~="string" then return end
-- Check path ending
if string.find(dir,"*") or string.find(dir,"?") then
-- Do nothing assume full glob
else
if string.sub(dir,-1)==[[\]] then
dir = dir..[[*.*]] -- Ensure files are found
else
dir = dir..[[\*.*]] -- Assume this is a directory
end
end
local h = io.popen('dir "'..dir..'" /a-d/b/s ')
local ret = {}
for file in h:lines() do
table.insert(ret,file)
if #ret > 1000 then break end
end
h:flush()
h:close()
return ret
end
function debug.which(funcname) -- Returns the source file + line of the function
-- identifies the source for the current definition of funcname
-- designed for the console, has been modified to return a string
--
if type(funcname)~="function" then
return tostring(funcname).. ": is a "..type(funcname)
end
local info = _G.debug.getinfo(funcname)
if info.short_src=="[C]" then
return "Compiled "..info.short_src.." code:"
else
return info.short_src..":"..info.linedefined..":"
end
end
function math.toBIN(num) -- Return binary string
local t={}
while num>0 do
rest=math.fmod(num,2)
t[#t+1]=rest
num=math.floor((num-rest)/2) -- For Lua 5.1 compatible
end
return string.reverse(table.concat(t,""))
end
-- ***A pipeline of string functions to allow macros and modal editing***
-- These functions work on \n separated lines of text - THEY ARE NOT NORMAL LUA STRING FUNCTIONS
function string.pre(text,prefix) -- Prefix each line
-- Prefix each line, assume line or block selection
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return prefix..text:gsub("\n","\n"..prefix)
end
function string.post(text,postfix) -- Postfix each line
-- Postfix each line, assume line or block selection
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return text:gsub("\n",postfix.."\n")..postfix
end
function string.unpre(text,n) -- Remove n char prefix
-- UnPrefix each line, to n characters
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return text:gsub("\n"..string.rep(".",n),"\n"):gsub("^"..string.rep(".",n),"")
end
function string.unpost(text,n) -- Remove n char postfix
-- UnPostfix each line, assume line or block selection
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
string.rep(".",n)
return text:gsub(string.rep(".",n).."\n","\n")
end
function string.ltrim(text) -- Trim left each line
-- Left trim lines in multiline text
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return text:gsub("\n%s*", "\n"):gsub("^%s*", "")
end
function string.rtrim(text) -- Trim right each line
-- Left trim lines in multiline text
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return text:gsub("%s+\n", "\n"):gsub("%s+$", "")
end
function string.trim(s) -- Trim both each line
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return s:match('^%s*(.-)%s*$')
end
function string.pcase(text) -- Proper case
-- Convert to proper case http://lua-users.org/wiki/StringRecipes
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
local function tchelper(first, rest)
return first:upper()..rest:lower()
end
text = string.gsub(text, "(%a)([%w_']*)", tchelper)
return text
end
function string.wrap(text,left,right) -- Enclose text
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
-- This works for sel(), word(), line()
return text:gsub("^.",left.."%1"):gsub(".$","%1"..right)
end
function string.dedup(text) -- Remove duplicate lines
-- Removes duplicated lines delimited by \n
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
local function split(inputstr, sep)
-- Splits for a single character e.g. , or /
-- https://stackoverflow.com/questions/1426954/split-string-in-lua
if sep == nil then
sep = "%s"
end
local t={}
local i=1
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
t[i] = str
i = i + 1
end
if i>1 then
return t
else
return inputstr
end
end
local t = split(text,"\n")
local hash = {}
local res = {}
for _,v in ipairs(t) do
v = string.lower(v)
if (not hash[v]) then
res[#res+1] = v
hash[v] = true
end
end
return table.concat(res,"\n")
end
function string.del(text) -- Delete current selection
-- Send the "\b" delete signal unless test is the "\a" signal
if text=="\a" then
return "\a"
else
return "\b"
end
end
function string.sort(text,functionORtag)-- Sort lines with \n
-- This is sorting lines within a string containing \n EOL
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
-- Check for text
if not text or text=="" then return end
-- Make a table to sort
local t = string.split(text,"\n")
-- Check for function
if functionORtag and type(functionORtag)=="function" then
table.sort(t,functionORtag)
return table.concat(t,"\n")
end
if not functionORtag then
table.sort(t,function(a,b) return string.lower(a) < string.lower(b) end)
return table.concat(t,"\n")
end
if functionORtag and functionORtag=="chara" then
table.sort(t,function(a,b) return string.lower(a) < string.lower(b) end)
return table.concat(t,"\n")
end
if functionORtag and functionORtag=="chard" then
table.sort(t,function(a,b) return string.lower(a) > string.lower(b) end)
return table.concat(t,"\n")
end
if functionORtag and functionORtag=="inta" then
table.sort(t,function(a,b) return tonumber(string.match(a,"%d+")) < tonumber(string.match(b,"%d+")) end)
return table.concat(t,"\n")
end
if functionORtag and functionORtag=="intd" then
table.sort(t,function(a,b) return tonumber(string.match(a,"%d+")) > tonumber(string.match(b,"%d+")) end )
return table.concat(t,"\n")
end
end
function string.min(text) -- Removes empty lines
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
return text:gsub("\n\n","\n")
end
function string.sum(text) -- Find digits and add them up
-- Summate all digits in string
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
local sum = 0
-- This only finds decimals
-- for match in text:gmatch("%d+.%d+") do
-- https://stackoverflow.com/questions/6192137/how-to-write-this-regular-expression-in-lua
for match in text:gmatch("%f[%.%d]%d*%.?%d*%f[^%.%d%]]") do
sum = sum + tonumber(match)
end
return tostring(sum)
end
function string.eval(text,s) -- Run as Lua with text as variable
-- Evaluate parameter as lua
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
-- Pass text as no access to local variables within load
local f, err = loadstring("do local text= [["..text.."]] "..s.." end")
if type(f)=="function" then
return f()
end
end
function string.call(text,f) -- Call function with text as parameter
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
if type(f)=="function" then
return f(text)
end
end
function string.iff(text,...) -- Conditional execution
-- Conditional execution using the "\a" abandon signal
if text=="\b" or text=="\a" then
return text
end
-- Variadic form send text if any match of arg in text
local arg={...}
if #arg<1 then
return nil
end
for _,v in pairs(arg) do
if text:match(v) then
return text
end
end
-- Fall through
return "\a"
end
function string.iffnot(text,...) -- Conditional execution
-- Variadic form send "\a" if all values of arg match text
-- Check for conditional execution
if text=="\b" or text=="\a" then
return text
end
local arg={...}
if #arg<1 then
return nil
end
local ret = 0
for i,v in pairs(arg) do
if text:match(v) then
ret = ret + 1
end
end
if ret==#arg then
return "\a"
end
-- Fall through
return text
end
-- Start a string processing pipe in SciTE:
function sel() -- Return current selection
-- Return the current selection with \n for EOL
local text, len = editor:GetSelText()
-- Do not default to line as we will use sel() as a test for a selection
if not text or len<1 then
return nil
end
-- Convert EOL to \n
text = text:gsub("\r?\n\r?", "\n")
-- We will convert back in string.ins()
-- editor:BeginUndoAction() -- This is paired with the string.ins()
return text
end
function word() -- Select and return current word forwards
local function isWordChar(char)
local strChar = string.char(char)
local beginIndex = string.find(strChar, '%w')
if beginIndex ~= nil then
return true
end
if strChar == '_' or strChar == '$' then
return true
end
return false
end
local beginPos = editor.CurrentPos
local endPos = beginPos
if editor.SelectionStart ~= editor.SelectionEnd then
return editor:GetSelText()
end
while isWordChar(editor.CharAt[beginPos-1]) do
beginPos = beginPos - 1
end
while isWordChar(editor.CharAt[endPos]) do
endPos = endPos + 1
end
editor:SetSel(beginPos,endPos)
local text = sel()
return text
end
function drow() -- Select and return current word backwards
local function isWordChar(char)
local strChar = string.char(char)
local beginIndex = string.find(strChar, '%w')
if beginIndex ~= nil then
return true
end
if strChar == '_' or strChar == '$' then
return true
end
return false
end
local beginPos = editor.CurrentPos
local endPos = beginPos
if editor.SelectionStart ~= editor.SelectionEnd then
return editor:GetSelText()
end
while isWordChar(editor.CharAt[beginPos-1]) do
beginPos = beginPos - 1
end
while isWordChar(editor.CharAt[endPos]) do
endPos = endPos + 1
end
editor:SetSel(endPos,beginPos)
local text = sel()
return text
end
function block() -- Select and return current block
scite.BlockSelect()
local text = sel()
return text
end
function line() -- Select and return current/next line
-- Use the current line
scite.SendEditor(SCI_HOME)
scite.SendEditor(SCI_LINEENDEXTEND)
local text = sel()
return text
end
function para() -- Select and return current paragraph
-- Use the current paragraph
scite.SendEditor(SCI_PARAUP)
scite.SendEditor(SCI_PARADOWNEXTEND)
scite.SendEditor(SCI_CHARLEFTEXTEND)
scite.SendEditor(SCI_CHARLEFTEXTEND)
-- Note this selects upto the next para
local text = sel()
return text
end
function rest() -- Select and return to EOF
-- Select down to EOF
scite.SendEditor(SCI_DOCUMENTENDEXTEND)
local text = sel()
return text
end
function above() -- Select and return to BOF
-- Select upto BOF
scite.SendEditor(SCI_DOCUMENTSTARTEXTEND)
local text = sel()
return text
end
function all() -- Select and return all
-- Select the whole buffer
scite.SendEditor(SCI_SELECTALL)
local text = sel()
return text
end
-- Midstream function to send text to output window in SciTE:
function string.trace(text) -- Print to output text from pipe or alternate
-- Intercept \a abandon command
if text=="\a" then
return
end
-- Intercept \b - delete command - ignore
if text=="\b" then
return
end
-- Insert the text
output:AddText(text)
return text
end
-- End a string processing pipe in SciTE:
function string.ins(text,text2) -- Insert text from pipe or alternate
-- Intercept \a abandon command
if text=="\a" then
if text2 then
-- We will insert text2
text = text2
else
return
end
end
-- Intercept \b - delete command
if text=="\b" then
if not editor:GetSelText() then
return
else
scite.MenuCommand(IDM_CLEAR)
return
end
end
-- Remember selection
local start, finish = editor.SelectionStart, editor.SelectionEnd
-- Delete selection
if not editor:GetSelText() then
return
else
scite.MenuCommand(IDM_CLEAR)
end
-- Insert the text at the cursor
editor:AddText(text)
-- Reselect text
editor:SetSelection(start+string.len(text), start)
-- Convert back the EOLs
scite.MenuCommand(IDM_EOL_CONVERT)
end
function string.clip(text) -- Load clipboard
-- EOL ??
-- Copy result to clipboard
if text then
editor:CopyText(text)
end
-- editor:EndUndoAction()
end
-- ***Additional lua functions in SciTE***
function ins(text) -- Insert text at current position
editor:AddText(text)
end
function del() -- Delete selection
scite.MenuCommand(IDM_CLEAR)
end
function paste() -- Inserts clipboard contents
editor:paste()
end
function copy(text) -- Copy text/variable text to clipboard
-- EOL ??
-- Copy result to clipboard
if text then
editor:CopyText(text)
end
end
function SetClipboard(text) -- Renamed function for consistency
copy(text)
end
function GetClipboard() -- Return the contents of the clipboard
local file = io.popen("paste.exe", "r")
local contents = file:read'*a'
file:flush()
file:close()
return contents
end
function find(text,flags) -- Also highlight text if found
if not text then return end
if not flags then
flags = 0 -- Alter if you want regex as default
-- SCFIND_NONE
-- SCFIND_MATCHCASE
-- SCFIND_WHOLEWORD
-- SCFIND_WORDSTART
-- SCFIND_REGEXP
-- SCFIND_POSIX
end
-- Set anchor
editor:SearchAnchor()
-- Do find
local start,finish = editor:findtext(text, flags, editor.CurrentPos)
if start then
-- Reverse selection to allow repeats
editor:SetSelection(finish,start)
-- Unfold into view
editor:EnsureVisible(editor:LineFromPosition(start))
-- Scroll into view
editor:ScrollCaret()
-- Store
local text = sel()
return text
else
return nil
end
end
-- ***Global tables***
scite.CommandExclusions = {} -- List of hidden functions in scite table
scite.KeyActions = {} -- Indexed store for Keyboard shortcuts
scite.ClickActions = {} -- Indexed store for DoubleClick events - not used yet
scite.UserListFunctions = {} -- Indexed store for OnUserList events
scite.DefaultDOSCache = { -- Preload your favourites here!
"dir /s/b",
"which CMD",
'shelexec.exe props["SciteDefaultHome"]',
'props["FileDir"]\\makeit.bat',
'props["FileDir"]\\ToDo.txt',
}
scite.DefaultLuaCache = { -- Preload your favourites here!
"for i,v in pairs(scite) do print(i,v) end",
}
-- ***"Super global variables"***
-- Are held in props for access from all buffers
-- ***New scite functions***
function scite.New(filename) -- Make a new file on disk
if io.exists(filename) then
scite.Open(filename)
return
end
-- Test for path TODO:
-- Make new empty file
-- Close and flush
-- Open this in scite
end
function scite.Colours(pal) -- Ignore this if you have your own colour settings
-- Load a colour palette from a table
-- Create a table for each palette using rgb hex values
-- scite.Colours()
local default = {
["colour.background"] ="#000000",
["colour.foreground"] ="#FFFFFF",
["fold.margin.colour"] ="#000000",
["fold.margin.highlight.colour"]="#000000",
["colour.red"] ="#FFFFFF",
["colour.green"] ="#FFFFFF",
["colour.blue"] ="#FFFFFF",
["colour.cyan"] ="#FFFFFF",
["colour.magenta"] ="#FFFFFF",
["colour.yellow"] ="#FFFFFF",
["caret.line.back.alpha"] =""
}
if type(pal)=="string" then
-- scite.Colours("Light")
if pal=="Light" then
pal = {
["colour.background"] ="#FFFFFF",
["colour.foreground"] ="#000000",
["fold.margin.colour"] ="#FFFFFF",
["fold.margin.highlight.colour"]="#FFFFFF",
["colour.red"] ="#7F0000",
["colour.green"] ="#007F00",
["colour.blue"] ="#00007F",
["colour.cyan"] ="#007F7F",
["colour.magenta"] ="#7F007F",
["colour.yellow"] ="#7F7F00",
["caret.line.back.alpha"] =""
}
end
if pal=="Dark" then
-- scite.Colours("Dark")
pal = {
["colour.background"] ="#000000",
["colour.foreground"] ="#FFFFFF",
["fold.margin.colour"] ="#000000",
["fold.margin.highlight.colour"]="#000000",
["colour.red"] ="#7F0000",
["colour.green"] ="#007F00",
["colour.blue"] ="#00007F",
["colour.blue"] ="#0000FF",
["colour.cyan"] ="#007F7F",
["colour.magenta"] ="#7F007F",
["colour.yellow"] ="#7F7F00",
["caret.line.back.alpha"] ="50"
}
end
if pal=="FTE" then
-- scite.Colours("FTE")
pal = {
["colour.background"] ="#004480",
["colour.foreground"] ="#c0c0c0",
["fold.margin.colour"] ="#004480",
["fold.margin.highlight.colour"]="#004480",
["colour.red"] ="#7F0000",
["colour.green"] ="#007F00",
["colour.blue"] ="#008080",
["colour.cyan"] ="#007F7F",
["colour.magenta"] ="#FF00FF",
["colour.yellow"] ="#7F7F00",
["caret.line.back.alpha"] ="50"
}
end
if pal=="Sol" then
-- scite.Colours("Sol")
pal = {
["colour.background"] ="#004480",
["colour.foreground"] ="#AFAEA3",
["fold.margin.colour"] ="#004480",
["fold.margin.highlight.colour"]="#004480",
["colour.red"] ="#DE3330",
["colour.green"] ="#869A01",
["colour.blue"] ="#278CD3",
["colour.cyan"] ="#2BA299",
["colour.magenta"] ="#D43883",
["colour.yellow"] ="#B68A01",
["caret.line.back.alpha"] ="50"
}
end
end
-- Load the selected palette
if type(pal)=="table" then
for i,v in pairs(pal) do
props[i]=v
end
else
for i,v in pairs(default) do
props[i]=v
end
print("Colour palette not found, using defaults!")
end
-- Map the colours to specific elements
props["colour.brace.highlight"] ="fore:"..props["colour.green"]
props["colour.brace.incomplete"] ="fore:"..props["colour.yellow"]
props["colour.code.comment.box"] ="fore:"..props["colour.green"]
props["colour.code.comment.line"] ="fore:"..props["colour.green"]
props["colour.code.comment.doc"] ="fore:"..props["colour.foreground"]
props["colour.code.comment.nested"] ="fore:"..props["colour.foreground"]
props["colour.text.comment"] ="fore:"..props["colour.blue"]
props["colour.other.comment"] ="fore:"..props["colour.green"]
props["colour.embedded.comment"] ="fore:"..props["colour.foreground"]
props["colour.embedded.js"] ="fore:"..props["colour.foreground"]
props["colour.notused"] ="back:"..props["colour.red"]
props["colour.number"] ="fore:"..props["colour.cyan"]
props["colour.keyword"] ="fore:"..props["colour.blue"]
props["colour.string"] ="fore:"..props["colour.magenta"]
props["colour.char"] ="fore:"..props["colour.magenta"]
props["colour.operator"] ="fore:"..props["colour.foreground"]
props["colour.preproc"] ="fore:"..props["colour.yellow"]
props["colour.error"] ="fore:"..props["colour.yellow"]
props["fold.back"] =props["colour.background"]
-- Refresh the current window - but not at startup when there is no editor window!
if props["FilePath"]~="" then
-- Set focus
scite.SendEditor(SCI_GRABFOCUS)
editor.Focus = true
-- Colourize
scite.SendEditor(SCI_COLOURISE,0, -1)
end
end
scite.Colours("Light") -- Remove this to leave your colours alone
function scite.Message(text) -- Single line message
if text then
scite.StripShow(" Message: "..text:gsub("\n"," "))
scite.SendEditor(SCI_GRABFOCUS)
end
end
function scite.CurrentWord(pos) -- Return Word Under Cursor without changing selection
if not pos then pos = editor.CurrentPos end
local p2 = editor:WordEndPosition(pos,true)
local p1 = editor:WordStartPosition(pos,true)
if p2 > p1 then
return editor:textrange(p1,p2)
end
end
function scite.CurrentLineNumber(pos) -- Return current editor line number
if not pos then pos = editor.CurrentPos end
return editor:LineFromPosition(pos)+1
end
function scite.BlockSelect() -- Smart block selection
-- Extends the selection to the whole contents of all lines partly selected.
-- This is needed because the line selection mode includes char 1 on the next line
-- Note it will work even for reverse selection.
-- If no selection select line
if editor.SelectionStart == editor.SelectionEnd then
return editor.SelectionStart, editor.SelectionStart
end
-- If reverse selection then reselect
if editor.SelectionStart > editor.SelectionEnd then
editor:SetSelection(editor.SelectionEnd,editor.SelectionStart)
end
-- If end col =1 then back to previous line
if props["SelectionEndColumn"]==1 then
editor:SetSelection(editor.SelectionStart,editor.SelectionEnd-1)
end
-- If start col ~= 1 then extend to start of line
if props["SelectionStartColumn"]~=1 then
editor:SetSelection(editor:PositionFromLine(editor:LineFromPosition(editor.SelectionStart)),editor.SelectionEnd)
end
-- If end col is not line end then extend
if editor:LineFromPosition(editor.SelectionEnd)==editor:LineFromPosition(editor.SelectionEnd+1) then
editor:SetSelection(editor.SelectionStart,editor:PositionFromLine(editor:LineFromPosition(editor.SelectionEnd)+1)-1)
end
return editor.SelectionStart, editor.SelectionEnd
end
function scite.GetCache(Name) -- Returns a table
local RS = string.char(30)
local t = string.split(props[Name],RS)
if type(t)~="table" then
return nil
else
return t
end
end
function scite.SetCache(Name,t) -- Stores an array
local RS = string.char(30)
props[Name]= table.concat(t,RS)
end
function scite.CloseStrips() -- TODO: close builtin strips
-- Close any single user strip
scite.StripShow("")
-- -- Close builtin strips
-- if props["ActiveUserStrip"]=="FindInc" then
-- scite.MenuCommand(IDM_INCSEARCH)
-- elseif props["ActiveUserStrip"]=="Find" then
-- scite.MenuCommand(IDM_FIND)
-- elseif props["ActiveUserStrip"]=="Replace" then
-- scite.MenuCommand(IDM_REPLACE)
-- else
-- print(props["ActiveUserStrip"])
-- end
props["ActiveUserStrip"] = ""
end
function scite.DefineTool(name,cmd,files,subsystem) -- Add a function to the tools menu
-- Validate parameters
-- if not name or type(name)~="string" then return end
-- if not cmd then return end
-- if not (type(cmd)=="function" or cmd:match("^dostring ")) then return end
if not files then files = "*" end
if not subsystem then subsystem = 3 end
-- Global to keep track of IDM number
IDMCount = IDMCount or 0
IDMCount = IDMCount + 1
if IDMCount > 49 then
print("Sorry there is a hard coded limit of 50 user defined tools.")
return
end
-- Create handle
local cmdHandle = "."..tostring(IDMCount).."."..files
-- Add to props
props["command.name"..cmdHandle] = name -- Overwrite previous commands
props["command"..cmdHandle] = cmd -- A single function name or dostring statement
props["command.subsystem"..cmdHandle] = subsystem -- Lua subsystem
props["command.mode"..cmdHandle] = "savebefore:no" -- Do it explicitly if necessary
end
function scite.LoadDic(fname) -- Load a list of words into an indexed table
if not io.exists(fname) then return end
local file = io.open(fname)
local words = {}
for line in io.lines(fname) do -- Expected input is one word per line!
if line and line~="" then -- Filter blank lines
words[line] = 1 -- Indexed for searching
end
end
return words
end
function scite.SetIndicator(tag) -- Define reusable indicators
if tag=="spelling" then -- For my spelling inidcators
local indic = 20
editor.IndicStyle[indic] = INDIC_SQUIGGLE
editor.IndicFore[indic] = 0x0000ff
editor.IndicAlpha[indic] = 100
editor.IndicOutlineAlpha[indic] = 100
-- editor.IndicFlags[indic] = SC_INDICFLAG_VALUEFORE
editor.IndicatorCurrent = indic
return indic
end
if tag=="word" then -- For my M+Ctrl+Editor marks
local indic = 21
editor.IndicStyle[indic] = INDIC_ROUNDBOX
editor.IndicFore[indic] = 0x1DCCAFF
editor.IndicAlpha[indic] = 100
editor.IndicOutlineAlpha[indic] = 100
-- editor.IndicFlags[indic] = SC_INDICFLAG_VALUEFORE
editor.IndicatorCurrent = indic
return indic
end
if tag=="found" then -- TODO: check this is the correct indic
local indic = 9
editor.IndicStyle[indic] = INDIC_ROUNDBOX
editor.IndicFore[indic] = 0x1DCCAFF
editor.IndicAlpha[indic] = 100
editor.IndicOutlineAlpha[indic] = 100
editor.IndicFlags[indic] = SC_INDICFLAG_VALUEFORE
editor.IndicatorCurrent = indic
return indic
end
end
function scite.Mark(target,mark) -- Marks all occurrences with indicator
-- Validate parameters
if not target then
return
end
if type(target)=="string" then
target = {target}
end
if type(target)~="table" then
return
end
-- Load predefined indicator properties
local indic = scite.SetIndicator(mark)
if not indic then
print("Unknown indicator mark : "..mark)
return
end