Created
November 10, 2011 02:27
-
-
Save miyamuko/1353916 to your computer and use it in GitHub Desktop.
バッファ内に書いてある数式を計算して答えを挿入 #xyzzy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; | |
;; バッファ内に書いてある数式を計算して答えを挿入 | |
;; | |
;; 例 | |
;; 1 + 1 ってバッファに書いておいてリージョンで囲って M-x eval-calc-region | |
;; | |
(require "calc") | |
(defun eval-calc-region (s e) | |
(interactive "*r") | |
(if (< e s) (rotatef s e)) | |
(progn | |
(goto-char e) | |
(let ((skip-equal (skip-chars-backward "[ =]")) | |
(expr (buffer-substring s (point)))) | |
(let ((ans (ed::calc-string expr))) | |
(goto-char e) | |
(unless skip-equal | |
(insert "=")) | |
(insert (format nil "~A" ans)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment