You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mitchell edited this page Dec 12, 2020
·
2 revisions
If you are on a Unix-based system of some sort there are quite a few useful
command-line utilities available to you. One of these is bc, a command-line
calculator. This script runs the currently selected text through bc. This
allows you to type "1 + 1" in your textadept buffer, select it, run this
function, and the selected text will be replaced with "2".
Place this in your ~/.textadept/init.lua
function replaceMath()
local text = buffer:get_sel_text()
local p = io.popen('echo "'..text..'" | bc 2>&1')
local out = p:read('*all')
p:close()
buffer:replace_sel(out:gsub("\n", ""))
end
keys['ctrl+M'] = replaceMath
bc is quite powerful. Selecting the text
x = 2
2 * x
and running this function will replace the text with "4", as you'd expect.
On Debian/Ubuntu based systems you can install bc with
sudo apt-get install bc.