Scite 简单模板 |
|
假设您有几行用制表符分隔的值。每行将被分割(制表符)成多个值。例如
af Afghanistan za Afrique Du Sud al Albanie dz Alg�rie de Allemagne //ad Andorre ao Angola ai Anguilla aq Antarctique ag Antigua [...] fr France SELECTED [...] zw Zimbabwe
现在写下模板(可以是多行)。它必须出现在您的值之后。例如
<option value="<1>" <3>><2></option>
该脚本将自动复制并用您的值填充模板。它非常简单
仔细选择模板(从上到下)并运行脚本。生成的文本将插入到模板之后。例如
<option value="af" >Afghanistan</option> <option value="za" >Afrique Du Sud</option> <option value="al" >Albanie</option> <option value="dz" >Alg�rie</option> <option value="de" >Allemagne</option> <option value="ao" >Angola</option> <option value="ai" >Anguilla</option> <option value="aq" >Antarctique</option> <option value="ag" >Antigua,Et,Barbuda</option> [...] <option value="fr" SELECTED>France</option> [...] <option value="zw" >Zimbabwe</option>
如果您觉得它有用,以下是脚本
-- we assume the template definition is the current selection local template = editor:GetSelText() -- now duplicate and fill the template -- for each line before the template definition local lastline = editor:LineFromPosition(editor.SelectionStart)-1 local res = "" for index=0,lastline do local line = editor:GetLine(index) if string.len(line) > 2 and string.sub(line,1,2) ~= "//" then -- split tab separated columns local values = { ["<0>"] = index+1 } local i = 0 for p in string.gfind(line, "[^\t\r\n]+") do i = i+1 values["<"..i..">"] = p end -- fill template with values res = res..string.gsub(template, "(<%d+>)", function(p) return values[p] end) end end -- insert & select generated content editor:insert(editor.SelectionEnd, res) editor:SetSel(editor.SelectionEnd, -1)
我喜欢按 Alt+Shift+T 运行脚本
command.name.33.*=Templatization! command.mode.33.*=subsystem:lua,savebefore:no,groupundo command.shortcut.33.*=Alt+Shift+T command.33.*=dofile $(SciteDefaultHome)/lua/templatization.lua
--Philippe