local txt_words = {
teh='the', wd='would',cd='could'
}
local pascal_words = {
fun='function',lfun='local function',
proc='procedure',virt='virtual',ctor='constructor',
dtor='destructor',prog='program',
int='integer',dbl='double',str='string'
}
local words
function switch_substitution_table()
local ext = props['FileExt']
if ext == 'pas' or ext == 'lua' then
words = pascal_words
elseif ext == 'txt' then
words = txt_words
else
words = nil
end
end
local function word_substitute(word)
return words and words[word] or word
end
local word_start,in_word,current_word
local find = string.find
function OnChar(s)
if not in_word then
if find(s,'%w') then
word_start = editor.CurrentPos
in_word = true
current_word = s
end
else
if find(s,'%w') then
current_word = current_word..s
else
local word_end = editor.CurrentPos
local subst = word_substitute(current_word)
if subst ~= current_word then
editor:SetSel(word_start-1,word_end-1)
local was_whitespace = find(s,'%s')
if was_whitespace then
subst = subst..s
end
editor:ReplaceSel(subst)
word_end = editor.CurrentPos
if not was_whitespace then
editor:GotoPos(word_end + 1)
end
end
in_word = false
end
end
return false
end
function OnOpen(f)
switch_substitution_table()
end
function OnSwitchFile(f)
switch_substitution_table()
end