(defun run-calc (expr&optional replace) "Calculate the `expr' using GNU bc. If called interactively, the user is asked for input. If called on region the selected expression is used as input. By default display output in temp buffer `*BC Output*'. With prefix, insert the output." (interactive (list (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (quick-calc current-prefix-arg)) current-prefix-arg)) (require 'calc) (let ((output (calc-eval expr))) (if (and replace output) (when (use-region-p) (delete-region (region-beginning) (region-end)) (insert output)) (message"Result: %s" output))))