Napisałem pare skrypcików w LUA do SciTE, jeśli ktoś może ich użyć

skrypt 1:
Kod
function OnChar(ch)
local html_tags={
table=1,
td=1,
tr=1,
span=1,
div=1,
html=1,
font=1,
head=1,
body=1,
title=1,
style=1,
script=1,
center=1,
object=1,
a=1,
b=1,
i=1,
u=1,
p=1,
ul=1,
li=1,
option=1,
select=1,
textarea=1,
form=1,
}
editor:BeginUndoAction()
local nextchr=editor.CharAt[editor.CurrentPos]
local prevchr=editor.CharAt[editor.CurrentPos-2]
local od=0
local stos={}
local c_stos=0
local str_low
if ch=='/' and prevchr==60 and nextchr==62 then
local buf=editor:textrange(0, editor.CurrentPos-2)
while true do
local x, y, str=string.find(buf, "<([^ >]+)", od)
if not x then
if c_stos and stos[c_stos] then
editor:InsertText(-1, stos[c_stos])
editor:GotoPos(editor.CurrentPos+string.len(stos[c_stos])+1)
end
break
end
od=y+2
str_low=string.lower(str)
if string.sub(str_low, 1, 1)=="/" then
str_low=string.sub(str_low, 2, string.len(str_low))
if html_tags[str_low] and c_stos and stos[c_stos] then
if string.lower(stos[c_stos])==str_low then c_stos=c_stos-1 end
end
elseif html_tags[str_low] then
c_stos=c_stos+1
stos[c_stos]=str
end
end
elseif ch == '(' and nextchr ~= 41 then editor:InsertText(-1,')')
elseif ch == '{' and nextchr ~= 125 then editor:InsertText(-1,'}')
elseif ch == '[' and nextchr ~= 91 and prevchr ~=-59 then editor:InsertText(-1,']') --dlatego prevchr~=-59 bo się myliło z ś w uicodzie
elseif ch == '<' and nextchr ~= 62 then editor:InsertText(-1,'>')
elseif ch == '"' and nextchr ~= 34 then editor:InsertText(-1,'"')
elseif ch == '\'' and nextchr ~= 39 then editor:InsertText(-1,'\'')
end
editor:ScrollCaret()
editor:EndUndoAction()
end
local html_tags={
table=1,
td=1,
tr=1,
span=1,
div=1,
html=1,
font=1,
head=1,
body=1,
title=1,
style=1,
script=1,
center=1,
object=1,
a=1,
b=1,
i=1,
u=1,
p=1,
ul=1,
li=1,
option=1,
select=1,
textarea=1,
form=1,
}
editor:BeginUndoAction()
local nextchr=editor.CharAt[editor.CurrentPos]
local prevchr=editor.CharAt[editor.CurrentPos-2]
local od=0
local stos={}
local c_stos=0
local str_low
if ch=='/' and prevchr==60 and nextchr==62 then
local buf=editor:textrange(0, editor.CurrentPos-2)
while true do
local x, y, str=string.find(buf, "<([^ >]+)", od)
if not x then
if c_stos and stos[c_stos] then
editor:InsertText(-1, stos[c_stos])
editor:GotoPos(editor.CurrentPos+string.len(stos[c_stos])+1)
end
break
end
od=y+2
str_low=string.lower(str)
if string.sub(str_low, 1, 1)=="/" then
str_low=string.sub(str_low, 2, string.len(str_low))
if html_tags[str_low] and c_stos and stos[c_stos] then
if string.lower(stos[c_stos])==str_low then c_stos=c_stos-1 end
end
elseif html_tags[str_low] then
c_stos=c_stos+1
stos[c_stos]=str
end
end
elseif ch == '(' and nextchr ~= 41 then editor:InsertText(-1,')')
elseif ch == '{' and nextchr ~= 125 then editor:InsertText(-1,'}')
elseif ch == '[' and nextchr ~= 91 and prevchr ~=-59 then editor:InsertText(-1,']') --dlatego prevchr~=-59 bo się myliło z ś w uicodzie
elseif ch == '<' and nextchr ~= 62 then editor:InsertText(-1,'>')
elseif ch == '"' and nextchr ~= 34 then editor:InsertText(-1,'"')
elseif ch == '\'' and nextchr ~= 39 then editor:InsertText(-1,'\'')
end
editor:ScrollCaret()
editor:EndUndoAction()
end
oparty na zdażeniu OnChar - wywływany po każdym wpisanym znaku. Kruciutki opisik:
- automatycznie zamyka nawiasy i qouty (z wyjątkiem kiedy następny znak jest już zamkniętym nawiasem/quotą - jak w EdHTML)
- automatycznie zamyka niektóre (patrz tablica) taki htmla, gdy wpiszemy / pomiędzy < i >
drugi skrypcik to konwerter polskich znaków. Mój SciTE zawsze pracuje w trybie utf-8, i wkórza mnie kiedy wczytuje pliki w kodowaniu iso-8859-2 lub windows-1250 bo wyskakują nieprzyjemne krzaczki. Dzięk skrótą klawiszowym mogę te krzaczki przekonwercić na utf-8 a później przy zapisywniu spowrotem na bazowe kodowanie.
Kod
function convert(typek)
local arr_utf={
'\196\133', '\196\132',
'\196\135', '\196\134',
'\196\153', '\196\152',
'\197\130', '\197\129',
'\195\179', '\195\147',
'\197\155', '\197\154',
'\197\188', '\197\187',
'\197\186', '\197\185',
'\197\132', '\197\131',
}
local arr_win={
'\185', '\165',
'\230', '\198',
'\234', '\202',
'\179', '\163',
'\243', '\211',
'\156', '\140',
'\159', '\143',
'\191', '\175',
'\241', '\209',
}
local arr_iso={
'\177', '\161',
'\230', '\198',
'\234', '\202',
'\179', '\163',
'\243', '\211',
'\182', '\166',
'\188', '\166',
'\191', '\175',
'\241', '\209',
}
--change utf-8 into iso-8859-2
if (typek=="1") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), value, arr_iso[key]));
end
--change iso-8859-2 into utf-8
elseif (typek=="2") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), arr_iso[key], value));
end
--change utf-8 into windows-1250
elseif (typek=="3") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), value, arr_win[key]));
end
--change windows1250 into utf-8
elseif (typek=="4") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), arr_win[key], value));
end
end
end
local arr_utf={
'\196\133', '\196\132',
'\196\135', '\196\134',
'\196\153', '\196\152',
'\197\130', '\197\129',
'\195\179', '\195\147',
'\197\155', '\197\154',
'\197\188', '\197\187',
'\197\186', '\197\185',
'\197\132', '\197\131',
}
local arr_win={
'\185', '\165',
'\230', '\198',
'\234', '\202',
'\179', '\163',
'\243', '\211',
'\156', '\140',
'\159', '\143',
'\191', '\175',
'\241', '\209',
}
local arr_iso={
'\177', '\161',
'\230', '\198',
'\234', '\202',
'\179', '\163',
'\243', '\211',
'\182', '\166',
'\188', '\166',
'\191', '\175',
'\241', '\209',
}
--change utf-8 into iso-8859-2
if (typek=="1") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), value, arr_iso[key]));
end
--change iso-8859-2 into utf-8
elseif (typek=="2") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), arr_iso[key], value));
end
--change utf-8 into windows-1250
elseif (typek=="3") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), value, arr_win[key]));
end
--change windows1250 into utf-8
elseif (typek=="4") then
for key,value in arr_utf do
editor:SetText(string.gsub(editor:GetText(), arr_win[key], value));
end
end
end
są to proste 2 skrypciki które pomagają mi bardzo w pracy - mogą pomódz i Wam.
Jeżeli jesteś początkującym SciTEowcem to jeszcze parę żeby te skrypciki zadziałały:)
utórz skopiuj se te skrypciki do jakiegoś pliku, powiedzmt "my.lua".
skopiuj go do głównego katalogu SciTE.
w configu SciTE np (SciTEGlobal.properties) dopisz gdzies na początku:
Kod
ext.lua.startup.script=$(SciteDefaultHome)/my.lua
puźniej wklej te linijki (i zmodyfikuj do swoich potrzeb):
Kod
command.name.5.*=utf-8 2 iso-8859-2
command.subsystem.5.*=3
command.5.*=convert 1
command.save.before.5.*=2
command.name.6.*=iso-8859-2 to utf-8
command.subsystem.6.*=3
command.6.*=convert 2
command.save.before.6.*=2
command.name.7.*=utf-8 to windows-1250
command.subsystem.7.*=3
command.7.*=convert 3
command.save.before.7.*=2
command.name.8.*=winows-1250 to utf-8
command.subsystem.8.*=3
command.8.*=convert 4
command.save.before.8.*=2
command.subsystem.5.*=3
command.5.*=convert 1
command.save.before.5.*=2
command.name.6.*=iso-8859-2 to utf-8
command.subsystem.6.*=3
command.6.*=convert 2
command.save.before.6.*=2
command.name.7.*=utf-8 to windows-1250
command.subsystem.7.*=3
command.7.*=convert 3
command.save.before.7.*=2
command.name.8.*=winows-1250 to utf-8
command.subsystem.8.*=3
command.8.*=convert 4
command.save.before.8.*=2
teraz pod ctr+5 .. ctr+8 masz funkcje zmiany kodowania.
testowałem skrypciki pod SciTE 1.63 pod windowsa
dodatkowo dla wygody kożystam z niektórych scryptów do scite które znajdują się na strionie:
http://lua-users.org/wiki/SciteScripts
(polecam: "Tab-to-space and vice versa" i "SciteCleanDocWhitespace")
dziś mam w planach dorobić jeszcze dodatkowe skrypciki które np. Bedą umożliwiały swobodne poruszanie kursorem oraz coś w rodzaju SciteCleanDocWhitespace tylko czyszczącej białe znaki w nowej lini oraz po przejściach kursorami (mam nadzieje że mi się to uda)
Jeżeli komuś chodź trochę pomogłem lub zachęciłem do kożystania z SciTE - to jest mi bardzo przyjemnie:)
Pozdrawiam
Marek Ogłodek (vel tsharek

edit: zrobiłem te kursorki, ale nie podobają mi się

my.lua:
Kod
function wyczysc(od_s,do_s)
editor.TargetStart = od_s
editor.TargetEnd = do_s
editor:ReplaceTarget(string.gsub(editor:textrange(od_s,do_s), "([ \\t]+)$", ''))
editor:ScrollCaret()
end
------------------
function lewo()
if editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))~=editor.CurrentPos then
editor:GotoPos(editor.CurrentPos-1)
editor:ScrollCaret()
end
end
------------------
function prawo()
if editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]~=editor.CurrentPos then
editor:GotoPos(editor.CurrentPos+1)
else
editor:InsertText(-1,' ')
editor:GotoPos(editor.CurrentPos+1)
end
editor:ScrollCaret()
end
------------------
function dol()
local nextLine=editor:LineFromPosition(editor.CurrentPos)+1
if nextLine<editor.LineCount then
local nextLineStartPosition=editor:PositionFromLine(nextLine)
local nextLineEndPosition=editor.LineEndPosition[nextLine]
local curentLineStartPosition=editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))
local curentLineEndPosition=editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]
local toNextLineAdd=editor.CurrentPos-curentLineStartPosition
local nextLinePosition=nextLineStartPosition+toNextLineAdd
if nextLineEndPosition<nextLinePosition then editor:InsertText(nextLineEndPosition,string.rep(" ", nextLinePosition-nextLineEndPosition)) end
editor:GotoPos(nextLineStartPosition+toNextLineAdd)
editor:ScrollCaret()
--wyczysczenie syfu
local prevline=editor:LineFromPosition(editor.CurrentPos)-1
wyczysc(editor:PositionFromLine(prevline), editor.LineEndPosition[prevline])
end
end
------------------
function gora()
local nextLine=editor:LineFromPosition(editor.CurrentPos)-1
if nextLine>=0 then
local nextLineStartPosition=editor:PositionFromLine(nextLine)
local nextLineEndPosition=editor.LineEndPosition[nextLine]
local curentLineStartPosition=editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))
local curentLineEndPosition=editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]
local toNextLineAdd=editor.CurrentPos-curentLineStartPosition
local nextLinePosition=nextLineStartPosition+toNextLineAdd
if nextLineEndPosition<nextLinePosition then editor:InsertText(nextLineEndPosition,string.rep(" ", nextLinePosition-nextLineEndPosition)) end
editor:GotoPos(nextLineStartPosition+toNextLineAdd)
editor:ScrollCaret()
--wyczysczenie syfu
local prevline=editor:LineFromPosition(editor.CurrentPos)+1
wyczysc(editor:PositionFromLine(prevline), editor.LineEndPosition[prevline])
end
end
editor.TargetStart = od_s
editor.TargetEnd = do_s
editor:ReplaceTarget(string.gsub(editor:textrange(od_s,do_s), "([ \\t]+)$", ''))
editor:ScrollCaret()
end
------------------
function lewo()
if editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))~=editor.CurrentPos then
editor:GotoPos(editor.CurrentPos-1)
editor:ScrollCaret()
end
end
------------------
function prawo()
if editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]~=editor.CurrentPos then
editor:GotoPos(editor.CurrentPos+1)
else
editor:InsertText(-1,' ')
editor:GotoPos(editor.CurrentPos+1)
end
editor:ScrollCaret()
end
------------------
function dol()
local nextLine=editor:LineFromPosition(editor.CurrentPos)+1
if nextLine<editor.LineCount then
local nextLineStartPosition=editor:PositionFromLine(nextLine)
local nextLineEndPosition=editor.LineEndPosition[nextLine]
local curentLineStartPosition=editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))
local curentLineEndPosition=editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]
local toNextLineAdd=editor.CurrentPos-curentLineStartPosition
local nextLinePosition=nextLineStartPosition+toNextLineAdd
if nextLineEndPosition<nextLinePosition then editor:InsertText(nextLineEndPosition,string.rep(" ", nextLinePosition-nextLineEndPosition)) end
editor:GotoPos(nextLineStartPosition+toNextLineAdd)
editor:ScrollCaret()
--wyczysczenie syfu
local prevline=editor:LineFromPosition(editor.CurrentPos)-1
wyczysc(editor:PositionFromLine(prevline), editor.LineEndPosition[prevline])
end
end
------------------
function gora()
local nextLine=editor:LineFromPosition(editor.CurrentPos)-1
if nextLine>=0 then
local nextLineStartPosition=editor:PositionFromLine(nextLine)
local nextLineEndPosition=editor.LineEndPosition[nextLine]
local curentLineStartPosition=editor:PositionFromLine(editor:LineFromPosition(editor.CurrentPos))
local curentLineEndPosition=editor.LineEndPosition[editor:LineFromPosition(editor.CurrentPos)]
local toNextLineAdd=editor.CurrentPos-curentLineStartPosition
local nextLinePosition=nextLineStartPosition+toNextLineAdd
if nextLineEndPosition<nextLinePosition then editor:InsertText(nextLineEndPosition,string.rep(" ", nextLinePosition-nextLineEndPosition)) end
editor:GotoPos(nextLineStartPosition+toNextLineAdd)
editor:ScrollCaret()
--wyczysczenie syfu
local prevline=editor:LineFromPosition(editor.CurrentPos)+1
wyczysc(editor:PositionFromLine(prevline), editor.LineEndPosition[prevline])
end
end
SciTEGlobal.properties:
Kod
command.name.9.*=lewo
command.subsystem.9.*=3
command.9.*=lewo
command.save.before.9.*=2
command.shortcut.9.*=Left
command.name.10.*=prawo
command.subsystem.10.*=3
command.10.*=prawo
command.save.before.10.*=2
command.shortcut.10.*=Right
command.name.11.*=dol
command.subsystem.11.*=3
command.11.*=dol
command.save.before.11.*=2
command.shortcut.11.*=Down
command.name.12.*=gora
command.subsystem.12.*=3
command.12.*=gora
command.save.before.12.*=2
command.shortcut.12.*=Up
command.subsystem.9.*=3
command.9.*=lewo
command.save.before.9.*=2
command.shortcut.9.*=Left
command.name.10.*=prawo
command.subsystem.10.*=3
command.10.*=prawo
command.save.before.10.*=2
command.shortcut.10.*=Right
command.name.11.*=dol
command.subsystem.11.*=3
command.11.*=dol
command.save.before.11.*=2
command.shortcut.11.*=Down
command.name.12.*=gora
command.subsystem.12.*=3
command.12.*=gora
command.save.before.12.*=2
command.shortcut.12.*=Up