# HG changeset patch # User Oleksandr Gavenko # Date 1436499594 18000 # Node ID 85654fc21cf56c4370f2b695fa8d8e5704793c90 # Parent 6333a733046f4b82ed6a3542920d18a3e550c0cc my-calc-line diff -r 6333a733046f -r 85654fc21cf5 .emacs-my --- a/.emacs-my Thu Apr 23 02:04:23 2015 +0300 +++ b/.emacs-my Thu Jul 09 22:39:54 2015 -0500 @@ -1265,7 +1265,7 @@ (setq-default calc-group-digits t) (setq-default calc-group-char "'") -(defun my-calc-eval-region (arg beg end) +(defun my-calc-region (arg beg end) "Calculate the region and display the result in the echo area. With prefix ARG non-nil, insert the result at the end of region." (interactive "P\nr") @@ -1278,6 +1278,29 @@ (save-excursion (insert result))))) +(defun my-calc-line (arg) + "Evaluate expression in current line and display the result in +the echo area by skipping final '=' sign. With prefix ARG +non-nil, insert the result at the end of line and space if +necessary for delimiting." + (interactive "P") + (require 'calc) + (save-excursion + (let (beg end expr result) + (beginning-of-line) + (setq beg (point)) + (end-of-line) + (search-backward "=" beg t) + (setq end (point)) + (setq expr (buffer-substring-no-properties beg end)) + (setq result (calc-eval expr)) + (if (null arg) + (message "%s = %s" expr result) + (end-of-line) + (unless (eq (char-before) ?\ ) + (insert ?\ )) + (insert result))))) + ;; ---------------------------------------------------------------- (message "rst, reStructuredText")