This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
293 lines (278 loc) · 12.6 KB
/
init.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
-- Copyright 2007-2023 Mitchell. See LICENSE.
local M = {}
--[[ This comment is for LuaDoc.
---
-- The html module for Textadept.
-- It provides utilities for editing HTML code.
module('_M.html')]]
-- Load CSS Autocompletion and documentation.
if not _M.css then _M.css = require('css') end
-- Sets default buffer properties for CSS files.
events.connect(events.LEXER_LOADED, function(name)
if name ~= 'html' then return end
buffer.word_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-'
end)
-- Autocompletion and documentation.
local completion = '%s' .. string.char(buffer.auto_c_type_separator) .. '%d'
local XPM = textadept.editing.XPM_IMAGES
-- List of HTML tags available for autocompletion.
local tags = {
'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'article', 'aside', 'audio', 'b', 'base',
'basefont', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center',
'cite', 'code', 'col', 'colgroup', 'dd', 'del', 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'fieldset',
'figcaption', 'figure', 'font', 'footer', 'form', 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4',
'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins',
'isindex', 'kbd', 'label', 'legend', 'li', 'link', 'map', 'menu', 'meta', 'nav', 'noframes',
'noscript', 'object', 'ol', 'optgroup', 'option', 'p', 'param', 'pre', 'q', 's', 'samp', 'script',
'section', 'select', 'small', 'span', 'strike', 'strong', 'style', 'sub', 'sup', 'table', 'tbody',
'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'tt', 'u', 'ul', 'var', 'video'
}
for i = 1, #tags do tags[i] = completion:format(tags[i], XPM.CLASS) end
-- Map of attribute sets to their attribute lists.
local attr = {
core = {'class', 'id', 'style', 'title'}, lang = {'dir', 'lang', 'xml:lang'},
key = {'accesskey', 'tabindex'}
}
for _, attrs in pairs(attr) do
for i = 1, #attrs do attrs[i] = completion:format(attrs[i], XPM.SLOT) end
end
-- LuaFormatter off
-- Map of events to their attribute lists.
local event = {
form = {'onblur', 'onchange', 'onfocus', 'onreset', 'onselect', 'onsubmit'},
key = {'onkeydown', 'onkeypress', 'onkeyup'},
mouse = {
'onclick', 'ondblclick', 'onmousedown', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup'
}
}
-- LuaFormatter on
for _, events in pairs(event) do
for i = 1, #events do events[i] = completion:format(events[i], XPM.SIGNAL) end
end
-- LuaFormatter off
-- Map of tags to attributes available for autocompletion.
local attributes = {
a = {
'charset', 'coords', 'href', 'hreflang', 'name', 'rel', 'shape', 'target', attr.core, attr.lang,
attr.key, event.key, event.mouse, event.form
},
abbr = {attr.core, attr.lang, event.key, event.mouse},
acronym = {attr.core, attr.lang, event.key, event.mouse},
address = {attr.core, attr.lang, event.key, event.mouse},
applet = {
'code', 'object', 'align', 'alt', 'archive', 'codebase', 'height', 'hspace', 'name', 'vspace',
'width', attr.core
},
area = {
'alt', 'coords', 'href', 'nohref', 'shape', 'target', attr.core, attr.lang, attr.key, event.key,
event.mouse, event.form
},
article = {attr.core, attr.lang, event.key, event.mouse},
aside = {attr.core, attr.lang, event.key, event.mouse},
audio = {attr.core, attr.lang, event.key, event.mouse},
b = {attr.core, attr.lang, event.key, event.mouse},
base = {'href', 'target'},
basefont = {'color', 'face', 'size', attr.core, attr.lang},
bdo = {'dir', attr.core, attr.lang},
big = {attr.core, attr.lang, event.key, event.mouse},
blockquote = {'cite', attr.core, attr.lang, event.key, event.mouse},
body = {'onload', 'onunload', 'alink', 'background', 'bgcolor', 'link', 'text', 'vlink'},
br = {attr.core},
button = {
'disabled', 'name', 'type', 'value', attr.core, attr.lang, attr.key, event.key, event.mouse,
event.form
},
canvas = {attr.core, attr.lang, event.key, event.mouse},
caption = {'align', attr.core, attr.lang, event.key, event.mouse},
center = {attr.core, attr.lang, event.key, event.mouse},
cite = {attr.core, attr.lang, event.key, event.mouse},
code = {attr.core, attr.lang, event.key, event.mouse},
col = {
'align', 'char', 'charoff', 'span', 'valign', 'width', attr.core, attr.lang, event.key,
event.mouse
},
colgroup = {
'align', 'char', 'charoff', 'span', 'valign', 'width', attr.core, attr.lang, event.key,
event.mouse
},
dd = {attr.core, attr.lang, event.key, event.mouse},
del = {attr.core, attr.lang, event.key, event.mouse},
dfn = {attr.core, attr.lang, event.key, event.mouse},
dir = {attr.core, attr.lang, event.key, event.mouse},
div = {attr.core, attr.lang, event.key, event.mouse},
dl = {attr.core, attr.lang, event.key, event.mouse},
dt = {attr.core, attr.lang, event.key, event.mouse},
em = {attr.core, attr.lang, event.key, event.mouse},
fieldset = {attr.core, attr.lang, event.key, event.mouse},
figcaption = {attr.core, attr.lang, event.key, event.mouse},
figure = {attr.core, attr.lang, event.key, event.mouse},
font = {'color', 'face', 'size', attr.core, attr.lang},
footer = {attr.core, attr.lang, event.key, event.mouse},
form = {
'action', 'accept', 'accept-charset', 'enctype', 'method', 'name', 'target', attr.core,
attr.lang, event.key, event.mouse
},
frame = {
'frameborder', 'longdesc', 'marginheight', 'marginwidth', 'name', 'noresize', 'scrolling',
'src', attr.core
},
frameset = {'cols', 'rows', attr.core, attr.lang},
head = {'profile', attr.lang},
h1 = {'align', attr.core, attr.lang, event.key, event.mouse},
h2 = {'align', attr.core, attr.lang, event.key, event.mouse},
h3 = {'align', attr.core, attr.lang, event.key, event.mouse},
h4 = {'align', attr.core, attr.lang, event.key, event.mouse},
h5 = {'align', attr.core, attr.lang, event.key, event.mouse},
h6 = {'align', attr.core, attr.lang, event.key, event.mouse},
header = {attr.core, attr.lang, event.key, event.mouse},
hgroup = {attr.core, attr.lang, event.key, event.mouse},
hr = {'align', 'noshade', 'size', 'width', attr.core},
html = {'xmlns', attr.lang},
i = {attr.core, attr.lang, event.key, event.mouse},
iframe = {
'align', 'frameborder', 'height', 'longdesc', 'marginheight', 'marginwidth', 'name',
'scrolling', 'src', 'width', attr.core
},
img = {
'onabort', 'alt', 'src', 'align', 'border', 'height', 'hspace', 'ismap', 'longdesc', 'usemap',
'vspace', 'width', attr.core, attr.lang, event.key, event.mouse
},
input = {
'accept', 'align', 'alt', 'checked', 'disabled', 'maxlength', 'name', 'readonly', 'size', 'src',
'type', 'value', attr.core, attr.lang, attr.key, event.key, event.mouse, event.form
},
ins = {'cite', 'datetime', attr.core, attr.lang, event.key, event.mouse},
isindex = {attr.core, attr.lang, event.key, event.mouse},
kbd = {attr.core, attr.lang, event.key, event.mouse},
label = {'for', attr.core, attr.lang, attr.key, event.key, event.mouse, event.form},
legend = {'align', attr.core, attr.lang, attr.key, event.key, event.mouse},
li = {'type', 'value', attr.core, attr.lang, event.key, event.mouse},
link = {
'charset', 'href', 'hreflang', 'media', 'rel', 'rev', 'target', 'type', attr.core, attr.lang,
event.key, event.mouse
},
map = {'name', attr.core, attr.lang, event.key, event.mouse},
menu = {'compact', attr.core, attr.lang, event.key, event.mouse},
meta = {'content', 'http-equiv', 'name', 'scheme', attr.lang},
nav = {attr.core, attr.lang, event.key, event.mouse},
noframes = {attr.core, attr.lang, event.key, event.mouse},
noscript = {attr.core, attr.lang, event.key, event.mouse},
object = {
'align', 'archive', 'border', 'classid', 'codebase', 'codetype', 'data', 'declare', 'height',
'hspace', 'name', 'standby', 'type', 'usemap', 'vspace', 'width', attr.core, attr.lang,
attr.key, event.key, event.mouse
},
ol = {'compact', 'start', 'type', attr.core, attr.lang, event.key, event.mouse},
optgroup = {'label', 'disabled', attr.core, attr.lang, event.key, event.mouse},
option = {'disabled', 'label', 'selected', 'value', attr.core, attr.lang, event.key, event.mouse},
p = {'align', attr.core, attr.lang, event.key, event.mouse},
param = {'name', 'type', 'value', 'valuetype', 'id'},
pre = {'width', attr.core, attr.lang, event.key, event.mouse},
q = {'cite', attr.core, attr.lang, event.key, event.mouse},
s = {attr.core, attr.lang, event.key, event.mouse},
samp = {attr.core, attr.lang, event.key, event.mouse},
script = {'type', 'charset', 'defer', 'src', 'xml:space'},
section = {attr.core, attr.lang, event.key, event.mouse},
select = {
'disabled', 'multiple', 'name', 'size', attr.core, attr.lang, attr.key, event.key, event.mouse,
event.form
},
small = {attr.core, attr.lang, event.key, event.mouse},
span = {attr.core, attr.lang, event.key, event.mouse},
strike = {attr.core, attr.lang, event.key, event.mouse},
strong = {attr.core, attr.lang, event.key, event.mouse},
style = {'type', 'media', attr.core, attr.lang},
sub = {attr.core, attr.lang, event.key, event.mouse},
sup = {attr.core, attr.lang, event.key, event.mouse},
table = {
'align', 'bgcolor', 'border', 'cellpadding', 'cellspacing', 'frame', 'rules', 'summary',
'width', attr.core, attr.lang, event.key, event.mouse
},
tbody = {'align', 'char', 'charoff', 'valign', attr.core, attr.lang, event.key, event.mouse},
td = {
'abbr', 'align', 'axis', 'bgcolor', 'char', 'charoff', 'colspan', 'headers', 'height', 'nowrap',
'rowspan', 'scope', 'valign', 'width', attr.core, attr.lang, event.key, event.mouse
},
textarea = {
'cols', 'rows', 'disabled', 'name', 'readonly', attr.core, attr.lang, attr.key, event.key,
event.mouse, event.form
},
tfoot = {'align', 'char', 'charoff', 'valign', attr.core, attr.lang, event.key, event.mouse},
th = {
'abbr', 'align', 'axis', 'bgcolor', 'char', 'charoff', 'colspan', 'height', 'nowrap', 'rowspan',
'scope', 'valign', 'width', attr.core, attr.lang, event.key, event.mouse
},
thead = {'align', 'char', 'charoff', 'valign', attr.core, attr.lang, event.key, event.mouse},
time = {attr.core, attr.lang, event.key, event.mouse},
title = {attr.lang},
tr = {
'align', 'bgcolor', 'char', 'charoff', 'valign', attr.core, attr.lang, event.key, event.mouse
},
tt = {attr.core, attr.lang, event.key, event.mouse},
u = {attr.core, attr.lang, event.key, event.mouse},
ul = {'compact', 'type', attr.core, attr.lang, event.key, event.mouse},
var = {attr.core, attr.lang, event.key, event.mouse},
video = {attr.core, attr.lang, event.key, event.mouse}
}
-- LuaFormatter on
for _, attrs in pairs(attributes) do
for i, attr in ipairs(attrs) do
if type(attr) ~= 'string' then goto continue end
attrs[i] = completion:format(attr, XPM.METHOD)
::continue::
end
end
textadept.editing.autocompleters.html = function()
local list = {}
-- Retrieve the symbol behind the caret and determine whether it is a tag or a tag attribute.
local line, pos = buffer:get_cur_line()
line = line:sub(1, pos - 1)
if line:find('>[^<]*$') then return nil end -- outside tag
if line:find('<([%w:]*)$') then
-- Autocomplete tag.
local part = line:match('<([%w:]*)$')
local name = '^' .. part
for _, tag in ipairs(tags) do if tag:find(name) then list[#list + 1] = tag end end
return #part, list
else
-- Autocomplete attribute.
local symbol, part = line:match('<([%w:]+)[^<>]-([%w:]*)$')
if not symbol and not part then
-- Look back for an open tag.
for i = buffer:line_from_position(buffer.current_pos) - 1, 1, -1 do
local prev_line = buffer:get_line(i)
if prev_line:find('>[^<]*$') then break end
symbol = prev_line:match('<(%w+)[^>]*$')
if symbol then break end
end
if not symbol then return nil end
part = line:match('([%w:]*)$')
end
local name, attrs = '^' .. part, attributes[symbol]
if attrs then
for _, attr in ipairs(attrs) do
if type(attr) == 'string' then
if attr:find(name) then list[#list + 1] = attr end
else
for _, attr in ipairs(attr) do if attr:find(name) then list[#list + 1] = attr end end
end
end
end
return #part, list
end
end
textadept.editing.api_files.html = {_HOME .. '/modules/html/api', _USERHOME .. '/modules/html/api'}
-- Snippets.
local snip = snippets.html
snip.c = '<!-- %0 -->'
snip['<'] = '<%1(div)>\n\t%0\n</%1>'
snip.divc = '<div class="%1">\n\t%0\n</div>'
snip.divi = '<div id="%1">\n\t%0\n</div>'
snip.br = '<br />\n%0'
snip.table = '<table class="%1">\n\t<tr>\n\t\t<th>%0</th>\n\t</tr>\n</table>'
snip.td = '<td>%0</td>'
snip.tr = '<tr>\n\t%0\n</tr>'
snip.ulc = '<ul class="%1(list)">\n\t%0\n</ul>'
snip.ul = '<ul>\n\t%0\n</ul>'
snip.li = '<li>%0</li>'
return M