Last active
September 30, 2016 00:28
-
-
Save osmatsuda/6eb57634ebd159b06ce699dee999dc48 to your computer and use it in GitHub Desktop.
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
(defmacro calc-eval-format (expr-str &rest vars) | |
(let ((expr (cl-gensym)) | |
(result (cl-gensym))) | |
`(let ((case-fold-search nil)) | |
(setq ,expr ,expr-str) | |
(cl-loop for sym in '(,@vars) by #'cl-cdddr | |
for eq-sym in (cdr '(,@vars)) by #'cl-cdddr | |
for val in (cddr '(,@vars)) by #'cl-cdddr | |
do | |
(unless (and (symbolp sym) | |
(numberp val) | |
(eq '= eq-sym)) | |
(error "Wrong format of variables")) | |
(setq ,expr (replace-regexp-in-string | |
(concat "\\<" (symbol-name sym) "\\>") | |
(number-to-string val) | |
,expr t))) | |
(setq ,result (calc-eval ,expr)) | |
(if (stringp ,result) | |
(kill-new ,result) | |
(if (listp ,result) | |
(kill-new (cadr ,result)) | |
,result))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment