-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk.filesettings
272 lines (249 loc) · 11 KB
/
k.filesettings
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
#!lua
--
-- Copyright 2015-2019 by Kevin L. Goodwin [[email protected]]; All rights reserved
--
-- This file is part of K.
--
-- K 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.
--
-- K 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 K. If not, see <http://www.gnu.org/licenses/>.
--
--[[
20070823 kgoodwin wrote
20080618 kgoodwin NB! K (editor core) directly accesses the contents of
this file's global ftype_map (see display.cpp)
20190208 kgoodwin FnmToFType, ShebangToFType
--]]
-- print "hello 1"
do
--------------------------------------------------------------
local shebangToFType_ = {
perl6 = "perl",
python2 = "python",
python3 = "python",
}
function ShebangToFType( shebang ) -- called from C++ !!! DO NOT RENAME!!! CHANGE WITH CAUTION!
return shebangToFType_[shebang] or shebang
end
--------------------------------------------------------------
local nxToFType_ = { -- keep sorted by value (FType)
["CMakeLists.txt"] = "cmake" ,
["k.luaedit" ] = "lua" ,
["makefile" ] = "make" ,
["GNUmakefile" ] = "make" ,
["Makefile" ] = "make" ,
}
local nxToFType_patterns = { -- keep sorted by value (FType)
-- startsWith
["^\.bash" ] = "bash" ,
["^Dockerfile" ] = "bash" , -- https://stackoverflow.com/questions/26077543/how-to-name-dockerfiles
["^SConstruct" ] = "python" , -- https://scons.org/doc/production/HTML/scons-man.html
["^SConscript" ] = "python" , -- https://scons.org/doc/production/HTML/scons-man.html
-- endsWith
["makefile$" ] = "make" ,
["Makefile$" ] = "make" ,
}
local exToFType_ = { -- keep sorted by value (FType)
asm = "asm" ,
inc = "asm" ,
s = "asm" ,
twk = "awk" ,
gawk = "awk" ,
kxt = "awk" ,
awk = "awk" ,
kxl = "awk" ,
twl = "awk" ,
csh = "bash" ,
tcsh = "bash" ,
bash = "bash" ,
fish = "bash" ,
sh = "bash" ,
zsh = "bash" ,
ksh = "bash" ,
hxx = "clang" ,
kh = "clang" ,
h = "clang" ,
kc = "clang" ,
hpp = "clang" ,
cxx = "clang" ,
cs = "clang" ,
go = "clang" , -- odd as it seems, this works pretty well
groovy = "clang" , -- odd as it seems, this works pretty well; even for """triple double quoted strings"""!
java = "clang" , -- odd as it seems, this works pretty well
json = "clang" , -- odd as it seems, this works pretty well
painless = "clang" , -- odd as it seems, this works pretty well (groovy-like elastisearch-only scripting language)
m = "clang" ,
cpp = "clang" ,
cc = "clang" ,
c = "clang" ,
go = "clang" ,
cmake = "cmake" ,
diff = "diff" ,
expect = "expect" ,
tcl = "expect" ,
kdb = "kdb" ,
krsrc = "krsrc" ,
log = "log" ,
lua = "lua" ,
mak = "make" ,
conf = "make" ,
mik = "make" ,
mak = "make" ,
make = "make" ,
md = "markdown" ,
mod = "modula2" ,
def = "modula2" ,
cmd = "msbatch" ,
bat = "msbatch" ,
pas = "pascal" ,
dpr = "pascal" ,
pl = "perl" ,
pm = "perl" ,
perl = "perl" ,
ps1 = "pwrshell" , -- https://stackoverflow.com/a/12108746
psm1 = "pwrshell" , -- https://stackoverflow.com/a/12108746
psd1 = "pwrshell" , -- https://stackoverflow.com/a/12108746
python = "python" ,
python3 = "python" ,
py = "python" ,
spa = "sprintascii" ,
psql = "sql" ,
sql = "sql" ,
xml = "xml" ,
html = "xml" ,
htm = "xml" ,
dtd = "xml" ,
tex = "tex" ,
}
function FnmToFType( nx ) -- called from C++ !!! DO NOT RENAME!!! CHANGE WITH CAUTION!
-- printf( "k.f.FnmToFType(%s)", nx or "(nil)" )
if nx and nxToFType_[nx] then
local rv = nxToFType_[nx] -- printf( "k.f.FnmToFType(%s) => %s", nx, rv )
return rv
end
for pat,rv in pairs( nxToFType_patterns ) do -- printf( "k.f.FnmToFType(%s) nx.pat=%s", nx, pat )
if string.match( nx, pat ) then -- printf( "k.f.FnmToFType(%s) nx.pat=%s => %s", nx, pat, rv )
return rv
end
end
local ex = ExtOf( nx ) -- printf( "k.f.FnmToFType(%s) ex=%s", nx, ex or "(nil)" )
if ex and exToFType_[ex] then
local rv = exToFType_[ex] -- printf( "k.f.FnmToFType(%s) ex=%s => %s", nx, ex, rv )
return rv
end
-- local nm = NameOf( nx ) printf( "k.f.FnmToFType(%s) -> %s,%s", nx,nm,ex )
return
end
end
printf( "%s", string.match( 'foobar', "foo" ) )
--printf( "%s", ExtOf( "nx.ex" ) )
local function bfg(bg,fg) return bg*16 + fg end
local function proto( base, tb )
setmetatable( tb, { __index = base } )
return tb
end
local Black = 0
local Blue = 1
local Green = 2
local Cyan = 3
local Red = 4
local Purple = 5
local Yellow = 6
local White = 7
local INTENSE = 8
local Gray = INTENSE + Black
local hiBlue = INTENSE + Blue
local hiGreen = INTENSE + Green
local hiCyan = INTENSE + Cyan
local hiRed = INTENSE + Red
local hiPink = INTENSE + Purple
local hiYellow = INTENSE + Yellow
local hiWhite = INTENSE + White
-- hack: on the Windows PC's I use, non-INTENSE colors (EX: Green) tend to be too dark, -> barely visible
local intifwin = OsName()=="win32" and function( color ) return INTENSE + (color % INTENSE) end or function( color ) return color end
local stdColors = {
txt = bfg( Blue , hiYellow ),
cxy = bfg( Purple , hiYellow ),
cxy = bfg( Cyan , hiYellow ),
cpp = bfg( Gray , hiWhite ),
hil = bfg( Cyan , hiWhite ),
sel = bfg( Green , hiWhite ),
wuc = bfg( hiWhite , Cyan ),
com = bfg( Blue , hiGreen ),
str = bfg( Blue , hiPink ),
str = bfg( Green , hiCyan ),
str = bfg( Black , hiRed ),
str = bfg( Black , hiCyan ),
}
local darkColors = {
txt = bfg( Black , White ),
txt = bfg( Black , hiGreen ),
txt = bfg( Black , intifwin( Green ) ),
cxy = bfg( Blue , hiYellow ),
cpp = bfg( Red , hiWhite ),
hil = bfg( Cyan , hiWhite ),
sel = bfg( Green , hiWhite ),
wuc = bfg( Cyan , Black ),
wuc = bfg( Cyan , White ),
com = bfg( Black , Green ),
com = bfg( Black , Yellow ),
com = bfg( Black , White ),
str = bfg( Gray , Black ),
str = bfg( Black , Red ),
str = bfg( Black , hiCyan ),
str = bfg( Black , hiRed ),
}
--------------------------------------------------
local text_settings = { colors = darkColors }
local tex_settings = { colors = darkColors, eolCommentDelim = "%" }
local krsrc_settings = { colors = darkColors, eolCommentDelim = "#" }
local sprintascii_settings = { colors = darkColors, eolCommentDelim = ";;" } -- hack: eolCommentDelim is valid only at start of line
local diff_settings = { colors = stdColors, hilite = "diff" }
local bat_settings = { colors = stdColors, eolCommentDelim = "rem " }
local clang_settings = { colors = darkColors, hilite = "c" }
local expect_settings = { colors = DeepCopy(darkColors), hilite = "python" }
local lua_settings = { colors = DeepCopy(darkColors), hilite = "lua" }
-- lua_settings.colors.com = bfg( Blue, hiPink )
local python_settings = { colors = stdColors, hilite = "python" }
local perl_settings = { colors = darkColors, hilite = "python" }
local make_settings = { colors = darkColors, hilite = "make" }
local cmake_settings = { colors = darkColors, hilite = "bash" }
local ushell_settings= { colors = darkColors, hilite = "bash" }
local sql_settings = { colors = darkColors, hilite = "sql" }
local pwrshell_settings= { colors = darkColors, hilite = "pwrshell" }
ftype_map = { -- ref'd from C, key source: .krsrc ftype: setting
clang = clang_settings ,
awk = clang_settings ,
msbatch = bat_settings ,
lua = lua_settings ,
expect = expect_settings ,
perl = perl_settings ,
python = perl_settings ,
make = make_settings ,
cmake = cmake_settings ,
kdb = text_settings ,
krsrc = krsrc_settings ,
text = text_settings ,
sh = ushell_settings ,
bash = ushell_settings ,
sql = sql_settings ,
pwrshell = pwrshell_settings ,
pseudo = text_settings ,
unknown = text_settings ,
wildcard = ushell_settings ,
diff = diff_settings ,
sprintascii = sprintascii_settings ,
tex = tex_settings ,
[""] = { colors = stdColors } ,
}
print( ftype_map.clang and "ftype_map.clang DEFINED" or "ftype_map.clang UNdefined" )
print( "############################### k.filesettings execution complete ##########################" )