.emacs-my
changeset 1289 85654fc21cf5
parent 1288 6333a733046f
child 1290 a3ec0437c4f1
equal deleted inserted replaced
1288:6333a733046f 1289:85654fc21cf5
  1263 (message "cacl, calculator")
  1263 (message "cacl, calculator")
  1264 
  1264 
  1265 (setq-default calc-group-digits t)
  1265 (setq-default calc-group-digits t)
  1266 (setq-default calc-group-char "'")
  1266 (setq-default calc-group-char "'")
  1267 
  1267 
  1268 (defun my-calc-eval-region (arg beg end)
  1268 (defun my-calc-region (arg beg end)
  1269   "Calculate the region and display the result in the echo area.
  1269   "Calculate the region and display the result in the echo area.
  1270 With prefix ARG non-nil, insert the result at the end of region."
  1270 With prefix ARG non-nil, insert the result at the end of region."
  1271   (interactive "P\nr")
  1271   (interactive "P\nr")
  1272   (require 'calc)
  1272   (require 'calc)
  1273   (let* ((expr (buffer-substring-no-properties beg end))
  1273   (let* ((expr (buffer-substring-no-properties beg end))
  1274          (result (calc-eval expr)))
  1274          (result (calc-eval expr)))
  1275     (if (null arg)
  1275     (if (null arg)
  1276         (message "%s = %s" expr result)
  1276         (message "%s = %s" expr result)
  1277       (goto-char end)
  1277       (goto-char end)
  1278       (save-excursion
  1278       (save-excursion
       
  1279         (insert result)))))
       
  1280 
       
  1281 (defun my-calc-line (arg)
       
  1282   "Evaluate expression in current line and display the result in
       
  1283 the echo area by skipping final '=' sign. With prefix ARG
       
  1284 non-nil, insert the result at the end of line and space if
       
  1285 necessary for delimiting."
       
  1286   (interactive "P")
       
  1287   (require 'calc)
       
  1288   (save-excursion
       
  1289     (let (beg end expr result)
       
  1290       (beginning-of-line)
       
  1291       (setq beg (point))
       
  1292       (end-of-line)
       
  1293       (search-backward "=" beg t)
       
  1294       (setq end (point))
       
  1295       (setq expr (buffer-substring-no-properties beg end))
       
  1296       (setq result (calc-eval expr))
       
  1297       (if (null arg)
       
  1298           (message "%s = %s" expr result)
       
  1299         (end-of-line)
       
  1300         (unless (eq (char-before) ?\ )
       
  1301           (insert ?\ ))
  1279         (insert result)))))
  1302         (insert result)))))
  1280 
  1303 
  1281 ;; ----------------------------------------------------------------
  1304 ;; ----------------------------------------------------------------
  1282 (message "rst, reStructuredText")
  1305 (message "rst, reStructuredText")
  1283 
  1306