# HG changeset patch # User Oleksandr Gavenko # Date 1617824919 -10800 # Node ID 237c8f98ac43cbc176d722b6d26cba8ff6e0b4b1 # Parent 746bcf68435fd7d263808b98bd593b0c2d5724ea Repeating my-calc-line interactive place result after "=" sign clearing any old text. diff -r 746bcf68435f -r 237c8f98ac43 .emacs-my --- a/.emacs-my Mon Feb 22 11:32:37 2021 +0200 +++ b/.emacs-my Wed Apr 07 22:48:39 2021 +0300 @@ -1652,10 +1652,13 @@ (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." + "Evaluate calc expression in current line and display the +result in the echo area by skipping everything after the final +'=' sign. + +With prefix ARG non-nil or repeating command interactively, +insert the result at the end of line + add a space if necessary +for delimiting clearing everything after '=' sign if it is here." (interactive "P") (require 'calc) (save-excursion @@ -1667,9 +1670,13 @@ (setq end (point)) (setq expr (buffer-substring-no-properties beg end)) (setq result (calc-eval expr)) - (if (null arg) + (if (and (null arg) (not (eq 'my-calc-line last-command))) (message "%s = %s" expr result) (end-of-line) + (setq end (point)) + (when (search-backward "=" beg t) + (forward-char 1) + (delete-region (point) end)) (unless (eq (char-before) ?\ ) (insert ?\ )) (insert result)))))