function executeFormula() editor:BeginUndoAction() if not formula or formula =="" then print('Please set formula first by ALT+SHIFT+F.') return end local expr = editor:GetSelText() local ss = editor.CurrentPos local se = editor.Anchor if not expr or expr == "" then ss, se = editor:findtext("\-*[0-9]+[.0-9]*", SCFIND_REGEXP, ss) end if ss > se then ss,se = se, ss end local cs, ce if editor.SelectionIsRectangle then cs = editor.Column[ss] ce = editor.Column[se] end for m in editor:match("\-*[0-9]+[.0-9]*", SCFIND_REGEXP, ss) do local c = m.pos if c > se then break end local width = m.len local col = editor.Column[c] local chFlag if not editor.SelectionIsRectangle or (col >= cs and (col + width -1) <= ce) then chFlag = true else chFlag = false end if chFlag then expr = m.text local pt = string.find(expr, '.', 1, true) local acc, fmt if pt then acc = width - pt if acc < 0 then acc = 0 end fmt = "%"..width.."."..acc.."f" else fmt = "%"..width.."i" end expr = string.gsub(formula, '<>', expr) local f, msg = loadstring("return "..expr) if f then m:replace(string.format(fmt, f())) else print(">Execute Formula: cannot evaluate the formula") end end end editor:EndUndoAction() end