.emacs-my
changeset 1289 85654fc21cf5
parent 1288 6333a733046f
child 1290 a3ec0437c4f1
--- 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")